I am trying to get a collection of objects that are stored in the
database using JDO. Once the objects have been retrieved, they are
marshaled into JSON and sent to the client.
I need some help in deciding which of the following two approaches is
the better one:
Approach 1:
// Using detachCopy(...)
public List<Employee> getEmployee(User user) {
PersistenceManager pm = PMF.get().getPersistenceManager();
List<Employee> employees, detached = null;
Query query = pm.newQuery(Employee.class);
try {
employees = (List<Employee>)query.execute();
detached = pm.detachCopyAll(employees);
} finally {
pm.close();
}
return detached;
}
Approach 2:
// Using Transaction with setDetachAllOnCommit(true)
public List<Employee> getEmployee(User user) {
PersistenceManager pm = PMF.get().getPersistenceManager();
pm.setDetachAllOnCommit(true);
Transaction tx = persistenceManager.currentTransaction(); p.p1 {margin:
0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
Query query = pm.newQuery(Employee.class);
List<Employee> employees = null;
try {
tx.begin();
employees = (List<Employee>)query.execute(); tx.commit);
} finally {
pm.close();
}
return employees;
}
Any help/advise is greatly appreciated.
-- Thomas
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.