赞
踩
功能分类 | 接口名称 | 描述 |
---|---|---|
分布式数据库创建、打开、关闭和删除 | isCreateIfMissing() | 检查数据库不存在时是否创建 |
setCreateIfMissing(boolean isCreateIfMissing) | 设置数据库不存在时是否创建 | |
isEncrypt() | 获取数据库是否加密 | |
setEncrypt(boolean isEncrypt) | 设置数据库是否加密 | |
getStoreType() | 获取分布式数据库的类型 | |
setStoreType(KvStoreType storeType) | 设置分布式数据库的类型 | |
KvStoreType.DEVICE_COLLABORATION | 设备协同分布式数据库类型 | |
KvStoreType.SINGLE_VERSION | 单版本分布式数据库类型 | |
getKvStore(Options options, String storeId) | 根据Options配置创建和打开标识符为storeId的分布式数据库 | |
closeKvStore(KvStore kvStore) | 关闭分布式数据库 | |
deleteKvStore(String storeId) | 删除分布式数据库 | |
分布式数据增、删、改、查 | getStoreId() | 根据配置构造帐号键值数据库管理类实例 |
putBoolean(String key, boolean value) putInt(String key, int value) putFloat(String key, float value) putDouble(String key, double value) putString(String key, String value) putByteArray(String key, byte[] value) putBatch(List entries) | 插入和更新数据 | |
delete(String key) deleteBatch(List keys) | 删除数据 | |
getInt(String key) getFloat(String key) getDouble(String key) getString(String key) getByteArray(String key) getEntries(String keyPrefix) | 查询数据 | |
分布式数据谓词查询 | select() reset() equalTo(String field, int value) equalTo(String field, long value) equalTo(String field, double value) equalTo(String field, String value) equalTo(String field, boolean value) notEqualTo(String field, int value) notEqualTog(String field, long value) notEqualTo(String field, boolean value) notEqualTo(String field, String value) notEqualTo(String field, double value) greaterThan(String field, int value) greaterThan(String field, long value) greaterThan(String field, double value) greaterThan(String field, String value) lessThan(String field, int value) lessThan(String field, long value) lessThan(String field, double value) lessThan(String field, String value) greaterThanOrEqualTo(String field, int value) greaterThanOrEqualTo(String field, long value) greaterThanOrEqualTo(String field, double value) greaterThanOrEqualTo(String field, String value) lessThanOrEqualTo(String field, int value) lessThanOrEqualTo(String field, long value) lessThanOrEqualTo(String field, double value) lessThanOrEqualTo(String field, String value) isNull(String field) orderByDesc(String field) orderByAsc(String field) limit(int number, int offset) like(String field, String value) unlike(String field, String value) inInt(String field, List valueList) inLong(String field, List valueList) inDouble(String field, List valueList) inString(String field, List valueList) notInInt(String field, List valueList) notInLong(String field, List valueList) notInDouble(String field, List valueList) notInString(String field, List valueList) and() or() | 对于Schema数据库谓词查询数据 |
订阅分布式数据变化 | subscribe(SubscribeType subscribeType, KvStoreObserver observer) | 订阅数据库中数据的变化 |
分布式数据同步 | sync(List deviceIdList, SyncMode mode) | 在手动模式下,触发数据库同步 |
Context context;
...
KvManagerConfig config = new KvManagerConfig(context);
KvManager kvManager = KvManagerFactory.getInstance().createKvManager(config);
Options CREATE = new Options();
CREATE.setCreateIfMissing(true).setEncrypt(false).setKvStoreType(KvStoreType.SINGLE_VERSION);
String storeID = "testApp";
SingleKvStore singleKvStore = kvManager.getKvStore(CREATE, storeID);
class KvStoreObserverClient implements KvStoreObserver {
@Override
public void onChange(ChangeNotification notification) {
List<Entry> insertEntries = notification.getInsertEntries();
List<Entry> updateEntries = notification.getUpdateEntries();
List<Entry> deleteEntries = notification.getDeleteEntries();
}
}
KvStoreObserver kvStoreObserverClient = new KvStoreObserverClient();
singleKvStore.subscribe(SubscribeType.SUBSCRIBE_TYPE_ALL, kvStoreObserverClient);
String key = "todayWeather";
String value = "Sunny";
singleKvStore.putString(key, value);
String key = "todayWeather";
String value = singleKvStore.getString(key);
List<DeviceInfo> deviceInfoList = kvManager.getConnectedDevicesInfo(DeviceFilterStrategy.NO_FILTER);
List<String> deviceIdList = new ArrayList<>();
for (DeviceInfo deviceInfo : deviceInfoList) {
deviceIdList.add(deviceInfo.getId());
}
singleKvStore.sync(deviceIdList, SyncMode.PUSH_ONLY);
kvManager.closeKvStore(singleKvStore);
kvManager.deleteKvStore(storeID);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。