Class CollectionRepository<DOC>

java.lang.Object
io.stargate.sdk.data.CollectionRepository<DOC>
Type Parameters:
DOC - java bean representing a document

public class CollectionRepository<DOC> extends Object
Client implementing repository pattern for a collection.
  • Field Details

    • collectionClient

      protected final CollectionClient collectionClient
      Raw collection client.
    • docClass

      protected final Class<DOC> docClass
      Keep ref to the generic.
  • Constructor Details

    • CollectionRepository

      public CollectionRepository(CollectionClient col, Class<DOC> clazz)
      Default constructor.
      Parameters:
      col - collection client parent
      clazz - working bean class
  • Method Details

    • getName

      public String getName()
      Return name of the store.
      Returns:
      store name
    • exists

      public boolean exists(String id)
      Check existence of a document from its id. Projection to make it as light as possible.
      Parameters:
      id - document identifier
      Returns:
      existence status
    • insert

      public DocumentMutationResult<DOC> insert(Document<DOC> bean)
      Save a NEW RECORD with a defined id.
      Parameters:
      bean - current object
      Returns:
      generated identifier
    • insertASync

      Save a NEW RECORD with a defined id.
      Parameters:
      bean - current object
      Returns:
      generated identifier
    • insert

      public final List<DocumentMutationResult<DOC>> insert(List<Document<DOC>> documents)
      Low level insertion of multiple records, they should not exist, or it will fail.
      Parameters:
      documents - list of documents
      Returns:
      list of ids
    • insertASync

      public final CompletableFuture<List<DocumentMutationResult<DOC>>> insertASync(List<Document<DOC>> documents)
      Low level insertion of multiple records, they should not exist, or it will fail.
      Parameters:
      documents - list of documents
      Returns:
      list of ids
    • insert

      public final List<DocumentMutationResult<DOC>> insert(List<Document<DOC>> documents, int chunkSize, int concurrency)
      Low level insertion of multiple records, they should not exist, or it will fail.
      Parameters:
      documents - list of documents
      chunkSize - how many document per chunk
      concurrency - how many thread in parallel
      Returns:
      list of ids
    • insertASync

      public final CompletableFuture<List<DocumentMutationResult<DOC>>> insertASync(List<Document<DOC>> documents, int chunkSize, int concurrency)
      Low level insertion of multiple records, they should not exist, or it will fail.
      Parameters:
      documents - list of documents
      chunkSize - how many document per chunk
      concurrency - how many thread in parallel
      Returns:
      list of ids
    • save

      public final DocumentMutationResult<DOC> save(Document<DOC> current)
      Upsert a record
      Parameters:
      current - object Mapping
      Returns:
      an unique identifier for the document
    • saveASync

      public final CompletableFuture<DocumentMutationResult<DOC>> saveASync(Document<DOC> current)
      Upsert a record
      Parameters:
      current - object Mapping
      Returns:
      an unique identifier for the document
    • saveAll

      public final List<DocumentMutationResult<DOC>> saveAll(List<Document<DOC>> documentList)
      Create a new document a generating identifier.
      Parameters:
      documentList - object Mapping
      Returns:
      an unique identifier for the document
    • saveAllASync

      public final CompletableFuture<List<DocumentMutationResult<DOC>>> saveAllASync(List<Document<DOC>> documentList)
      Create a new document a generating identifier asynchronously
      Parameters:
      documentList - object Mapping
      Returns:
      an unique identifier for the document
    • saveAll

      public final List<DocumentMutationResult<DOC>> saveAll(List<Document<DOC>> documentList, int chunkSize, int concurrency)
      Create a new document a generating identifier.
      Parameters:
      documentList - object Mapping
      chunkSize - size of the chunk to process items
      concurrency - concurrency to process items
      Returns:
      an unique identifier for the document
    • saveAllASync

      public final CompletableFuture<List<DocumentMutationResult<DOC>>> saveAllASync(List<Document<DOC>> documentList, int chunkSize, int concurrency)
      Create a new document a generating identifier asynchronously
      Parameters:
      documentList - object Mapping
      chunkSize - size of the chunk to process items
      concurrency - concurrency to process items
      Returns:
      an unique identifier for the document
    • count

      public final int count()
      Count Document request.
      Returns:
      number of document.
    • count

      public final int count(Filter jsonFilter)
      Count Document request.
      Parameters:
      jsonFilter - a filter for the count
      Returns:
      number of document.
    • find

      public Optional<DocumentResult<DOC>> find(@NonNull @NonNull SelectQuery query)
      Find by id.
      Parameters:
      query - query to retrieve documents and vector
      Returns:
      object if presents
    • findById

      public Optional<DocumentResult<DOC>> findById(@NonNull @NonNull String id)
      Find by id.
      Parameters:
      id - identifier
      Returns:
      object if presents
    • search

      public Stream<DocumentResult<DOC>> search()
      Find all item in the collection.
      Returns:
      retrieve all items
    • search

      public Stream<DocumentResult<DOC>> search(SelectQuery query)
      Find all item in the collection.
      Parameters:
      query - search with a query
      Returns:
      retrieve all items
    • searchPage

      public Page<DocumentResult<DOC>> searchPage(SelectQuery query)
      Find a page in the collection.
      Parameters:
      query - current query
      Returns:
      page of records
    • delete

      public boolean delete(@NonNull @NonNull Document<DOC> document)
      Delete a document from id or vector .
      Parameters:
      document - document
      Returns:
      if document has been deleted.
    • deleteAll

      public DeleteResult deleteAll()
      Delete all documents
      Returns:
      number of document deleted
    • deleteAll

      public int deleteAll(List<Document<DOC>> documents)
      Use parallelism and async to delete all records.
      Parameters:
      documents - list of records
      Returns:
      number of records deleted
    • deleteAll

      public DeleteResult deleteAll(DeleteQuery deleteQuery)
      Delete item through a query.
      Parameters:
      deleteQuery - delete query
      Returns:
      number of records deleted
    • deleteAllChunked

      public DeleteResult deleteAllChunked(DeleteQuery deleteQuery, int concurrency)
      Delete item through a query.
      Parameters:
      deleteQuery - delete query
      concurrency - how many chunks processed in parallel
      Returns:
      number of records deleted
    • deletePage

      public DeleteResult deletePage(DeleteQuery deleteQuery)
      Delete item through a query.
      Parameters:
      deleteQuery - delete query
      Returns:
      number of records deleted
    • findByVector

      public Optional<DocumentResult<DOC>> findByVector(float[] vector)
      Find by vector
      Parameters:
      vector - vector
      Returns:
      object if presents
    • deleteByVector

      public boolean deleteByVector(float[] vector)
      Delete by vector
      Parameters:
      vector - vector
      Returns:
      if object deleted
    • deleteById

      public boolean deleteById(String id)
      Delete by vector
      Parameters:
      id - id
      Returns:
      if object deleted
    • findVector

      public Page<DocumentResult<DOC>> findVector(float[] vector, Filter metadataFilter)
      Search similarity from the vector and a limit, if a limit / no paging
      Parameters:
      vector - vector
      metadataFilter - metadata filtering
      Returns:
      page of results
    • findVector

      public List<DocumentResult<DOC>> findVector(float[] vector, Integer limit)
      Search similarity from the vector and a limit, if a limit / no paging
      Parameters:
      vector - vector
      limit - return count
      Returns:
      page of results
    • findVector

      public List<DocumentResult<DOC>> findVector(float[] vector, Filter metadataFilter, Integer limit)
      Search similarity from the vector and a limit, if a limit / no paging
      Parameters:
      vector - vector
      metadataFilter - metadata filtering
      limit - return count
      Returns:
      page of results