use of com.google.cloud.datastore.IncompleteKey in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method batchAllocateId.
/**
* Example of allocating multiple ids in a single batch.
*/
// [TARGET allocateId(IncompleteKey...)]
public List<Key> batchAllocateId() {
// [START batchAllocateId]
KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
IncompleteKey incompleteKey1 = keyFactory.newKey();
IncompleteKey incompleteKey2 = keyFactory.newKey();
// let cloud datastore automatically assign the ids
List<Key> keys = datastore.allocateId(incompleteKey1, incompleteKey2);
// [END batchAllocateId]
return keys;
}
use of com.google.cloud.datastore.IncompleteKey in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method allocateIdSingle.
/**
* Example of allocating an id.
*/
// [TARGET allocateId(IncompleteKey)]
public Key allocateIdSingle() {
// [START allocateIdSingle]
KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
IncompleteKey incompleteKey = keyFactory.newKey();
// let cloud datastore automatically assign an id
Key key = datastore.allocateId(incompleteKey);
// [END allocateIdSingle]
return key;
}
use of com.google.cloud.datastore.IncompleteKey in project google-cloud-java by GoogleCloudPlatform.
the class ITDatastoreTest method testGet.
@Test
public void testGet() {
Entity entity = DATASTORE.get(KEY3);
assertNull(entity);
entity = DATASTORE.get(KEY1);
assertEquals(ENTITY1, entity);
StringValue value1 = entity.getValue("str");
assertEquals(STR_VALUE, value1);
BooleanValue value2 = entity.getValue("bool");
assertEquals(BOOL_VALUE, value2);
ListValue value3 = entity.getValue("list");
assertEquals(LIST_VALUE2, value3);
TimestampValue value4 = entity.getValue("date");
assertEquals(TIMESTAMP_VALUE, value4);
LatLngValue value5 = entity.getValue("latLng");
assertEquals(LAT_LNG_VALUE, value5);
FullEntity<IncompleteKey> value6 = entity.getEntity("partial1");
assertEquals(PARTIAL_ENTITY1, value6);
ListValue value7 = entity.getValue("emptyList");
assertEquals(EMPTY_LIST_VALUE, value7);
assertEquals(7, entity.getNames().size());
assertFalse(entity.contains("bla"));
}
Aggregations