简体   繁体   中英

What is the difference between libraries appengine.api.datastore and com.google.cloud.datastore?

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM