use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class RemoteApiExample method main.
/**
* A simple API client.
*
* @param args .
* @throws IOException .
*/
public static void main(String[] args) throws IOException {
String serverString = args[0];
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 443).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
} finally {
installer.uninstall();
}
}
use of com.google.appengine.api.datastore.DatastoreService in project cloudinary_java by cloudinary.
the class PhotoController method listPhotos.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String listPhotos(ModelMap model) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key photoKey = KeyFactory.createKey("photos", "album");
List<Entity> photoEntities = datastore.prepare(new Query("photo", photoKey)).asList(FetchOptions.Builder.withDefaults());
List<PhotoUpload> photos = new java.util.ArrayList<PhotoUpload>();
for (int i = 0, n = photoEntities.size(); i < n; i++) {
photos.add(new PhotoUpload(photoEntities.get(i)));
}
model.addAttribute("photos", photos);
return "photos";
}
use of com.google.appengine.api.datastore.DatastoreService in project google-oauth-java-client by googleapis.
the class AppEngineCredentialStore method delete.
@Override
public void delete(String userId, Credential credential) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key key = KeyFactory.createKey(KIND, userId);
datastore.delete(key);
}
use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class TransactionsTest method creatingAnEntityInASpecificEntityGroup.
@Test
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public void creatingAnEntityInASpecificEntityGroup() throws Exception {
String boardName = "my-message-board";
// [START creating_an_entity_in_a_specific_entity_group]
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
String messageTitle = "Some Title";
String messageText = "Some message.";
Date postDate = new Date();
Key messageBoardKey = KeyFactory.createKey("MessageBoard", boardName);
Entity message = new Entity("Message", messageBoardKey);
message.setProperty("message_title", messageTitle);
message.setProperty("message_text", messageText);
message.setProperty("post_date", postDate);
Transaction txn = datastore.beginTransaction();
datastore.put(txn, message);
txn.commit();
// [END creating_an_entity_in_a_specific_entity_group]
}
use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class TransactionsTest method transactionalTaskEnqueuing.
@Test
public void transactionalTaskEnqueuing() throws Exception {
// [START transactional_task_enqueuing]
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Queue queue = QueueFactory.getDefaultQueue();
Transaction txn = datastore.beginTransaction();
// ...
queue.add(txn, TaskOptions.Builder.withUrl("/path/to/handler"));
// ...
txn.commit();
// [END transactional_task_enqueuing]
}
Aggregations