Datastoreの更新時に新しいカラムを追加する場合は
addProperty
メソッドを使います。
slim3を使っていて既存のカラムの schemaVersion などを更新したい場合はindexを指定して
setProperty
メソッドを使います。
Propertyの順番なんぞわからん、という場合は一旦今のPropertyを取ってきて、該当するカラムのindexを取得して、そこに対して更新をかけます。ちょっとしょっぱいやり方なのでもっと他に良い方法があれば教えて下さい。
/**
* @param listComments
* @param roomModel
* @throws Exception
*/
public static void setOrgId(Entity model, String hoge)
throws DatastoreException {
BeginTransactionRequest.Builder treq = BeginTransactionRequest.newBuilder();
BeginTransactionResponse tres = datastore.beginTransaction(treq.build());
ByteString tx = tres.getTransaction();
CommitRequest.Builder request = CommitRequest.newBuilder();
request.setTransaction(tx);
Entity.Builder entity = Entity.newBuilder(model);
entity.addProperty(Property.newBuilder().setName("hoge").setValue(
Value.newBuilder().setStringValue(hoge)));
// あわせてschemaVersionを更新する
List<Property> propertyList = entity.getPropertyList();
for (int i = 0; i < propertyList.size(); i++) {
String name = propertyList.get(i).getName();
if ("sV".equals(name)) {
entity.setProperty(i, Property.newBuilder().setName("sV").setValue(
Value.newBuilder().setIntegerValue(2)));
}
}
request.getMutationBuilder().addUpdate(entity);
CommitResponse response = datastore.commit(request.build());
request.clearTransaction();
}


