Java Reference
In-Depth Information
StringBuffer queryString,
Map parameters) {
PagedQueryResult result = (PagedQueryResult) getJdoTemplate()
.execute(
new ExecuteFindOrdersQuery(queryString
.toString(), pageSize, parameters));
return result;
}
}
Let's look at the details:
B
The
findOrders()
method calls a series of helper methods that construct a
JDOQL
query from the
OrderSearchCriteria
and execute it.
The
makeSelectFrom()
method creates the initial part of the query.
The
addWhere()
method constructs the
where
clause and appends it to the query.
It has conditional logic that adds an expression to the
where
clause for each of the
search criteria that has been specified in the
OrderSearchCriteria
object. The
addWhere()
method returns a map containing the query parameters, which is later
passed to
Query.executeWithMap()
.
The
addOrderBy()
method adds an
order by
clause to the query.
The
addRange()
method adds a
range
clause to the query.
The
executeQuery()
method executes the query using
ExecuteFindOrdersQuery
,
which is a
JdoCallback
.
As you can see, we had to write a lot of code to generate a
JDO
query. Even if some
code is refactored into a reusable utility class, the repository would still contain
some messy conditional logic and
JDOQL
fragments, which makes it error-prone
and difficult to maintain. But we mostly have to tolerate this problem because of
the benefits of
JDOQL
.
C
D
E
F
G
11.4.2
The ExecuteFindOrdersQuery class
ExecuteFindOrdersQuery
is a
JdoCallback
that is executed by
JDOOrderRepository-
Impl
. It defines a
doInJdo()
method, which is called by the
JdoTemplate
. This
method uses the Kodo
JDO
API
s to configure the object loading and execute the
query. Here is the code:
Search WWH ::
Custom Search