java - 在 App Engine 上将实体转换为它的类类型

标签 java google-app-engine google-cloud-datastore

我有 Entity 对象,我想获取该对象。 目前,我正在使用

PersistenceManager.getObjectById(Object.class, Entity.getId());

问题在于,当实体中的所有属性都已可用时,这是对数据存储的额外调用。

最佳答案

这不是我认为您正在寻找的 Elixir ;它需要一些繁重的工作才能完成。

DAO代码

DatastoreService datastore = DatastoreServiceFactory
 .getDatastoreService();
List<Foo> results = new ArrayList<Foo>();

Query query = new Query("Foo");
List<Entity> entities = datastore.prepare(query).asList(
  FetchOptions.Builder.withDefaults());

for (Entity entity : entities) {
  results.add(new Foo(entity));
}

Foo 类

public Foo(Entity entity) {
  // TODO get properties from entity and populate POJO
  this.bar=entity.getProperty("bar");
  //get the key
  //if the @PrimaryKey is a Long use this
  this.id=entity.getKey().getId();
  //if the @PrimaryKey is a String use this
  this.id=entity.getKey().getName();
}

a way to convert appengine datastore Entity to my object?

关于java - 在 App Engine 上将实体转换为它的类类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2249328/

相关文章:

JavaFX - 显示禁用标签的背景

java - Play 框架中的表单验证

google-app-engine - 使用 5 个 SNI 证书插槽,GAE 每秒可以支持多少次查询?

php - 将文件从 App Engine 上传到 Google Drive

python - 如何在不实例化模型的情况下获取数据存储(应用程序引擎)记录?

java - 按键获取GAE实体

java - 使用 DocumentBuilder 从 xml 文件中提取值

java - 如何连续播放AudioInputStream的音频?

google-app-engine - 从 GAE 将文件写入 Dropbox 帐户

java - 谷歌数据存储使用java插入日期作为空值