UpdateJSON.updateZipCode()
The UpdateJSON.updateZipCode()
method performs the actual update operation in the store.
Because JSON can be returned as a MapValue
, it is simple and efficient to update the JSON data field.
// 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);
}