use of com.google.cloud.datastore.FullEntity in project google-cloud-java by GoogleCloudPlatform.
the class ITDatastoreTest method testGetArrayNoDeferredResults.
@Test
public void testGetArrayNoDeferredResults() {
DATASTORE.put(ENTITY3);
Iterator<Entity> result = DATASTORE.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
assertEquals(ENTITY1, result.next());
assertNull(result.next());
assertEquals(ENTITY2, result.next());
Entity entity3 = result.next();
assertEquals(ENTITY3, entity3);
assertTrue(entity3.isNull("null"));
assertFalse(entity3.getBoolean("bool"));
assertEquals(LIST_VALUE2.get(), entity3.getList("list"));
FullEntity<IncompleteKey> partial1 = entity3.getEntity("partial1");
FullEntity<IncompleteKey> partial2 = entity3.getEntity("partial2");
assertEquals(PARTIAL_ENTITY2, partial1);
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected - no such property
}
assertFalse(result.hasNext());
}
use of com.google.cloud.datastore.FullEntity 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.FullEntity in project google-cloud-java by GoogleCloudPlatform.
the class TransactionSnippets method addSingleEntity.
/**
* Example of adding a single entity.
*/
// [TARGET add(FullEntity)]
// [VARIABLE "my_key_name"]
public void addSingleEntity(String keyName) {
Datastore datastore = transaction.getDatastore();
// [START addSingleEntity]
Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
Entity.Builder entityBuilder = Entity.newBuilder(key);
entityBuilder.set("propertyName", "value");
Entity entity = entityBuilder.build();
transaction.add(entity);
transaction.commit();
// [END addSingleEntity]
}
use of com.google.cloud.datastore.FullEntity 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();
}
use of com.google.cloud.datastore.FullEntity in project google-cloud-java by GoogleCloudPlatform.
the class TransactionSnippets method putSingleEntity.
/**
* Example of putting a single entity.
*/
// [TARGET put(FullEntity)]
// [VARIABLE "my_key_name"]
public void putSingleEntity(String keyName) {
Datastore datastore = transaction.getDatastore();
// [START putSingleEntity]
Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
Entity.Builder entityBuilder = Entity.newBuilder(key);
entityBuilder.set("propertyName", "value");
Entity entity = entityBuilder.build();
transaction.put(entity);
transaction.commit();
// [END putSingleEntity]
}
Aggregations