Class DocumentClient

java.lang.Object
io.stargate.sdk.doc.DocumentClient

public class DocumentClient extends Object
Part of the Document API in stargate wrapper for methods at the document level.
Author:
Cedrick LUNVEN (@clunven)
  • Field Details

    • documentResource

      public Function<ServiceHttp,String> documentResource
      /v2/schemas/namespaces/{namespace}/collections/{collection}/{docId}
  • Constructor Details

    • DocumentClient

      public DocumentClient(LoadBalancedHttpClient stargateHttpClient, CollectionClient collectionClient, String docId)
      Full constructor.
      Parameters:
      stargateHttpClient - stargateHttpClient
      collectionClient - CollectionClient
      docId - String
  • Method Details

    • exist

      public boolean exist()
      Leverage find() to check existence without eventual formatting issues. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/getDocById
      Returns:
      boolean
    • upsert

      public <DOC> String upsert(DOC doc)
      Replace a document. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/replaceDoc
      Type Parameters:
      DOC - working class
      Parameters:
      doc - object to be updated
      Returns:
      the unique document identifier
    • upsert

      public String upsert(String json)
      Replace a document providing only the Json.
      Parameters:
      json - jon file.
      Returns:
      the unique document identifier
    • update

      public <DOC> String update(DOC doc)
      Update part of a document. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/updatePartOfDoc
      Type Parameters:
      DOC - working class
      Parameters:
      doc - working class
      Returns:
      DOC
    • update

      public String update(String json)
      Update a document providing only the Json.
      Parameters:
      json - jon file.
      Returns:
      the unique document identifier
    • find

      public Optional<String> find()
      Get a document by id.
      Returns:
      the json payload if document exists.
    • find

      public <DOC> Optional<DOC> find(RecordMapper<DOC> docm)
      Get a document by id.
      Type Parameters:
      DOC - nea
      Parameters:
      docm - document mapper
      Returns:
      a document if exist
    • find

      public <DOC> Optional<DOC> find(Class<DOC> clazz)
      Get a document by {document-id}. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/getDocById
      Type Parameters:
      DOC - working class
      Parameters:
      clazz - working class
      Returns:
      a document if exist
    • delete

      public void delete()
      Delete a document. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/deleteDoc
    • findSubDocument

      public <SUBDOC> Optional<SUBDOC> findSubDocument(String path, Class<SUBDOC> className)
      Get a sub document by {document-path}. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/GetSubDocByPath
      Type Parameters:
      SUBDOC - working class
      Parameters:
      path - subpath in the doc
      className - working class
      Returns:
      SUBDOC
    • findSubDocument

      public Optional<String> findSubDocument(String path)
      Retrieve a sub document with no marshalling
      Parameters:
      path - path of the document
      Returns:
      value as a String
    • executefunction

      public String executefunction(String path, String function, Object value)
      Execute a function on a document.
      Parameters:
      path - current document sub path
      function - function executed.
      value - value for attribute to update
      Returns:
      attribute updated
    • replaceSubDocument

      public <SUBDOC> void replaceSubDocument(String path, SUBDOC newValue)
      Replace a subpart of the document. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/replaceSubDoc
      Type Parameters:
      SUBDOC - working class
      Parameters:
      path - subpath in the doc
      newValue - object for the new value
    • replaceSubDocument

      public void replaceSubDocument(String path, String newValue)
      Replace a subpart of the document.
      Parameters:
      path - sub path
      newValue - new value for the path
    • updateSubDocument

      public <SUBDOC> void updateSubDocument(String path, SUBDOC newValue)
      Update part of a sub document https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/updatePartOfSubDoc
      Type Parameters:
      SUBDOC - working class
      Parameters:
      path - subpath in the doc
      newValue - object for the new value
    • updateSubDocument

      public void updateSubDocument(String path, String newValue)
      Update a subpart of the document.
      Parameters:
      path - sub path
      newValue - new value for the path
    • deleteSubDocument

      public void deleteSubDocument(String path)
      Delete a sub document. https://docs.datastax.com/en/astra/docs/_attachments/docv2.html#operation/deleteSubDoc
      Parameters:
      path - sub document path