1
votes

Newbie to Datastore. I found two tutorials on the GCP site to use Datastore on App Engine. Which one should I use?

There are subtle differences in how the APIs work.

https://cloud.google.com/datastore/docs/datastore-api-tutorial uses package (import com.google.appengine.api.datastore.Entity;)

vs.

https://cloud.google.com/appengine/docs/standard/java/building-app/cloud-datastore uses package (import com.google.cloud.datastore.Entity)

Question: Is there a preferred package to use and call the datastore API while on App Engine - com.google.cloud.datastore.Entity vs. com.google.appengine.api.datastore.Entity?

1
Ok.. now when there are clearly 2 different ways of doing the same thing , why would one down vote the question when I ask which is a better way to do things ?Srikanth
I have noticed a performance difference between the two. Low Level AppEngine DataStore library is faster on AppEngine compared to the more generic DataStore Client Library running on AppEnginekdabir

1 Answers

3
votes

The library with this package com.google.appengine.api.datastore (aka "Datastore API for Java") is intended for use by Java 7 and Java 8 applications which run on AppEngine.

The library with this package com.google.cloud.datastore (aka "Cloud Datastore client library") is intended for use by any Java 8 application regardless of where it is deployed (GKE, GCE, on-premises etc)

From the docs:

Datastore API for Java is a low-level Datastore API built into the App Engine SDK to provide direct access to all Datastore features and is described throughout the App Engine Datastore documentation for Java.

Cloud Datastore client library is a library that can be used by apps in the App Engine standard Java 8 runtime, by applications in the App Engine flexible environment, and by non App Engine applications as well.

So, according to Google, both are valid choices subject to these limitations ...

  • If you are running Java 7 then you cannot use Cloud Datastore client library
  • If your application is not deployed to AppEngine then you cannot use Datastore API for Java

These limitations describe the scenarios in which one or other of these libraries cannot be used. Google offers no advice on which one should be used. This is because the two libraries are functionally equivalent so, assuming that the limitations described above do not apply to your usage, the choice is probably moot.