use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testAddGetUpdateMultiple.
@Test
public void testAddGetUpdateMultiple() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
transactionSnippets.multipleAddEntities(registerKey("add_get_multiple_key_1"), registerKey("add_get_multiple_key_2"));
transaction = datastore.newTransaction();
transactionSnippets = new TransactionSnippets(transaction);
List<Entity> entities = transactionSnippets.getMultiple("add_get_multiple_key_1", "add_get_multiple_key_2");
assertEquals(2, entities.size());
Set<String> values = ImmutableSet.of(entities.get(0).getString("propertyName"), entities.get(1).getString("propertyName"));
assertTrue(values.contains("value1"));
assertTrue(values.contains("value2"));
transaction = datastore.newTransaction();
transactionSnippets = new TransactionSnippets(transaction);
transactionSnippets.multipleUpdateEntities(registerKey("add_get_multiple_key_1"), registerKey("add_get_multiple_key_2"));
transaction = datastore.newTransaction();
transactionSnippets = new TransactionSnippets(transaction);
entities = transactionSnippets.getMultiple("add_get_multiple_key_1", "add_get_multiple_key_2");
assertEquals(2, entities.size());
values = ImmutableSet.of(entities.get(0).getString("propertyName"), entities.get(1).getString("propertyName"));
assertTrue(values.contains("value3"));
assertTrue(values.contains("value4"));
}
use of com.google.cloud.datastore.Transaction in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionSnippets method testAddGetMultipleDeferredId.
@Test
public void testAddGetMultipleDeferredId() {
Transaction transaction = datastore.newTransaction();
TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
List<Key> keys = transactionSnippets.multipleAddEntitiesDeferredId();
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