提交 9805e772 编写于 作者: M marui

8.23 modify deviceID

Signed-off-by: Nmarui <marui83@huawei.com>
上级 bdc794a7
...@@ -44,8 +44,6 @@ ...@@ -44,8 +44,6 @@
- 单个数据库最多支持注册8个订阅数据变化的回调。 - 单个数据库最多支持注册8个订阅数据变化的回调。
- 不支持非系统应用调用需要指定设备的分布式能力接口。
## 接口说明 ## 接口说明
...@@ -142,34 +140,35 @@ ...@@ -142,34 +140,35 @@
> **说明:** > **说明:**
> >
> deviceIds通过调用[devManager.getTrustedDeviceListSync](../reference/apis/js-apis-device-manager.md#gettrusteddevicelistsync)方法得到,deviceManager模块的接口均为系统接口,仅系统应用可用 > deviceIds通过调用[deviceManager.getAvailableDeviceListSync](../reference/apis/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到
```js ```js
// 获取deviceIds // 获取deviceIds
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { let deviceId = null;
if (err) {
console.info(`Failed to create device manager. Code:${err.code},message:${err.message}`); try {
return; dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
} let devices = dmInstance.getAvailableDeviceListSync();
let devices = manager.getTrustedDeviceListSync(); deviceId = devices[0].networkId;
let deviceId = devices[0].deviceId;
// 构造用于查询分布式表的谓词对象
// 构造用于查询分布式表的谓词对象 let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); // 调用跨设备查询接口,并返回查询结果
// 调用跨设备查询接口,并返回查询结果 store.remoteQuery(deviceId, 'EMPLOYEE', predicates, ['ID', 'NAME', 'AGE', 'SALARY', 'CODES'],
store.remoteQuery(deviceId, 'EMPLOYEE', predicates, ['ID', 'NAME', 'AGE', 'SALARY', 'CODES'], function (err, resultSet) {
function (err, resultSet) { if (err) {
if (err) { console.error(`Failed to remoteQuery data. Code:${err.code},message:${err.message}`);
console.error(`Failed to remoteQuery data. Code:${err.code},message:${err.message}`); return;
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
} }
) console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
}) }
)
} catch (err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## 相关实例 ## 相关实例
......
...@@ -798,7 +798,8 @@ inDevices(devices: Array&lt;string&gt;): RdbPredicates ...@@ -798,7 +798,8 @@ inDevices(devices: Array&lt;string&gt;): RdbPredicates
> **说明:** > **说明:**
> >
> 其中devices通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getAvailableDeviceListSync)方法得到。数据库同步时调用Sync接口,需要在入参谓词中调用inDevices接口选择设备。如果不调用inDevices接口即默认连接组网内所有的设备。 > 其中devices通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
数据库同步时调用Sync接口,需要在入参谓词中调用inDevices接口选择设备。如果不调用inDevices接口即默认连接组网内所有的设备。
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -817,22 +818,20 @@ inDevices(devices: Array&lt;string&gt;): RdbPredicates ...@@ -817,22 +818,20 @@ inDevices(devices: Array&lt;string&gt;): RdbPredicates
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = []; let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; for (var i = 0; i < devices.length; i++) {
} deviceIds[i] = devices[i].networkId;
dmInstance = manager; }
let devices = dmInstance.getAvailableDeviceListSync(); } catch (err) {
for (var i = 0; i < devices.length; i++) { console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
deviceIds[i] = devices[i].networkId; }
}
})
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.inDevices(deviceIds); predicates.inDevices(deviceIds);
``` ```
...@@ -844,9 +843,6 @@ inAllDevices(): RdbPredicates ...@@ -844,9 +843,6 @@ inAllDevices(): RdbPredicates
同步分布式数据库时连接到组网内所有的远程设备。 同步分布式数据库时连接到组网内所有的远程设备。
> **说明:**
>
>如果不调用inAllDevices接口即默认连接组网内所有的远程设备。
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -2737,7 +2733,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -2737,7 +2733,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
> **说明:** > **说明:**
> >
> 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getAvailableDeviceListSync)方法得到。 > 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -2762,19 +2758,17 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -2762,19 +2758,17 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null; let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; deviceId = devices[0].networkId;
} } catch (err) {
dmInstance = manager; console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
let devices = dmInstance.getAvailableDeviceListSync(); }
deviceId = devices[0].networkId;
})
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0); predicates.greaterThan("id", 0);
...@@ -2807,7 +2801,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -2807,7 +2801,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
> **说明:** > **说明:**
> >
> 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getAvailableDeviceListSync)方法得到。 > 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -2837,19 +2831,17 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -2837,19 +2831,17 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null; let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; deviceId = devices[0].networkId;
} } catch (err) {
dmInstance = manager; console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
let devices = dmInstance.getAvailableDeviceListSync(); }
deviceId = devices[0].networkId;
})
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0); predicates.greaterThan("id", 0);
...@@ -3688,7 +3680,7 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac ...@@ -3688,7 +3680,7 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac
> **说明:** > **说明:**
> >
> 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getAvailableDeviceListSync)方法得到。 > 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC **需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
...@@ -3713,19 +3705,17 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac ...@@ -3713,19 +3705,17 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null; let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; deviceId = devices[0].networkId;
} } catch (err) {
dmInstance = manager; console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
let devices = dmInstance.getAvailableDeviceListSync(); }
deviceId = devices[0].networkId;
})
store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
if (err) { if (err) {
...@@ -3744,7 +3734,7 @@ store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) ...@@ -3744,7 +3734,7 @@ store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName)
> **说明:** > **说明:**
> >
> 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getAvailableDeviceListSync)方法得到。 > 其中device通过调用[deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC **需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
...@@ -3774,19 +3764,17 @@ store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) ...@@ -3774,19 +3764,17 @@ store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName)
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null; let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; deviceId = devices[0].networkId;
} } catch (err) {
dmInstance = manager; console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
let devices = dmInstance.getAvailableDeviceListSync(); }
deviceId = devices[0].networkId;
})
let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE"); let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE");
promise.then((tableName) => { promise.then((tableName) => {
...@@ -3825,21 +3813,19 @@ sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array ...@@ -3825,21 +3813,19 @@ sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = []; let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; for (var i = 0; i < devices.length; i++) {
} deviceIds[i] = devices[i].networkId;
dmInstance = manager; }
let devices = dmInstance.getAvailableDeviceListSync(); } catch (err) {
for (var i = 0; i < devices.length; i++) { console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
deviceIds[i] = devices[i].networkId; }
}
})
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(deviceIds); predicates.inDevices(deviceIds);
...@@ -3889,21 +3875,19 @@ store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, r ...@@ -3889,21 +3875,19 @@ store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, r
**示例:** **示例:**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = []; let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { try {
if (err) { dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
console.log("create device manager failed, err=" + err); let devices = dmInstance.getAvailableDeviceListSync();
return; for (var i = 0; i < devices.length; i++) {
} deviceIds[i] = devices[i].networkId;
dmInstance = manager; }
let devices = dmInstance.getAvailableDeviceListSync(); } catch (err) {
for (var i = 0; i < devices.length; i++) { console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
deviceIds[i] = devices[i].networkId; }
}
})
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(deviceIds); predicates.inDevices(deviceIds);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册