Java Reference
In-Depth Information
Here is the same query using the method style of calling. This method is a little more
straightforward and is easier to maintain than the string format.
Query qry = pm.newQuery(Contact.class);
qry.setFilter("country == countryParam");
qry.setOrdering("dateCreated desc");
qry.declareParameters("String countryParam");
List<Contact> contacts = (List<Contact>) qry.execute("USA");
Again, JDOQL is very flexible. You can mix these two styles according to your business
requirements to create some interesting and dynamic combinations.
Query qry = pm.newQuery(Contact.class,
"country == countryParam order by dateCreated desc");
qry.declareParameters("String countryParam");
List<Contact> contacts = (List<Contact>) qry.execute("USA");
Filtering Queries
Queries can contain zero or more filters specifying a field name, an operator, and a
value. Values cannot refer to another property or be calculated in terms of other
properties. Your application must provide the values for the filters. JDOQL supports
only the following filter operators: < , <= , == , >=, and > .
When using the JDOQL string syntax, you can only use && (logical “and”) to
separate your filters. The datastore does not support other combinations (for
example, “or”, “not”).
Another restriction for queries pertains to inequality filters. You must not
construct your queries to contain inequality filters on more than one property.
However, the same property may contain multiple inequality filters, as shown in this
example.
qry.setFilter("countryName == 'USA' && stateName == stateName");
qry.declareParameters("String stateName");
 
Search WWH ::




Custom Search