Class DocStoreClient
- java.lang.Object
-
- com.salesforce.multicloudj.docstore.client.DocStoreClient
-
public class DocStoreClient extends Object
DocStoreClient provides a unified interface for document/kv store operations across multiple cloud providers.This client supports various document operations such as create, read, update, delete (CRUD) operations along with Query interface on documents stored in cloud-based document databases like AWS DynamoDB, GCP Firestore, and Alibaba TableStore. The implementations also supports secondary indexes behind the scenes and uses them to optimize the queries.
Usage example:
DocStoreClient client = DocStoreClient.builder("aws") .withRegion("us-west-2") .build(); Person p = new Person("John", "Doe", 30); Document doc = new Document(p); client.create(doc); client.query().where("age", 30).run();
The client supports input and output data in the form of Java POJOs and maps. The standard types supported are String, Number, Boolean, Date, List and Map. List and Maps are not supported for Alibaba tablestore.- Since:
- 0.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DocStoreClient.DocStoreClientBuilder
Builder class for creating DocStoreClient instances with fluent configuration.
-
Field Summary
Fields Modifier and Type Field Description protected AbstractDocStore
docStore
-
Constructor Summary
Constructors Modifier Constructor Description protected
DocStoreClient(AbstractDocStore docStore)
Protected constructor for DocStoreClient.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
batchGet(List<Document> documents)
Retrieves multiple documents from the document store in a single batch operation.void
batchPut(List<Document> documents)
Creates or updates multiple documents in the document store in a single batch operation.static DocStoreClient.DocStoreClientBuilder
builder(String providerId)
Creates a new builder for DocStoreClient.void
close()
Closes the document store client and releases associated resources.void
create(Document document)
Creates a new document in the document store.void
delete(Document document)
Deletes a document from the document store.void
get(Document document, String... fieldPath)
Retrieves a document from the document store.ActionList
getActions()
Returns the underlying ActionList for advanced batch operations.void
put(Document document)
Creates or updates a document in the document store.Query
query()
Creates a new Query instance for querying the document store.void
replace(Document document)
Replaces an existing document in the document store.void
update(Document document, Map<String,Object> mods)
Updates specific fields of an existing document in the document store.
-
-
-
Field Detail
-
docStore
protected AbstractDocStore docStore
-
-
Constructor Detail
-
DocStoreClient
protected DocStoreClient(AbstractDocStore docStore)
Protected constructor for DocStoreClient. Use the builder pattern to create instances.- Parameters:
docStore
- the underlying document store implementation
-
-
Method Detail
-
builder
public static DocStoreClient.DocStoreClientBuilder builder(String providerId)
Creates a new builder for DocStoreClient.- Parameters:
providerId
- the cloud provider identifier (e.g., "aws", "gcp-firestore", "ali")- Returns:
- a new DocStoreClientBuilder instance
-
create
public void create(Document document)
Creates a new document in the document store. This operation will fail if a document with the same key already exists.- Parameters:
document
- the document to create, must have a valid key
-
replace
public void replace(Document document)
Replaces an existing document in the document store. This operation will fail if the document does not exist.- Parameters:
document
- the document to replace, must have a valid key
-
put
public void put(Document document)
Creates or updates a document in the document store. This operation will create the document if it doesn't exist, or update it if it does.- Parameters:
document
- the document to put, must have a valid key
-
delete
public void delete(Document document)
Deletes a document from the document store. This operation is idempotent - it will not fail if the document doesn't exist.- Parameters:
document
- the document to delete, must have a valid key
-
get
public void get(Document document, String... fieldPath)
Retrieves a document from the document store. The document input should have a valid key. The retrieved data is stored in the supplied document.- Parameters:
document
- the document to retrieve, must have a valid key. The result will be stored in this documentfieldPath
- optional field paths to retrieve specific fields only. If not provided, all fields are retrieved
-
update
public void update(Document document, Map<String,Object> mods)
Updates specific fields of an existing document in the document store. This operation is not yet supported and will throw an UnSupportedOperationException.- Parameters:
document
- the document to update, must have a valid keymods
- the field modifications to apply
-
batchGet
public void batchGet(List<Document> documents)
Retrieves multiple documents from the document store in a single batch operation. This is more efficient than multiple individual get operations. The retrieved data is stored in the supplied documents.- Parameters:
documents
- the list of documents to retrieve, each must have a valid key. Results will be stored in these documents
-
batchPut
public void batchPut(List<Document> documents)
Creates or updates multiple documents in the document store in a single batch operation. This is more efficient than multiple individual put operations. Each document will be created if it doesn't exist, or updated if it does.- Parameters:
documents
- the list of documents to put, each must have a valid key
-
close
public void close()
Closes the document store client and releases associated resources. After calling this method, the client should not be used for further operations.
-
getActions
public ActionList getActions()
Returns the underlying ActionList for advanced batch operations. This allows for fine-grained control over batch operations and mixing different operation types.- Returns:
- the ActionList instance for building custom batch operations
-
query
public Query query()
Creates a new Query instance for querying the document store. This allows for complex queries with filters, sorting, and pagination.- Returns:
- a new Query instance for building and executing queries
-
-