Java Reference
In-Depth Information
ORDER BY o.ORDER_ID ASC
</select>
<resultMap id="OrderResultMap"
class="net.chrisrichardson.foodToGo.
bbbbbbbbb bb placeOrderTransactionScripts.details.
bbbbbbbbbb OrderSummaryDTO">
<result property="orderId" column="ORDER_ID" />
<result property="restaurantName" column="RESTAURANT_NAME" />
</resultMap>
</sqlMap>
The query contains a FIRST_ROWS(N) optimizer hint that tells Oracle how many rows
the application wants. The dynamic mapped statement uses the <isNotEmpty> ele-
ment to conditionally include SQL fragments based on the properties of an Order-
SearchCriteria object. Each of the <isNotEmpty> elements adds to the SELECT
statement's WHERE clause. For example, <isNotEmpty property="restaurantName">…
</isNotEmpty> adds AND r.name = #restaurantName# to the WHERE clause if the res-
taurantName property is not blank or null.
i BATIS supports many other conditional elements in addition to the
<isNotEmpty> element, including an <iteration> element that iterates through a
list. See the i BATIS documentation for more information.
11.2.2
Using ROWNUM to select the rows
For some queries, navigating through the result set is the best approach. For oth-
ers, a more efficient approach is to use a query that uses a ROWNUM -like feature to
return only the needed rows. To execute this kind of query, the DAO can use the
version of queryForList() that returns the entire result set and pass the starting-
Index and the pageSize as parameters to the mapped statement. One convenient
way to do this is to call queryForList() with a Map containing the startingIndex ,
pageSize , and the search criteria. Here is a version of findOrders() that does this:
public PagedQueryResult findOrders (int startingIndex,
int pageSize, OrderSearchCriteria criteria) {
Map map = new HashMap();
map.put("startingIndex", new Integer(startingIndex));
map.put("maxRows", new Integer(pageSize + startingIndex
+ 2));
map.put("criteria", criteria);
List result = getSqlMapClientTemplate().queryForList(
 
 
 
 
Search WWH ::




Custom Search