public interface DataStore
extends java.io.Closeable
Ordinarily, the only implementations of this interface are the default in-memory implementation,
which holds references to actual SDK data model objects, and the persistent data store
implementation that delegates to a PersistentDataStore
.
All implementations must permit concurrent access and updates.
Modifier and Type | Method and Description |
---|---|
DataStoreTypes.ItemDescriptor |
get(DataStoreTypes.DataKind kind,
java.lang.String key)
Retrieves an item from the specified collection, if available.
|
DataStoreTypes.KeyedItems<DataStoreTypes.ItemDescriptor> |
getAll(DataStoreTypes.DataKind kind)
Retrieves all items from the specified collection.
|
DataStoreStatusProvider.CacheStats |
getCacheStats()
Returns statistics about cache usage, if this data store implementation supports caching.
|
void |
init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
Overwrites the store's contents with a set of items for each collection.
|
boolean |
isInitialized()
Checks whether this store has been initialized with any data yet.
|
boolean |
isStatusMonitoringEnabled()
Returns true if this data store implementation supports status monitoring.
|
boolean |
upsert(DataStoreTypes.DataKind kind,
java.lang.String key,
DataStoreTypes.ItemDescriptor item)
Updates or inserts an item in the specified collection.
|
void init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
All previous data should be discarded, regardless of versioning.
The update should be done atomically. If it cannot be done atomically, then the store must first add or update each item in the same order that they are given in the input data, and then delete any previously stored items that were not in the input data.
allData
- a list of DataStoreTypes.DataKind
instances and their corresponding data setsDataStoreTypes.ItemDescriptor get(DataStoreTypes.DataKind kind, java.lang.String key)
If the item has been deleted and the store contains a placeholder, it should return that placeholder rather than null.
kind
- specifies which collection to usekey
- the unique key of the item within that collectionDataStoreTypes.KeyedItems<DataStoreTypes.ItemDescriptor> getAll(DataStoreTypes.DataKind kind)
If the store contains placeholders for deleted items, it should include them in the results, not filter them out.
kind
- specifies which collection to useboolean upsert(DataStoreTypes.DataKind kind, java.lang.String key, DataStoreTypes.ItemDescriptor item)
The SDK may pass an DataStoreTypes.ItemDescriptor
that contains a null, to represent a placeholder
for a deleted item. In that case, assuming the version is greater than any existing version of
that item, the store should retain that placeholder rather than simply not storing anything.
kind
- specifies which collection to usekey
- the unique key for the item within that collectionitem
- the item to insert or updateboolean isInitialized()
boolean isStatusMonitoringEnabled()
This is normally only true for persistent data stores created with
Components.persistentDataStore(ComponentConfigurer)
,
but it could also be true for any custom DataStore
implementation that makes use of
ClientContext.getDataStoreUpdateSink()
.
Returning true means that the store guarantees that if it ever enters an invalid state (that is, an
operation has failed or it knows that operations cannot succeed at the moment), it will publish a
status update, and will then publish another status update once it has returned to a valid state.
The same value will be returned from DataStoreStatusProvider.isStatusMonitoringEnabled()
.
DataStoreStatusProvider.CacheStats getCacheStats()