Class CollectionClient

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

public class CollectionClient extends Object
Work on a dedicated collection without using the Pojo className.
Author:
Cedrick LUNVEN (@clunven)
  • Field Details

    • DOCUMENT_ID

      public static final String DOCUMENT_ID
      Read document id.
      See Also:
    • BATCH_ID_PATH

      public static final String BATCH_ID_PATH
      Read document id.
      See Also:
    • namespaceClient

      protected NamespaceClient namespaceClient
      Namespace.
    • collectionName

      protected String collectionName
      Collection name.
    • collectionResource

      public Function<ServiceHttp,String> collectionResource
      /v2/schemas/namespaces/{namespace}/collections/{collection}
    • collectionUpgradeResource

      public Function<ServiceHttp,String> collectionUpgradeResource
      /v2/schemas/namespaces/{namespace}/collections/{collection}/upgrade?raw=true
    • collectionBatchResource

      public Function<ServiceHttp,String> collectionBatchResource
      /v2/schemas/namespaces/{namespace}/collections/{collection}/batch
    • collectionJsonSchemaResource

      public Function<ServiceHttp,String> collectionJsonSchemaResource
      /v2/schemas/namespaces/{namespace}/collections/{collection}/json-schema
  • Constructor Details

    • CollectionClient

      public CollectionClient(LoadBalancedHttpClient stargateHttpClient, NamespaceClient namespaceClient, String collectionName)
      Full constructor.
      Parameters:
      stargateHttpClient - http client
      namespaceClient - NamespaceClient
      collectionName - String
  • Method Details

    • find

      Get metadata of the collection. There is no dedicated resources we use the list and filter with what we need.
      Returns:
      metadata of the collection if its exist or empty
      See Also:
    • exist

      public boolean exist()
      Check if the collection exist.
      Returns:
      if the collection exists.
    • create

      public void create()
      Create the collection.
      See Also:
    • upgradeSAI

      public void upgradeSAI()
      Upgrade the collection. This is not relevant in ASTRA.
    • upgrade

      public void upgrade(CollectionClient.CollectionUpgradeType index)
      Update a collection to SAI.
      Parameters:
      index - collection SAI
    • delete

      public void delete()
      Deleting the collection
      See Also:
    • create

      public <DOC> String create(DOC doc)
      Create a new document from any serializable object. The doc could be a the String value.
      Type Parameters:
      DOC - working bean type
      Parameters:
      doc - working bean instance
      Returns:
      created document id
      See Also:
    • create

      public String create(String doc)
      Create a new document from any serializable object. The doc could be a the String value.
      Parameters:
      doc - working bean instance
      Returns:
      created document id
      See Also:
    • batchInsert

      public <DOC> List<String> batchInsert(List<DOC> records, String idPath)
      Use the resource batch to insert massively in the DB.
      Type Parameters:
      DOC - working document
      Parameters:
      records - list of records
      idPath - id path to enforced ids
      Returns:
      list of inserted ids
    • batchInsertRaw

      public List<String> batchInsertRaw(List<String> records, String idPath)
      Use the resource batch to insert massively in the DB.
      Parameters:
      records - list of records
      idPath - id path to enforced ids
      Returns:
      list of inserted ids
    • batchInsert

      public <DOC> List<String> batchInsert(List<DOC> records)
      Insert multiple record with a single resource.
      Type Parameters:
      DOC - working document
      Parameters:
      records - list of records
      Returns:
      list of inserted ids
    • batchInsertRaw

      public List<String> batchInsertRaw(List<String> records)
      Insert multiple record with a single resource.
      Parameters:
      records - list of records
      Returns:
      list of inserted ids
    • count

      public long count()
      Count items in a collection, it can be slow as we iterate over pages limitating payload and marshalling as much as possible.
      Returns:
      number of record
    • findAll

      public Stream<Document<String>> findAll()
      This function will retrieve all documents in the Collection without any mapping. USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Returns:
      all items in the the collection
    • findAll

      public <DOC> Stream<Document<DOC>> findAll(RecordMapper<DOC> documentMapper)
      This function will retrieve all documents in the Collection providing a custom mapping logic. USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Type Parameters:
      DOC - generic for working bean
      Parameters:
      documentMapper - mapper from a record to the document bean
      Returns:
      all items in the the collection
    • findAll

      public <DOC> Stream<Document<DOC>> findAll(Class<DOC> beanClass)
      This function will retrieve all documents in the Collection with automatic marshalling (jackson). USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Type Parameters:
      DOC - generic for working bean
      Parameters:
      beanClass - class for working bean
      Returns:
      all items in the the collection
    • findAll

      public Stream<Document<String>> findAll(Query query)
      Find all document matching the query. USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Parameters:
      query - list of filters
      Returns:
      all items matchin criteria
    • findAll

      public <DOC> Stream<Document<DOC>> findAll(Query query, RecordMapper<DOC> documentMapper)
      Find all document matching the query. USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Type Parameters:
      DOC - generic for working bean
      Parameters:
      query - list of filters
      documentMapper - custom mapping implementation
      Returns:
      all items matchin criteria
    • findAll

      public <DOC> Stream<Document<DOC>> findAll(Query query, Class<DOC> beanClass)
      Find all document matching the query. USE WITH CAUTION. Default behaviour is using paging, here we are fetching all pages until no more.
      Type Parameters:
      DOC - generic for working bean
      Parameters:
      query - list of filters
      beanClass - class for working bean
      Returns:
      all items matchin criteria
    • findPage

      public Page<Document<String>> findPage()
      Search for a page (without marshalling). There is no filter either.
      Returns:
      a page of results
    • findPage

      public Page<Document<String>> findPage(PageableQuery query)
      Find a page given some search (without marshalling the documents).
      Parameters:
      query - query
      Returns:
      output
    • findPage

      public <DOC> Page<Document<DOC>> findPage(Class<DOC> beanClass)
      Default query, find first page.
      Type Parameters:
      DOC - working class
      Parameters:
      beanClass - working bean
      Returns:
      the page of records
    • findPage

      public <DOC> Page<Document<DOC>> findPage(PageableQuery query, Class<DOC> beanClass)
      Find a page given some search.
      Type Parameters:
      DOC - generic for working bean
      Parameters:
      query - filters for the query
      beanClass - class for working bean
      Returns:
      a page of results
    • findPage

      public <DOC> Page<Document<DOC>> findPage(RecordMapper<DOC> documentMapper)
      Find a page and marshall using a mapper.
      Type Parameters:
      DOC - current bean
      Parameters:
      documentMapper - document mapper
      Returns:
      page of results
    • findPage

      public <DOC> Page<Document<DOC>> findPage(PageableQuery query, RecordMapper<DOC> documentMapper)
      Find a page and marshall using a mapper.
      Type Parameters:
      DOC - current bean
      Parameters:
      query - current query
      documentMapper - document mapper
      Returns:
      page of results
    • document

      public DocumentClient document(String docId)
      Move to document Resource
      Parameters:
      docId - String
      Returns:
      DocumentClient
    • getCollectionName

      public String getCollectionName()
      Getter accessor for attribute 'collectionName'.
      Returns:
      current value of 'collectionName'