The datastore is designed with web applications in mind, with an emphasis on read and query performance.
要知道,datastore是为Web应用程序而设计的,其重点关注的是读取和查询的性能。
All queries are pre-indexed for fast results over very large data sets.
为了在大量数据集中快速查询到结果,在datastore中所做的所有查询都必须事先建立索引。与在关系型数据库系统中建立索引的方式不同,在Google App Engine for Java应用中,整个应用程序所使用到的索引被保存在一个XML文件中。你可以手工编写,也可以由Google Plugin for Eclipse自动生成。
With the App Engine datastore, every attempt to create, update or delete an entity happens in a transaction
.
对App Engine datastore而言,每次创建、更新或删除一个实体的行为都在一个事务中完成。
All entities fetched, created, updated or deleted in a transaction must be in the same entity group.
在一个事务中,对多个实体进行增、删、改、查操作时,这些实体必须属于同一“实体组”。在这里,对“实体组”的概念不好理解,下面以一组代码段来解释:
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String firstName;
@Persistent
private String lastName;
@Persistent
private Date hireDate;
...
}
public class ContactInfo {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String streetAddress;
@Persistent
private String city;
@Persistent
private String stateOrProvince;
@Persistent
private String zipCode;
...
}
Employee em = new Employee("Jiankang", "Jin", new Date());
ContactInfo info = new ContactInfo("ZhiChun Road", "Beijing",
"Beijing", "010");
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(em);
pm.makePersistent(info);
tx.commit();
} catch (Exception e) {
System.out.println(e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
运行Servlet,在控制台看到:
javax.jdo.JDOFatalUserException: Illegal argument
NestedThrowables:
java.lang.IllegalArgumentException: can't operate on multiple entity groups in a single transaction.
修改后:
public class Employee {
...
@Persistent
private ContactInfo contactInfo;
...
}
ContactInfo info = new ContactInfo("ZhiChun Road", "Beijing",
"Beijing", "010");
Employee em = new Employee("Jiankang", "Jin", new Date(), info);
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(em);
pm.makePersistent(info);
tx.commit();
} catch (Exception e) {
System.out.println(e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
再次运行Servlet,无异常。查看http://127.0.0.1:8080/_ah/admin,Kind Employee有一条记录,Kind ContactInfo有一条记录(注意:不是两条,代码pm.makePersistent(info)是不必要的,即使写了,也只保存一条ContactInfo记录)。而且,The key of the ContactInfo
entity has the key of the Employee
entity as its entity group parent. 这句话可能引起歧义,我原以为前者的key包含后者的key,但结果是:
the key of Employee is 'agByDgsSCEVtcGxveWVlGAEM',
and the key of ContactInfo is
'agByHwsSCEVtcGxveWVlGAEMCxILQ29udGFjdEluZm8YAgw'.
在Google Groups上请教了该问题,上述现象是正常的,两者的key确实不是简单的字符串包含关系。但可以肯定的是:
KeyFactory.stringToKey(employeeKeyString).equals(KeyFactory.stringToKey(con
tactInfoKeyString).getParent())
参见:http://groups.google.com/group/google-appengine-java/browse_thread/thread/76ca595de10a5a5a/95509d1364acc9d4?lnk=gst&q=jinjiankang1980#95509d1364acc9d4
Entity groups are defined by a hierarchy of relationships between entities.
如果多个实体间有关联关系,则它们组成一个实体组。据我我理解,这里的“a hierarchy of relationships”就是指UML中的组合或聚合。
(如何使用附件源代码注:使用Google Eclipse插件建立工程,工程名GAE_Test,包名com.gaetest)
(所使用的GAE JDK:appengine-java-sdk-1.2.2)
分享到:
相关推荐
NULL 博文链接:https://jinjiankang.iteye.com/blog/436821
Google Datastore的JAR
Android DataStore使用和封装
This practical guide shows intermediate and advanced web and mobile app developers how to build highly scalable Java applications in the cloud with Google App Engine. The flagship of Google's Cloud ...
The journey begins with a look at the Google Plugin for Eclipse and finishes with a working web application that uses Google Web Toolkit, Google Accounts, and Bigtable. Along the way, you’ll dig ...
谷歌云数据存储注意:此存储库包含适用于 Google Cloud Datastore 的低级 Java 和 Python 客户端库。 有关这些语言的更多惯用和可用客户端库,请访问库的库。 您还可以在 Cloud Datastore 的上找到各种语言的受支持...
PB虛擬datastore用法-----------------------------------------------------------------------
一 、DataStore介绍 Jetpack DataStore 是一种改进的新数据存储解决方案,允许使用协议缓冲区存储键值对或类型化对 象。 DataStore 以异步、一致的事务方式存储数据,克服了 SharedPreferences(以下统称为SP)的 ...
在微服务结合前端AJAX越加普遍的今天,以一种没有后端的web开发理念,极大缩小了开发成本,此博客结合这个概念做了一个数据服务原型。 主要有如下特色: 用户只需以JSON格式定义表结构,以所见即所得的方式快速创建...
Laravel开发-laravel-datastore Laravel数据存储框架。
NULL 博文链接:https://woods.iteye.com/blog/295703
matlab开发-datastore。一种工具,用于在matlab会话之间保存与登录用户相关的数据。
Google APIs Client Library for Java Library Maintenance Overview Highlighted Features Dependencies Important Warnings @Beta Deprecations Documentation Links Library Maintenance These client ...
完整介绍创建datastore,根据条件在datastore中查询数据、取值;将取出的值赋值到新窗体新增行的字段中。
However, building and deploying scalable web applications using Google Web Toolkit and Google App Engine for Java can be challenging even to developers. The start to finish approach of this book ...
前端开源库-datastore-fs数据存储fs,带有文件系统后端的数据存储实现
数据存储区用户界面一个简单的docker容器,其中包含用于浏览的for-devs用户界面该容器仅运行NodeJS 程序包,但具有附加功能,它将基于环境变量设置项目,因此可以在docker-compose上下文中使用,并提供流畅的开发...
适用于Node.js的Cloud Datastore客户端...安装客户端库npm install @google-cloud/datastore使用客户端库// Imports the Google Cloud client libraryconst { Datastore } = require ( '@google-cloud/datastore' ) ;//
Pick the right managed service for your data needs, choosing intelligently between Datastore, BigTable, and BigQuery Migrate existing Hadoop, Spark, and Pig workloads with minimal disruption to your ...