这些 user/userParam 引用如何与客户和帐户查找相关?
在以下代码示例中,用户如何操作/userParam
引用与 Customer
和 Account
查找相关,以及 Customer
和 Account
之间的关系是什么>?
// PersistenceManager pm = ...;
Transaction tx = pm.currentTransaction();
User user = userService.currentUser();
List<Account> accounts = new ArrayList<Account>();
try {
tx.begin();
Query query = pm.newQuery("select from Customer " +
"where user == userParam " +
"parameters User userParam");
List<Customer> customers = (List<Customer>)
query.execute(user);
query = pm.newQuery("select from Account " +
"where parent-pk == keyParam " +
"parameters Key keyParam");
for (Customer customer : customers) {
accounts.addAll((List<Account>)
query.execute(customer.key));
}
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
In the following code example how do the user/userParam
references relate to the Customer
and Account
lookups and what is the relationship between Customer
and Account
?
// PersistenceManager pm = ...;
Transaction tx = pm.currentTransaction();
User user = userService.currentUser();
List<Account> accounts = new ArrayList<Account>();
try {
tx.begin();
Query query = pm.newQuery("select from Customer " +
"where user == userParam " +
"parameters User userParam");
List<Customer> customers = (List<Customer>)
query.execute(user);
query = pm.newQuery("select from Account " +
"where parent-pk == keyParam " +
"parameters Key keyParam");
for (Customer customer : customers) {
accounts.addAll((List<Account>)
query.execute(customer.key));
}
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个查询是查询所有客户
其中 Customer.user == userParam
。所以看起来客户与用户具有一对一的关系(大概这是 GAE 用户类)。第二个查询是查询所有帐户,其中帐户的父密钥是客户的密钥。所以看起来客户与客户有父子关系。
总而言之,每个用户都有一个客户,每个客户可以有多个子帐户。一个帐户只能有一个父客户。
The first query is querying all Customers
where Customer.user == userParam
. So it looks like Customers have a one-to-one relationship with Users (presumably this is the GAE User class).The second query is querying all Accounts where the account's parent-key is the key of a customer. So it looks like Customers have a parent-child relationship with Accounts.
Putting it all together, every User has one Customer, and every Customer can have multiple child Accounts. An Account can only have one parent Customer.