Search in sources :

Example 16 with Transaction

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"));
}
Also used : Entity(com.google.cloud.datastore.Entity) Transaction(com.google.cloud.datastore.Transaction) Test(org.junit.Test)

Example 17 with Transaction

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"));
}
Also used : Entity(com.google.cloud.datastore.Entity) Transaction(com.google.cloud.datastore.Transaction) Key(com.google.cloud.datastore.Key) Test(org.junit.Test)

Aggregations

Transaction (com.google.cloud.datastore.Transaction)17 Test (org.junit.Test)16 Entity (com.google.cloud.datastore.Entity)15 Key (com.google.cloud.datastore.Key)9 DatastoreException (com.google.cloud.datastore.DatastoreException)4 FullEntity (com.google.cloud.datastore.FullEntity)3 ProjectionEntity (com.google.cloud.datastore.ProjectionEntity)3 Datastore (com.google.cloud.datastore.Datastore)1 DatastoreOptions (com.google.cloud.datastore.DatastoreOptions)1 IncompleteKey (com.google.cloud.datastore.IncompleteKey)1 KeyFactory (com.google.cloud.datastore.KeyFactory)1