use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method getEntityWithKey.
/**
* Example of getting an entity.
*/
// [TARGET get(Key, ReadOption...)]
// [VARIABLE "my_key_name"]
public Entity getEntityWithKey(String keyName) {
// [START getEntityWithKey]
Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
Entity entity = datastore.get(key);
// [END getEntityWithKey]
return entity;
}
use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method batchUpdateEntities.
/**
* Example of updating multiple entities.
*/
// [TARGET update(Entity...)]
// [VARIABLE "my_key_name_1"]
// [VARIABLE "my_key_name_2"]
public void batchUpdateEntities(String keyName1, String keyName2) {
// [START batchUpdateEntities]
Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
entityBuilder1.set("propertyName", "updatedValue1");
Entity entity1 = entityBuilder1.build();
Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
entityBuilder2.set("propertyName", "updatedValue2");
Entity entity2 = entityBuilder2.build();
datastore.update(entity1, entity2);
// [END batchUpdateEntities]
}
use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method batchDeleteEntities.
/**
* Example of deleting multiple entities.
*/
// [TARGET delete(Key...)]
// [VARIABLE "my_key_name1"]
// [VARIABLE "my_key_name2"]
public void batchDeleteEntities(String keyName1, String keyName2) {
// [START batchDeleteEntities]
Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
datastore.delete(key1, key2);
// [END batchDeleteEntities]
}
use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method putSingleEntity.
/**
* Example of putting a single entity.
*/
// [TARGET put(FullEntity)]
// [VARIABLE "my_key_name"]
public void putSingleEntity(String keyName) {
// [START putSingleEntity]
Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
Entity.Builder entityBuilder = Entity.newBuilder(key);
entityBuilder.set("propertyName", "value");
Entity entity = entityBuilder.build();
datastore.put(entity);
// [END putSingleEntity]
}
use of com.google.cloud.datastore.Key in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreSnippets method fetchEntitiesWithKeys.
/**
* Example of fetching a list of Entity objects.
*/
// [TARGET fetch(Iterable, ReadOption...)]
// [VARIABLE "my_first_key_name"]
// [VARIABLE "my_second_key_name"]
public List<Entity> fetchEntitiesWithKeys(String firstKeyName, String secondKeyName) {
// [START fetchEntitiesWithKeys]
KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
Key firstKey = keyFactory.newKey(firstKeyName);
Key secondKey = keyFactory.newKey(secondKeyName);
List<Entity> entities = datastore.fetch(Lists.newArrayList(firstKey, secondKey));
for (Entity entity : entities) {
// do something with the entity
}
// [END fetchEntitiesWithKeys]
return entities;
}
Aggregations