136 Queries with JDOQL collection is the entire

136 Queries with JDOQL collection is the entire extent of BusinessPartner (including subclasses). It is important to note that the objects being returned each time next() is called on the Iterator are in fact instances of the concrete subclasses of BusinessPartner: Company, Charity, and Individual. 8.4.2 Query with ordering The next step is to add a simple ordering declaration. The example below orders the query results according to name, and then according to partnerId descending. Thus if multiple partners had the same name they would appear in the descending sequence of their partnerIds. Extent partnerExt = pm.getExtent(BusinessPartner.class, true); Query q = pm.newQuery(partnerExt); q.setOrdering(”name ascending, partnerId descending”); Collection c = (Collection) q.execute(); The ordering declaration comprises any number of persistent field names, each paired with the keyword ascending or descending as appropriate. These pairs are separated with commas. 8.4.3 Query with filter For our next example, let s apply a simple filter to the query. We will discuss the full suite of available filter operators shortly. For now we will use the == operator to select only those business partners with a specific name. Extent partnerExt = pm.getExtent(BusinessPartner.class, true); String filter = “name == “Ogilvie Partners”"; Query q = pm.newQuery(partnerExt, filter); q.setOrdering(”name ascending, partnerId descending”); Collection c = (Collection) q.execute(); We are now using a different newQuery() method that returns a query with the filter declaration assigned. The filter declaration is a String containing the boolean expression. Although this expression is based on Java syntax there are significant differences, such as the use of the == operator for testing string equivalence above. In the next section we examine the capabilities and syntax of filter expressions in detail. 8.5 Query filter expressions The filter expression for a query is optional. If no filter is set, the filter will be deemed to evaluate to true in all cases, and the query result will be the whole candidate collection.

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider

Comments are closed.