KvStorepublic interface DeviceKvStore extends KvStore
To create a DeviceKvStore database,
you can use the KvManager.getKvStore(Options, String) method with
KvStoreType set to DEVICE_COLLABORATION for the input parameter Options.
This database manages distributed data by device, and cannot modify data synchronized from remote devices.
When an application writes a key-value pair entry into the database, the system automatically adds the ID
of the device running the application to the key.
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 deviceId,
String key) |
Obtains the
boolean value matching a specified device ID and key. |
byte[] |
getByteArray(String deviceId,
String key) |
Obtains the
byte[] value matching a specified device ID and key. |
double |
getDouble(String deviceId,
String key) |
Obtains the
double value matching a specified device ID and key. |
List<Entry> |
getEntries(String deviceId,
String keyPrefix) |
Obtains all key-value pairs matching a specified device ID and key prefix.
|
List<Entry> |
getEntries(String deviceId,
Query query) |
Obtains the list of key-value pairs matching a specified device ID and
Query object. |
List<Entry> |
getEntries(Query query) |
Obtains the list of key-value pairs matching the specified
Query object. |
float |
getFloat(String deviceId,
String key) |
Obtains the
float value matching a specified device ID and key. |
int |
getInt(String deviceId,
String key) |
Obtains the
int value matching a specified device ID and key. |
KvStoreResultSet |
getResultSet(String deviceId,
String keyPrefix) |
Obtains the
KvStoreResultSet object matching the specified device ID and key prefix. |
KvStoreResultSet |
getResultSet(String deviceId,
Query query) |
Obtains the
KvStoreResultSet object matching a specified device ID and Query object. |
KvStoreResultSet |
getResultSet(Query query) |
Obtains the
KvStoreResultSet object matching the specified Query object. |
int |
getResultSize(String deviceId,
Query query) |
Obtains the number of results matching a specified device ID and
Query object. |
int |
getResultSize(Query query) |
Obtains the number of results matching the specified
Query object. |
String |
getString(String deviceId,
String key) |
Obtains the
String value matching a specified device ID and key. |
void |
registerSyncCallback(SyncCallback syncCallback) |
Register Synchronizes
DeviceKvStore databases callback. |
void |
removeDeviceData(String deviceId) |
Removes data of a specified device from the current database.
|
void |
sync(List<String> deviceIdList,
SyncMode mode) |
Synchronizes
DeviceKvStore databases. |
void |
unRegisterSyncCallback() |
UnRegister Synchronizes
DeviceKvStore databases callback. |
commit, delete, deleteBatch, enableSync, getStoreId, putBatch, putBoolean, putByteArray, putDouble, putFloat, putInt, putString, rollback, setSyncRange, startTransaction, subscribe, unSubscribeboolean getBoolean(String deviceId, String key) throws KvStoreException
boolean value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String key) throws KvStoreException
int value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String key) throws KvStoreException
float value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String key) throws KvStoreException
double value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String key) throws KvStoreException
String value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String key) throws KvStoreException
byte[] value matching a specified device ID and key.deviceId - Identifies the device whose data is to be queried.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 deviceId, String keyPrefix) throws KvStoreException
deviceId - Identifies the device whose data is to be queried.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.List<Entry> getEntries(String deviceId, Query query) throws KvStoreException
Query object.deviceId - Indicates the ID of the device to which the key-value pairs belong.query - Indicates the Query object.Query object.INVALID_ARGUMENT - Throws this exception if either or both of the input parameters are incorrect.SERVER_UNAVAILABLE - Throws this exception if the service is unavailable.IPC_ERROR - Throws this exception if an IPC error occurs.DB_ERROR - Throws this exception if a database error occurs.KvStoreExceptionKvStoreResultSet getResultSet(String deviceId, String keyPrefix) throws KvStoreException
KvStoreResultSet object matching the specified device ID and key prefix.
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.
deviceId - Identifies the device whose data is to be queried.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.KvStoreResultSet getResultSet(String deviceId, Query query) throws KvStoreException
KvStoreResultSet object matching a specified device ID and Query object.deviceId - Indicates the ID of the device to which the KvStoreResultSet object belongs.query - Indicates the Query object.KvStoreResultSet object matching the specified Query object.INVALID_ARGUMENT - Throws this exception if either or both of the input parameters are incorrect.SERVER_UNAVAILABLE - Throws this exception if the service is unavailable.IPC_ERROR - Throws this exception if an IPC error occurs.DB_ERROR - Throws this exception if a database error occurs.KvStoreExceptionvoid 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.int getResultSize(String deviceId, Query query) throws KvStoreException
Query object.deviceId - Indicates the ID of the device to which the results belong.query - Indicates the Query object.Query object.INVALID_ARGUMENT - Throws this exception if either or both of the input parameters are incorrect.SERVER_UNAVAILABLE - Throws this exception if the service is unavailable.IPC_ERROR - Throws this exception if an IPC error occurs.DB_ERROR - Throws this exception if a database error occurs.KvStoreExceptionvoid sync(List<String> deviceIdList, SyncMode mode) throws KvStoreException
DeviceKvStore databases.
This method returns immediately and sync result will be returned through asynchronous callback.
deviceIdList - Indicates the list of IDs of devices
whose DeviceKvStore databases are to be synchronized.mode - Indicates the synchronization mode, PUSH, PULL, or PUSH_PULL.KvStoreException - Throws this exception if no DeviceKvStore database is available.void removeDeviceData(String deviceId) throws KvStoreException
deviceId - Identifies the device whose data is to be removed. The value cannot be the current device ID.KvStoreException - Throws this exception if any of the following errors occurs: INVALID_ARGUMENT,
SERVER_UNAVAILABLE, IPC_ERROR, and DB_ERROR.void registerSyncCallback(SyncCallback syncCallback) throws KvStoreException
DeviceKvStore 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 DeviceKvStore database is available.void unRegisterSyncCallback()
throws KvStoreException
DeviceKvStore databases callback.KvStoreException - Throws this exception if no DeviceKvStore database is available.