use of com.google.cloud.datastore.Transaction.Response in project google-cloud-java by GoogleCloudPlatform.
the class TransactionSnippets method multiplePutEntitiesDeferredId.
/**
* Example of putting multiple entities with deferred id allocation.
*/
// [TARGET putWithDeferredIdAllocation(FullEntity...)]
public List<Key> multiplePutEntitiesDeferredId() {
Datastore datastore = transaction.getDatastore();
// [START multiplePutEntitiesDeferredId]
IncompleteKey key1 = datastore.newKeyFactory().setKind("MyKind").newKey();
FullEntity.Builder entityBuilder1 = FullEntity.newBuilder(key1);
entityBuilder1.set("propertyName", "value1");
FullEntity entity1 = entityBuilder1.build();
IncompleteKey key2 = datastore.newKeyFactory().setKind("MyKind").newKey();
FullEntity.Builder entityBuilder2 = FullEntity.newBuilder(key2);
entityBuilder2.set("propertyName", "value2");
FullEntity entity2 = entityBuilder2.build();
transaction.putWithDeferredIdAllocation(entity1, entity2);
Response response = transaction.commit();
// [END multiplePutEntitiesDeferredId]
return response.getGeneratedKeys();
}
use of com.google.cloud.datastore.Transaction.Response in project google-cloud-java by GoogleCloudPlatform.
the class TransactionSnippets method multipleAddEntitiesDeferredId.
/**
* Example of adding multiple entities with deferred id allocation.
*/
// [TARGET addWithDeferredIdAllocation(FullEntity...)]
public List<Key> multipleAddEntitiesDeferredId() {
Datastore datastore = transaction.getDatastore();
// [START multipleAddEntitiesDeferredId]
IncompleteKey key1 = datastore.newKeyFactory().setKind("MyKind").newKey();
FullEntity.Builder entityBuilder1 = FullEntity.newBuilder(key1);
entityBuilder1.set("propertyName", "value1");
FullEntity entity1 = entityBuilder1.build();
IncompleteKey key2 = datastore.newKeyFactory().setKind("MyKind").newKey();
FullEntity.Builder entityBuilder2 = FullEntity.newBuilder(key2);
entityBuilder2.set("propertyName", "value2");
FullEntity entity2 = entityBuilder2.build();
transaction.addWithDeferredIdAllocation(entity1, entity2);
Response response = transaction.commit();
// [END multipleAddEntitiesDeferredId]
return response.getGeneratedKeys();
}
Aggregations