Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Developer's Guide

- Previous: Query Variables
- Next: Performance-Related Features

## JDOQL Examples

This section provides a few query examples.

### Example 1

The following query returns all players called Michael. It defines a filter that compares the name field with a string literal:

    name == "Michael"

The `finder` element of the `sun-ejb-jar.xml` file looks like this:

    <finder>
       <method-name>findPlayerByName</method-name>
       <query-filter>name == "Michael"</query-filter>
    </finder>

### Example 2

This query returns all products in a specified price range. It defines two query parameters which are the lower and upper bound for the price: double low, double high. The filter compares the query parameters with the price field:

    low < price && price < high

Query ordering is set to `price ascending`.

The `finder` element of the `sun-ejb-jar.xml` file looks like this:

    <finder>
       <method-name>findInRange</method-name>
       <query-params>double low, double high</query-params>
       <query-filter>low &lt; price &amp;&amp; price &lt high</query-filter>
       <query-ordering>price ascending</query-ordering>
    </finder>

### Example 3

This query returns all players having a higher salary than the player with the specified name. It defines a query parameter for the name `java.lang.String name`. Furthermore, it defines a variable to which the player’s salary is compared. It has the type of the persistence capable class that corresponds to the bean:

        mypackage.PlayerEJB_170160966_JDOState player

The filter compares the salary of the current player denoted by the `this` keyword with the salary of the player with the specified name:

        (this.salary > player.salary) && (player.name == name)

The `finder` element of the `sun-ejb-jar.xml` file looks like this:

    <finder>
       <method-name>findByHigherSalary</method-name>
       <query-params>java.lang.String name</query-params>
       <query-filter>
          (this.salary &gt; player.salary) &amp;&amp; (player.name == name)
       </query-filter>
       <query-variables>
          mypackage.PlayerEJB_170160966_JDOState player
       </query-variables>
    </finder>

- Previous: Query Variables
- Next: Performance-Related Features

- © 2010, Oracle Corporation and/or its affiliates