本文整理了Java中com.google.cloud.datastore.Datastore.update()
方法的一些代码示例,展示了Datastore.update()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.update()
方法的具体详情如下:
包路径:com.google.cloud.datastore.Datastore
类名称:Datastore
方法名:update
[英]Example of updating multiple entities.
String keyName1 = "my_key_name_1";
[中]更新多个实体的示例。
String keyName1 = "my_key_name_1";
代码示例来源:origin: googleapis/google-cloud-java
public static void main(String... args) {
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
Key key = keyFactory.newKey("keyName");
Entity entity = datastore.get(key);
if (entity != null) {
System.out.println("Updating access_time for " + entity.getString("name"));
entity = Entity.newBuilder(entity).set("access_time", Timestamp.now()).build();
datastore.update(entity);
}
}
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of updating multiple entities. */
// [TARGET update(Entity...)]
// [VARIABLE "my_key_name_1"]
// [VARIABLE "my_key_name_2"]
public void batchUpdateEntities(String keyName1, String keyName2) {
// [START batchUpdateEntities]
Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
entityBuilder1.set("propertyName", "updatedValue1");
Entity entity1 = entityBuilder1.build();
Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
entityBuilder2.set("propertyName", "updatedValue2");
Entity entity2 = entityBuilder2.build();
datastore.update(entity1, entity2);
// [END batchUpdateEntities]
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdate() {
List<Entity> keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
try {
DATASTORE.update(ENTITY3);
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected;
}
DATASTORE.add(ENTITY3);
assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
assertNotEquals(ENTITY3, entity3);
DATASTORE.update(entity3);
assertEquals(entity3, DATASTORE.get(ENTITY3.getKey()));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdate() {
List<Entity> keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
try {
datastore.update(ENTITY3);
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected;
}
datastore.add(ENTITY3);
assertEquals(ENTITY3, datastore.get(ENTITY3.getKey()));
Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
assertNotEquals(ENTITY3, entity3);
datastore.update(entity3);
assertEquals(entity3, datastore.get(ENTITY3.getKey()));
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Updates a user in Cloud Datastore.
*/
public User updateUser(String id, String name, String email) {
failIfInvalid(name, email);
Key key = keyFactory.newKey(id);
Entity entity = datastore.get(key);
if (entity == null) {
throw new IllegalArgumentException("No user with id '" + id + "' found");
} else {
entity = Entity.newBuilder(entity)
.set("id", id)
.set("name", name)
.set("email", email)
.build();
datastore.update(entity);
}
return new User(id, name, email);
}
代码示例来源:origin: stackoverflow.com
Datastore ds = TransactionItem.ds();
UpdateOperations<TransactionItem> op = ds.createUpdateOperations(TransactionItem.class).set("paidInvoiceDocNum", String.valueOf(docNumber));
Query<TransactionItem> q = (Query<TransactionItem>)TransactionItem.q().filter("id in", itemsIds).getMorphiaQuery();
ds.update(q, op);
内容来源于网络,如有侵权,请联系作者删除!