7
votes

I am developing an appengine project and storing my data using Google Datastore. I am using different Datastore libraries as they are the ones used in the examples, but I find it kind of weird that I have to use both:

If I check the docs for querying, in this example they use this library to process queries:

com.google.appengine.api.datastore

https://cloud.google.com/appengine/docs/java/datastore/retrieving-query-results

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(q); Entity result = pq.asSingleEntity();

However, in this example to store data, they use

com.google.cloud.datastore

https://cloud.google.com/datastore/docs/concepts/entities

Entity task = Entity.builder(taskKey) .set("category", "Personal") .set("done", false) .set("priority", 4) .set("description", "Learn Cloud Datastore") .build();

Right now I am able to use both but I am wondering which one is better for which kind of purpose or if they are just the same libraries with different packages. However, I am looking for a way to remove one of them.

1

1 Answers

9
votes

com.google.appengine.api.datastore - is specifically designed to work from Apps deployed on AppEngine. The API does not work if you later decide to deploy your App elsewhere (e.g. Compute Engine).

com.google.cloud.datastore - is the new API that allows you to access Datastore from Apps deployed anywhere, not just AppEngine.

com.google.appengine.api.datastore - has some additional features that the other one does not have (at least not yet). For example, OR condition in your Datastore queries, ability to integrate with other AppEngine Services such as MemCache, FullText Search, etc.