UpdateJSON.updateTableUsingSQLQuery()
UpdateJSON.updateTableUsingSQLQuery()
メソッドでは、Oracle NoSQL Database SQL問合せを使用して必要な表の行を取得します。
この3番目と最後の問合せメソッドを実装するのが最も簡単で、索引が不要であるというメリットがあります。適切な索引が使用可能な場合は、索引で提供されるすべての利点とともに使用されますが、索引は前述のメソッドのように必須ではありません。
// Update the zip code found on all Boston home addresses
// to "02102-1000"
//
// This query works with or without an index. If an index is
// available, it is automatically used. For larger datasets,
// the read operation will be faster with an index because only
// the rows where person.address.home.city=Boston are returned
// for the read.
private void updateTableUsingSQLQuery(KVStore kvstore) {
TableAPI tableH = kvstore.getTableAPI();
Table myTable = tableH.getTable("personContacts");
String query = "select * from personContacts p ";
query += "where p.person.address.home.city=\"Boston\"";
StatementResult result = kvstore.executeSync(query);
for (RecordValue rv : result) {
Row row = myTable.createRowFromJson(rv.toString(),
false);
updateZipCode(tableH, row, "home", "02102-1000");
}
System.out.println("Updated a table using a SQL Query to " +
"read.");
}