11.2. JDOQL

JDOQL is a datastore-neutral query language based on Java. It relies
solely on your object model, completely abstracting the details of the
underlying data model. As you have already seen, the syntax of JDOQL
is virtually identical to Java syntax. In fact, a good trick when
writing a JDOQL string is to pretend that you are writing a method of
the query's candidate class. You have access to all of the class'
persistent fields, and to the this keyword. There
are, however, some notable ways in which JDOQL differs from Java:

While it is important to note the differences between JDOQL and Java
enumerated in the list above, it is just as important to note what
is not in the list. Mathematical operators,
logical operators, instanceof, casting,
field traversal, and static field access are omitted, meaning
they are all fully supported by JDOQL.

We demonstrate some of the interesting aspects of JDOQL below.

Example 11.2. Relation Traversal and Mathematical Operations

Find all magazines whose sales account for over 1% of the
total revenue for the publisher. Notice the use of standard Java
"dot" notation to traverse into the persistent fields of
Magazine's publisher
relation.

Find all magazines whose publisher's name is "Random House" or
matches a regular expression, and whose price is less than or equal
to 10 dollars. Here, we use single-quoted string literals to avoid
having to escape double quotes within the filter string. Notice
also that we compare strings with == rather
than the equals method.