这些 user/userParam 引用如何与客户和帐户查找相关?

发布于 2024-08-27 13:28:54 字数 1210 浏览 6 评论 0原文

以下代码示例中,用户如何操作/userParam 引用与 CustomerAccount 查找相关,以及 CustomerAccount 之间的关系是什么>?

    // 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2024-09-03 13:28:54

第一个查询是查询所有客户 其中 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文