Search in sources :

Example 1 with Key

use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.

the class ITDatastoreSnippets method addEntity.

private void addEntity(String keyName, String keyClass, String property, String value) {
    Key key = datastore.newKeyFactory().setKind(keyClass).newKey(keyName);
    Entity.Builder entityBuilder = Entity.newBuilder(key);
    entityBuilder.set(property, value);
    Entity entity = entityBuilder.build();
    datastore.put(entity);
}
Also used : Entity(com.google.cloud.datastore.Entity) Key(com.google.cloud.datastore.Key)

Example 2 with Key

use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.

the class ITDatastoreSnippets method registerKey.

private String registerKey(String keyName, String kind) {
    Key key = datastore.newKeyFactory().setKind(kind).newKey(keyName);
    registeredKeys.add(key);
    return key.getName();
}
Also used : Key(com.google.cloud.datastore.Key)

Example 3 with Key

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

Example 4 with Key

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

Example 5 with Key

use of com.google.cloud.datastore.Key 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);
}
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

Key (com.google.cloud.datastore.Key)49 Entity (com.google.cloud.datastore.Entity)37 IncompleteKey (com.google.cloud.datastore.IncompleteKey)32 Datastore (com.google.cloud.datastore.Datastore)19 KeyFactory (com.google.cloud.datastore.KeyFactory)17 FullEntity (com.google.cloud.datastore.FullEntity)16 Test (org.junit.Test)15 Transaction (com.google.cloud.datastore.Transaction)9 DatastoreException (com.google.cloud.datastore.DatastoreException)4 ProjectionEntity (com.google.cloud.datastore.ProjectionEntity)3 Batch (com.google.cloud.datastore.Batch)2 DatastoreOptions (com.google.cloud.datastore.DatastoreOptions)1 BeforeClass (org.junit.BeforeClass)1