Google App Engine 上的云数据存储 Java。使用哪个包?

Google Cloud Datastore on App Engine with Java. Which package to use?

Datastore 新手。我在 GCP 网站上找到了两个关于在 App Engine 上使用 Datastore 的教程。我应该使用哪一个?

API 的工作方式存在细微差别。

https://cloud.google.com/datastore/docs/datastore-api-tutorial 使用包(导入com.google.appengine.api.datastore.Entity;)

对比

https://cloud.google.com/appengine/docs/standard/java/building-app/cloud-datastore 使用包(导入com.google.cloud.datastore.Entity)

问题:在 App Engine 上使用和调用数据存储 API 时是否有首选包 - com.google.cloud.datastore.Entity 与 com.google.appengine.api.datastore.Entity?

包含此软件包 com.google.appengine.api.datastore 的库(又名“Datastore API for Java”)供 Java 7 和 Java 8 使用AppEngine 上 运行 的应用程序。

包含此包的库 com.google.cloud.datastore(又名“云数据存储客户端库”)旨在供任何 Java 8 应用程序使用,无论其部署在何处(GKE、GCE、on-premises等)

来自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.

因此,根据 Google,两者都是受这些限制的有效选择...

  • 如果您是 运行ning Java 7,则无法使用 Cloud Datastore 客户端库
  • 如果您的应用程序未部署到 AppEngine,则您无法将 Datastore API 用于 Java

这些限制描述了其中一个或其他库不能的场景。 Google 没有提供关于应该 使用哪一个的建议。这是因为这两个库在功能上是等价的,所以假设上述限制不适用于您的使用,选择可能没有实际意义。