KvStorepublic interface SingleKvStore extends KvStore
To create a SingleKvStore database,
you can use the KvManager.getKvStore(Options, String) method
with KvStoreType set to SINGLE_VERSION for the input parameter Options.
This database synchronizes data to other databases in time sequence.
The SingleKvStore database does not support
synchronous transactions, or data search using snapshots.
SystemCapability.Data#DATA_DISTRIBUTEDDATAMGRMAX_BATCH_SIZE, MAX_KEY_LENGTH, MAX_KEY_LENGTH_DEVICE, MAX_QUERY_LENGTH, MAX_STORE_ID_LENGTH, MAX_VALUE_LENGTH| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
closeResultSet(KvStoreResultSet resultSet) |
Closes a
KvStoreResultSet object returned by getResultSet. |
boolean |
getBoolean(String key) |
Obtains the
boolean value of a specified key. |
byte[] |
getByteArray(String key) |
Obtains the
byte[] value of a specified key. |
double |
getDouble(String key) |
Obtains the
double value of a specified key. |
List<Entry> |
getEntries(String keyPrefix) |
Obtains all key-value pairs that match a specified key prefix.
|
List<Entry> |
getEntries(Query query) |
Obtains the list of key-value pairs matching the specified
Query object. |
float |
getFloat(String key) |
Obtains the
float value of a specified key. |
int |
getInt(String key) |
Obtains the
int value of a specified key. |
KvStoreResultSet |
getResultSet(String keyPrefix) |
Obtains the result sets with a specified prefix from a
KvStore database. |
KvStoreResultSet |
getResultSet(Query query) |
Obtains the
KvStoreResultSet object matching the specified Query object. |
int |
getResultSize(Query query) |
Obtains the number of results matching the specified
Query object. |
SecurityLevel |
getSecurityLevel() |
Get the security level of the database.
|
String |
getString(String key) |
Obtains the
String value of a specified key. |
void |
registerSyncCallback(SyncCallback syncCallback) |
Register Synchronizes
SingleKvStore databases callback. |
void |
removeDeviceData(String deviceId) |
|
void |
setSyncParam(int defaultAllowedDelayMs) |
Sets the default delay allowed for database synchronization.
|
void |
sync(List<String> deviceIdList,
SyncMode mode) |
Synchronizes
SingleKvStore databases. |
void |
sync(List<String> deviceIdList,
SyncMode mode,
int allowedDelayMs) |
Synchronizes the database to the specified devices with the specified delay allowed.
|
void |
unRegisterSyncCallback() |
UnRegister Synchronizes
SingleKvStore databases callback. |
commit, delete, deleteBatch, enableSync, getStoreId, putBatch, putBoolean, putByteArray, putDouble, putFloat, putInt, putString, rollback, setSyncRange, startTransaction, subscribe, unSubscribeboolean getBoolean(String key) throws KvStoreException
boolean value of a specified key.key - Indicates the key of the boolean value to be queried.boolean value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.int getInt(String key) throws KvStoreException
int value of a specified key.key - Indicates the key of the int value to be queried.int value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.float getFloat(String key) throws KvStoreException
float value of a specified key.key - Indicates the key of the float value to be queried.float value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.double getDouble(String key) throws KvStoreException
double value of a specified key.key - Indicates the key of the double value to be queried.double value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.String getString(String key) throws KvStoreException
String value of a specified key.key - Indicates the key of the String value to be queried.String value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.byte[] getByteArray(String key) throws KvStoreException
byte[] value of a specified key.key - Indicates the key of the byte[] value to be queried.byte[] value matching the given criteria.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, DB_ERROR, and KEY_NOT_FOUND.List<Entry> getEntries(String keyPrefix) throws KvStoreException
keyPrefix - Indicates the key prefix to match.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.List<Entry> getEntries(Query query) throws KvStoreException
Query object.query - Indicates the Query object.Query object.KvStoreException - Throws this exception if any of the following errors occurs:
INVALID_ARGUMENT, SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.KvStoreResultSet getResultSet(String keyPrefix) throws KvStoreException
KvStore database.
The KvStoreResultSet object can be used to query all key-value pairs that meet the search criteria.
Each KvStore instance can have a maximum of four KvStoreResultSet objects at the same time.
If you have created four objects, calling this method will return a failure. Therefore, you are advised to call
the closeResultSet method to close unnecessary KvStoreResultSet objects in a timely manner.keyPrefix - Indicates the key prefix to match.KvStoreResultSet objects.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.KvStoreResultSet getResultSet(Query query) throws KvStoreException
KvStoreResultSet object matching the specified Query object.query - Indicates the Query object.KvStoreResultSet object matching the specified Query object.KvStoreException - Throws this exception if any of the following errors occurs:
INVALID_ARGUMENT, SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.void closeResultSet(KvStoreResultSet resultSet) throws KvStoreException
KvStoreResultSet object returned by getResultSet.resultSet - Indicates the KvStoreResultSet object to close.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.int getResultSize(Query query) throws KvStoreException
Query object.query - Indicates the Query object.Query object.KvStoreException - Throws this exception if any of the following errors occurs:
INVALID_ARGUMENT, SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.void sync(List<String> deviceIdList, SyncMode mode) throws KvStoreException
SingleKvStore databases.
This method returns immediately and sync result will be returned through asynchronous callback.
deviceIdList - Indicates the list of IDs of devices
whose SingleKvStore databases are to be synchronized.mode - Indicates the synchronization mode, PUSH, PULL, or PUSH_PULL.KvStoreException - Throws this exception if no SingleKvStore database is available.void sync(List<String> deviceIdList, SyncMode mode, int allowedDelayMs) throws KvStoreException
deviceIdList - Indicates the list of devices to which to synchronize the database.mode - Indicates the synchronization mode. The value can be PUSH, PULL, or
PUSH_PULL.allowedDelayMs - Indicates the delay allowed for the synchronization, in milliseconds.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.void removeDeviceData(String deviceId) throws KvStoreException
KvStoreExceptionvoid registerSyncCallback(SyncCallback syncCallback) throws KvStoreException
SingleKvStore databases callback.
Sync result is returned through asynchronous callback.
syncCallback - Indicates the callback used to send the synchronization result to the caller.KvStoreException - Throws this exception if no SingleKvStore database is available.void unRegisterSyncCallback()
throws KvStoreException
SingleKvStore databases callback.KvStoreException - Throws this exception if no SingleKvStore database is available.void setSyncParam(int defaultAllowedDelayMs)
throws KvStoreException
defaultAllowedDelayMs - Indicates the default delay allowed for the database synchronization, in
milliseconds.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.SecurityLevel getSecurityLevel() throws KvStoreException
SecurityLevel the security level of the database.KvStoreException - Throws this exception if any of the following errors occurs:
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.