use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testIsActive.
@Test
public void testIsActive() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
Key key = transactionSnippets.isActive();
Entity result = datastore.get(key);
assertNotNull(result);
datastore.delete(key);
}
use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testCommit.
@Test
public void testCommit() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
Key key = transactionSnippets.commit();
Entity result = datastore.get(key);
assertNotNull(result);
datastore.delete(key);
}
use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testActive.
@Test
public void testActive() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
Key key = transactionSnippets.active();
Entity result = datastore.get(key);
assertNotNull(result);
datastore.delete(key);
}
use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testRun.
@Test
public void testRun() {
Key key1 = datastore.newKeyFactory().setKind("ParentKind").newKey("run_key_1");
Entity entity1 = Entity.newBuilder(key1).set("description", "run1").build();
datastore.put(entity1);
Key key2 = datastore.newKeyFactory().setKind("MyKind").addAncestor(PathElement.of("ParentKind", "run_key_1")).newKey("run_key_2");
registerKey(key1);
registerKey(key2);
Entity entity2 = Entity.newBuilder(key2).set("description", "run2").build();
datastore.put(entity2);
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
List<Entity> entities = transactionSnippets.run("run_key_1");
assertEquals(1, entities.size());
assertEquals(entity2, entities.get(0));
}
use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testPutGetMultipleDeferredId.
@Test
public void testPutGetMultipleDeferredId() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
List<Key> keys = transactionSnippets.multiplePutEntitiesDeferredId();
assertEquals(2, keys.size());
Key key1 = keys.get(0);
registerKey(key1);
Entity entity1 = datastore.get(key1);
assertEquals("value1", entity1.getString("propertyName"));
Key key2 = keys.get(1);
registerKey(key2);
Entity entity2 = datastore.get(key2);
assertEquals("value2", entity2.getString("propertyName"));
}
Aggregations