Interface StateStoreRecordOperations
- All Known Implementing Classes:
StateStoreBaseImpl,StateStoreDriver,StateStoreFileBaseImpl,StateStoreFileImpl,StateStoreFileSystemImpl,StateStoreMySQLImpl,StateStoreSerializableImpl,StateStoreZooKeeperImpl
@Private
@Evolving
public interface StateStoreRecordOperations
Operations for a driver to manage records in the State Store.
-
Method Summary
Modifier and TypeMethodDescription<T extends BaseRecord>
QueryResult<T>Get all records of the requested record class from the data store.<T extends BaseRecord>
TGet a single record from the store that matches the query.<T extends BaseRecord>
List<T>getMultiple(Class<T> clazz, Query<T> query) Get multiple records from the store that match a query.<T extends BaseRecord>
booleanput(T record, boolean allowUpdate, boolean errorIfExists) Creates a single record.<T extends BaseRecord>
StateStoreOperationResultCreates multiple records.<T extends BaseRecord>
Map<Query<T>,Integer> Remove all records of a specific class that match any query in a list of queries.<T extends BaseRecord>
intRemove multiple records of a specific class that match a query.<T extends BaseRecord>
booleanremove(T record) Remove a single record.<T extends BaseRecord>
booleanRemove all records of this class from the store.<T extends BaseRecord>
Map<T,Boolean> removeMultiple(List<T> records) Remove multiple records.
-
Method Details
-
get
Get all records of the requested record class from the data store. To use the default implementations in this class, getAll must return new instances of the records on each call. It is recommended to override the default implementations for better performance.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of record to fetch.- Returns:
- List of all records that match the class.
- Throws:
IOException- Throws exception if unable to query the data store.
-
get
Get a single record from the store that matches the query.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of record to fetch.query- Query to filter results.- Returns:
- A single record matching the query. Null if there are no matching records.
- Throws:
IOException- If multiple records match or if the data store cannot be queried.
-
getMultiple
Get multiple records from the store that match a query. This method assumes the underlying driver does not support filtering. If the driver supports filtering it should overwrite this method.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of record to fetch.query- Query to filter results.- Returns:
- Records of type class that match the query or empty list if none are found.
- Throws:
IOException- Throws exception if unable to query the data store.
-
put
<T extends BaseRecord> boolean put(T record, boolean allowUpdate, boolean errorIfExists) throws IOException Creates a single record. Optionally updates an existing record with same primary key.- Type Parameters:
T- Record class of the records.- Parameters:
record- The record to insert or update.allowUpdate- True if update of exiting record is allowed.errorIfExists- True if an error should be returned when inserting an existing record. Only used if allowUpdate = false.- Returns:
- True if the operation was successful.
- Throws:
IOException- Throws exception if unable to query the data store.
-
putAll
<T extends BaseRecord> StateStoreOperationResult putAll(List<T> records, boolean allowUpdate, boolean errorIfExists) throws IOException Creates multiple records. Optionally updates existing records that have the same primary key.- Type Parameters:
T- Record class of the records.- Parameters:
records- List of data records to update or create. All records must be of class clazz.allowUpdate- True if update of exiting record is allowed.errorIfExists- True if an error should be returned when inserting an existing record. Only used if allowUpdate = false.- Returns:
- The result of the putAll operation.
- Throws:
IOException- Throws exception if unable to query the data store.
-
remove
Remove a single record.- Type Parameters:
T- Record class of the records.- Parameters:
record- Record to be removed.- Returns:
- true If the record was successfully removed. False if the record could not be removed or not stored.
- Throws:
IOException- Throws exception if unable to query the data store.
-
removeMultiple
Remove multiple records.- Type Parameters:
T- Record class of the records.- Parameters:
records- Records to be removed.- Returns:
- Map of record to a boolean indicating if the record has being removed successfully.
- Throws:
IOException- Throws exception if unable to query the data store.
-
removeAll
Remove all records of this class from the store.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of records to remove.- Returns:
- True if successful.
- Throws:
IOException- Throws exception if unable to query the data store.
-
remove
Remove multiple records of a specific class that match a query. Requires the getAll implementation to fetch fresh records on each call.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- The class to match the records with.query- Query to filter what to remove.- Returns:
- The number of records removed.
- Throws:
IOException- Throws exception if unable to query the data store.
-
remove
<T extends BaseRecord> Map<Query<T>,Integer> remove(Class<T> clazz, List<Query<T>> queries) throws IOException Remove all records of a specific class that match any query in a list of queries. Requires the getAll implementation to fetch fresh records on each call.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- The class to match the records with.queries- Queries (logical OR) to filter what to remove.- Returns:
- Map of query to number of records removed by that query.
- Throws:
IOException- Throws exception if unable to query the data store.
-