Java Reference
In-Depth Information
class ExecuteFindOrdersQuery implements JdoCallback {
private final String queryString;
private final int pageSize;
private final Map parameters;
private ExecuteFindOrdersQuery(String queryString,
int pageSize, Map parameters) {
this.queryString = queryString;
this.pageSize = pageSize;
this.parameters = parameters;
}
public Object doInJdo(PersistenceManager pm)
throws JDOException {
Query query = pm.newQuery(queryString.toString());
KodoQuery kquery = (KodoQuery) query;
FetchConfiguration fc = kquery.getFetchConfiguration();
fc.addField(Order.class.getName() + ".restaurant");
List result = new ArrayList((List) query
.executeWithMap(parameters));
boolean more = result.size() > pageSize;
if (more)
result.remove(pageSize);
return new PagedQueryResult(result, more);
}
}
The doInJdo() method creates a query, calls configureFetchGroups() , executes
the query, and creates the PagedQueryResult containing the list of orders and the
more flag.
But sometimes you must execute queries that require the use of SQL features
such as optimizer hints in order to achieve good performance. That is when you
must use a JDO native SQL query.
11.5 A Hibernate design example
As with JDO , queries in a Hibernate application are typically executed by domain
model repositories. The Hibernate version of the OrderRepository , which is pretty
similar to the JDO version, is shown in figure 11.6. The OrderRepository interface
is implemented by HibernateOrderRepositoryImpl , which uses the Spring Hiber-
nateTemplate to construct and execute a Hibernate criteria query.
The OrderRepository interface is implemented by the HibernateOrderReposi-
toryImpl class. It uses a Spring HibernateTemplate to execute a HibernateCallback
 
 
 
 
Search WWH ::




Custom Search