UpdateJSON.updateZipCode()
UpdateJSON.updateZipCode()
メソッドは、ストア内で実際の更新操作を実行します。
JSONはMapValue
として返すことができるため、JSONデータ・フィールドを更新するのは簡単で効率的です。
// Updates the zipcode for the proper address (either "home"
// or "work" in this example).
//
// The calling method must guarantee that this row contains a
// home address which refers to the correct city.
private void updateZipCode(TableAPI tableH, Row row,
String addrType, String newzip) {
MapValue homeaddr = row.get("person").asMap()
.get("address").asMap()
.get(addrType).asMap();
// If the zip field does not exist in the home address,
// it is created with the newzip value. If it currently
// exists, it is updated with the new value.
homeaddr.put("zip", newzip);
// Write the updated row back to the store.
// Note that if this was production code, we
// should be using putIfVersion() when
// performing this write to ensure that the row
// has not been changed since it was originally read.
tableH.put(row, null, null);
}