Package com.dtsx.astra.sdk
Class AstraDBRepository<DOC>
java.lang.Object
com.dtsx.astra.sdk.AstraDBRepository<DOC>
- Type Parameters:
DOC
- working document
Client for AstraDB collection using repository pattern.
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
count()
Count Document request.final int
count
(io.stargate.sdk.data.domain.query.Filter jsonFilter) Count Document request.boolean
Delete a document from id or vector.int
Delete all documentsint
deleteAll
(io.stargate.sdk.data.domain.query.DeleteQuery deleteQuery) Delete item through a query.int
Use parallelism and async to delete all records.boolean
deleteById
(String id) Delete by vectorboolean
deleteByVector
(float[] vector) Delete by vectorboolean
Check existence of a document from its id.find
(@NonNull io.stargate.sdk.data.domain.query.SelectQuery query) Find all item in the collection.findAll()
Find all item in the collection.Find by id.findByVector
(float[] vector) Find by vectorio.stargate.sdk.core.domain.Page
<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> findVector
(float[] vector, io.stargate.sdk.data.domain.query.Filter metadataFilter) Search similarity from the vector and a limit, if a limit / no pagingfindVector
(float[] vector, io.stargate.sdk.data.domain.query.Filter metadataFilter, Integer limit) Search similarity from the vector and a limit, if a limit / no pagingfindVector
(float[] vector, Integer limit) Search similarity from the vector and a limit, if a limit / no pagingio.stargate.sdk.data.domain.DocumentMutationResult
<DOC> Save a NEW RECORD with a defined id.Low level insertion of multiple records, they should not exist, or it will fail.insert
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documents, int chunkSize, int concurrency) Low level insertion of multiple records, they should not exist, or it will fail.CompletableFuture
<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> insertAsync
(io.stargate.sdk.data.domain.odm.Document<DOC> bean) Save a NEW RECORD with a defined id asynchronouslyfinal CompletableFuture
<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> insertASync
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documents) Insert a List asynchronously.final CompletableFuture
<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> insertASync
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documents, int chunkSize, int concurrency) Insert a List asynchronously.final io.stargate.sdk.data.domain.DocumentMutationResult
<DOC> Save by record.Create a new document a generating identifier.saveAll
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documentList, int chunkSize, int concurrency) Create a new document a generating identifier.final CompletableFuture
<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> saveAllASync
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documentList) Create a new document a generating identifier asynchronouslyfinal CompletableFuture
<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> saveAllASync
(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documentList, int chunkSize, int concurrency) Create a new document a generating identifier asynchronouslyfinal CompletableFuture
<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> Save by record asynchronously.io.stargate.sdk.core.domain.Page
<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> searchPage
(io.stargate.sdk.data.domain.query.SelectQuery query) Find a page in the collection.
-
Method Details
-
exists
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 io.stargate.sdk.data.domain.DocumentMutationResult<DOC> insert(io.stargate.sdk.data.domain.odm.Document<DOC> bean) Save a NEW RECORD with a defined id.- Parameters:
bean
- current object- Returns:
- generated identifier
-
insertAsync
public CompletableFuture<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> insertAsync(io.stargate.sdk.data.domain.odm.Document<DOC> bean) Save a NEW RECORD with a defined id asynchronously- Parameters:
bean
- current object- Returns:
- generated identifier
-
insert
public final List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> insert(List<io.stargate.sdk.data.domain.odm.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<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> insertASync(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documents) Insert a List asynchronously.- Parameters:
documents
- list of documents- Returns:
- list of ids
-
insert
public final List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> insert(List<io.stargate.sdk.data.domain.odm.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 documentschunkSize
- how many document per chunkconcurrency
- how many thread in parallel- Returns:
- list of ids
-
insertASync
public final CompletableFuture<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> insertASync(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documents, int chunkSize, int concurrency) Insert a List asynchronously.- Parameters:
documents
- list of documentschunkSize
- split into chunksconcurrency
- number of thread to process the chunks- Returns:
- list of ids
-
save
public final io.stargate.sdk.data.domain.DocumentMutationResult<DOC> save(@NonNull @NonNull io.stargate.sdk.data.domain.odm.Document<DOC> current) Save by record.- Parameters:
current
- object Mapping- Returns:
- an unique identifier for the document
-
saveASync
public final CompletableFuture<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> saveASync(@NonNull @NonNull io.stargate.sdk.data.domain.odm.Document<DOC> current) Save by record asynchronously.- Parameters:
current
- object Mapping- Returns:
- an unique identifier for the document
-
saveAll
public final List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> saveAll(List<io.stargate.sdk.data.domain.odm.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<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> saveAllASync(List<io.stargate.sdk.data.domain.odm.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<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>> saveAll(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documentList, int chunkSize, int concurrency) Create a new document a generating identifier.- Parameters:
documentList
- object MappingchunkSize
- size of the chunk to process itemsconcurrency
- concurrency to process items- Returns:
- an unique identifier for the document
-
saveAllASync
public final CompletableFuture<List<io.stargate.sdk.data.domain.DocumentMutationResult<DOC>>> saveAllASync(List<io.stargate.sdk.data.domain.odm.Document<DOC>> documentList, int chunkSize, int concurrency) Create a new document a generating identifier asynchronously- Parameters:
documentList
- object MappingchunkSize
- size of the chunk to process itemsconcurrency
- 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(io.stargate.sdk.data.domain.query.Filter jsonFilter) Count Document request.- Parameters:
jsonFilter
- a filter for the count- Returns:
- number of document.
-
findById
public Optional<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> findById(@NonNull @NonNull String id) Find by id.- Parameters:
id
- identifier- Returns:
- object if presents
-
findAll
Find all item in the collection.- Returns:
- retrieve all items
-
find
public Stream<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> find(@NonNull @NonNull io.stargate.sdk.data.domain.query.SelectQuery query) Find all item in the collection.- Parameters:
query
- search with a query- Returns:
- retrieve all items
-
searchPage
public io.stargate.sdk.core.domain.Page<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> searchPage(io.stargate.sdk.data.domain.query.SelectQuery query) Find a page in the collection.- Parameters:
query
- current query- Returns:
- page of records
-
delete
Delete a document from id or vector.- Parameters:
document
- document- Returns:
- if document has been deleted.
-
deleteAll
public int deleteAll()Delete all documents- Returns:
- number of document deleted
-
deleteAll
Use parallelism and async to delete all records.- Parameters:
documents
- list of records- Returns:
- number of records deleted
-
deleteAll
public int deleteAll(io.stargate.sdk.data.domain.query.DeleteQuery deleteQuery) Delete item through a query.- Parameters:
deleteQuery
- delete query- Returns:
- number of records deleted
-
findByVector
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
Delete by vector- Parameters:
id
- id- Returns:
- if object deleted
-
findVector
public io.stargate.sdk.core.domain.Page<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> findVector(float[] vector, io.stargate.sdk.data.domain.query.Filter metadataFilter) Search similarity from the vector and a limit, if a limit / no paging- Parameters:
vector
- vectormetadataFilter
- metadata filtering- Returns:
- page of results
-
findVector
public List<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> findVector(float[] vector, Integer limit) Search similarity from the vector and a limit, if a limit / no paging- Parameters:
vector
- vectorlimit
- return count- Returns:
- page of results
-
findVector
public List<io.stargate.sdk.data.domain.odm.DocumentResult<DOC>> findVector(float[] vector, io.stargate.sdk.data.domain.query.Filter metadataFilter, Integer limit) Search similarity from the vector and a limit, if a limit / no paging- Parameters:
vector
- vectormetadataFilter
- metadata filteringlimit
- return count- Returns:
- page of results
-