What does this do and why does it require a transaction?

Posted by S. Palin on Stack Overflow See other posts from Stack Overflow or by S. Palin
Published on 2010-03-31T08:01:14Z Indexed on 2010/03/31 8:03 UTC
Read the original article Hit count: 308

What does the following code example do and why does it require a transaction?

    // 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();
        }
    }

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about java