| <!DOCTYPE html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| <!-- No caching headers --> |
| <meta http-equiv="cache-control" content="no-cache"/> |
| <meta http-equiv="pragma" content="no-cache"/> |
| <meta http-equiv="expires" content="-1"/> |
| <meta name="keywords" content="JDO, Apache, Java, Data, Objects"/> |
| <meta name="description" content="Apache JDO - Java Data Objects"/> |
| |
| <title>JDOQL</title> |
| |
| <link rel="icon" type="image/png" href="https://apache.github.io/db-jdo-site/images/JDO_32x32.png"/> |
| |
| <!-- |
| Apache JDO Documentation Template |
| ================================== |
| This template derived various aspects from Apache Deltaspike template, the Apache ISIS template and the Datanucleus template. |
| This template uses |
| * Bootstrap v3.3.7 (https://getbootstrap.com/) for navbar. |
| * Asciidoctor "foundation" CSS |
| * Bootswatch "cosmo" theme for Bootstrap (https://bootswatch.com/cosmo). |
| * Bootstrap TOC plugin v0.4.1 (https://afeld.github.io/bootstrap-toc/) for the table of contents. |
| * jQuery (necessary for Bootstrap's JavaScript plugins) |
| * Font-Awesome for some icons used by Asciidoctor |
| NOTE: tried using Font-Awesome CSS hosted locally but then fails to work! |
| --> |
| <link href="css/bootswatch/3.3.7/bootstrap-cosmo.css" rel="stylesheet"/> |
| <link href="css/bootstrap-toc/0.4.1/bootstrap-toc.min.css" rel="stylesheet"/> |
| |
| <link href="css/asciidoctor/foundation.css" rel="stylesheet"/> |
| <link href="css/datanucleus_theme.css" rel="stylesheet"/> |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> |
| <script src="js/bootstrap/3.3.7/bootstrap.min.js"></script> |
| <script src="js/bootstrap-toc/0.4.1/bootstrap-toc.min.js"></script> |
| |
| <!-- Coderay syntax formatter --> |
| <style type="text/css"> |
| /* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */ |
| /*pre.CodeRay {background-color:#f7f7f8;}*/ |
| .CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em} |
| .CodeRay span.line-numbers{display:inline-block;margin-right:.5em;color:rgba(0,0,0,.3)} |
| .CodeRay .line-numbers strong{color:rgba(0,0,0,.4)} |
| table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0;background:none} |
| table.CodeRay td{vertical-align: top;line-height:1.45} |
| table.CodeRay td.line-numbers{text-align:right} |
| table.CodeRay td.line-numbers>pre{padding:0;color:rgba(0,0,0,.3)} |
| table.CodeRay td.code{padding:0 0 0 .5em} |
| table.CodeRay td.code>pre{padding:0} |
| .CodeRay .debug{color:#fff !important;background:#000080 !important} |
| .CodeRay .annotation{color:#007} |
| .CodeRay .attribute-name{color:#000080} |
| .CodeRay .attribute-value{color:#700} |
| .CodeRay .binary{color:#509} |
| .CodeRay .comment{color:#998;font-style:italic} |
| .CodeRay .char{color:#04d} |
| .CodeRay .char .content{color:#04d} |
| .CodeRay .char .delimiter{color:#039} |
| .CodeRay .class{color:#458;font-weight:bold} |
| .CodeRay .complex{color:#a08} |
| .CodeRay .constant,.CodeRay .predefined-constant{color:#008080} |
| .CodeRay .color{color:#099} |
| .CodeRay .class-variable{color:#369} |
| .CodeRay .decorator{color:#b0b} |
| .CodeRay .definition{color:#099} |
| .CodeRay .delimiter{color:#000} |
| .CodeRay .doc{color:#970} |
| .CodeRay .doctype{color:#34b} |
| .CodeRay .doc-string{color:#d42} |
| .CodeRay .escape{color:#666} |
| .CodeRay .entity{color:#800} |
| .CodeRay .error{color:#808} |
| .CodeRay .exception{color:inherit} |
| .CodeRay .filename{color:#099} |
| .CodeRay .function{color:#900;font-weight:bold} |
| .CodeRay .global-variable{color:#008080} |
| .CodeRay .hex{color:#058} |
| .CodeRay .integer,.CodeRay .float{color:#099} |
| .CodeRay .include{color:#555} |
| .CodeRay .inline{color:#000} |
| .CodeRay .inline .inline{background:#ccc} |
| .CodeRay .inline .inline .inline{background:#bbb} |
| .CodeRay .inline .inline-delimiter{color:#d14} |
| .CodeRay .inline-delimiter{color:#d14} |
| .CodeRay .important{color:#555;font-weight:bold} |
| .CodeRay .interpreted{color:#b2b} |
| .CodeRay .instance-variable{color:#008080} |
| .CodeRay .label{color:#970} |
| .CodeRay .local-variable{color:#963} |
| .CodeRay .octal{color:#40e} |
| .CodeRay .predefined{color:#369} |
| .CodeRay .preprocessor{color:#579} |
| .CodeRay .pseudo-class{color:#555} |
| .CodeRay .directive{font-weight:bold} |
| .CodeRay .type{font-weight:bold} |
| .CodeRay .predefined-type{color:inherit} |
| .CodeRay .reserved,.CodeRay .keyword {color:#000;font-weight:bold} |
| .CodeRay .key{color:#808} |
| .CodeRay .key .delimiter{color:#606} |
| .CodeRay .key .char{color:#80f} |
| .CodeRay .value{color:#088} |
| .CodeRay .regexp .delimiter{color:#808} |
| .CodeRay .regexp .content{color:#808} |
| .CodeRay .regexp .modifier{color:#808} |
| .CodeRay .regexp .char{color:#d14} |
| .CodeRay .regexp .function{color:#404;font-weight:bold} |
| .CodeRay .string{color:#d20} |
| .CodeRay .string .string .string{background:#ffd0d0} |
| .CodeRay .string .content{color:#d14} |
| .CodeRay .string .char{color:#d14} |
| .CodeRay .string .delimiter{color:#d14} |
| .CodeRay .shell{color:#d14} |
| .CodeRay .shell .delimiter{color:#d14} |
| .CodeRay .symbol{color:#990073} |
| .CodeRay .symbol .content{color:#a60} |
| .CodeRay .symbol .delimiter{color:#630} |
| .CodeRay .tag{color:#008080} |
| .CodeRay .tag-special{color:#d70} |
| .CodeRay .variable{color:#036} |
| .CodeRay .insert{background:#afa} |
| .CodeRay .delete{background:#faa} |
| .CodeRay .change{color:#aaf;background:#007} |
| .CodeRay .head{color:#f8f;background:#505} |
| .CodeRay .insert .insert{color:#080} |
| .CodeRay .delete .delete{color:#800} |
| .CodeRay .change .change{color:#66f} |
| .CodeRay .head .head{color:#f4f} |
| </style> |
| </head> |
| <body data-spy="scroll" data-target="#toc"> |
| <!-- Navbar --> |
| <nav class="navbar navbar-default navbar-static-top"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <!-- Three line menu button for use on mobile screens --> |
| <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <!-- 'style' added to align image with navbar. FIX THIS --> |
| <a class="navbar-brand" href="https://db.apache.org/jdo/"> |
| <img style="margin-top: -12px;" alt="Brand" src="images/JDO_44x44.png"/> |
| </a> |
| <!-- TODO Any way to abstract the version from Maven? --> |
| <a class="navbar-brand" href="index.html">Apache JDO</a> |
| </div> |
| <!-- Navbar that will collapse on mobile screens --> |
| <div id="navbar" class="navbar-collapse collapse"> |
| <ul class="nav navbar-nav"> |
| <li class="dropdown"> |
| |
| <!-- menu item General --> |
| |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">General<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="why_jdo.html">Why JDO?</a></li> |
| <li><a href="getting-started.html">Getting Started</a></li> |
| <li><a href="specifications.html">Specifications</a></li> |
| <li><a href="tck.html">TCK</a></li> |
| <li><a href="javadoc.html">API Javadoc</a></li> |
| <li role="separator" class="divider"></li> |
| <li><a href="jdo_v_jpa.html">JDO v JPA</a></li> |
| <li><a href="jdo_v_jpa_api.html">JDO v JPA : API</a></li> |
| <li><a href="jdo_v_jpa_orm.html">JDO v JPA : ORM</a></li> |
| <li role="separator" class="divider"></li> |
| <li><a href="license.html">License</a></li> |
| <li><a href="impls.html">Implementations</a></li> |
| <li><a href="jdo_3_0_overview.html">JDO 3.0 Overview</a></li> |
| <li><a href="references.html">References</a></li> |
| <li><a href="glossary.html">Glossary</a></li> |
| </ul> |
| </li> |
| |
| <!-- menu item API Usage --> |
| |
| <li class="dropdown"> |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">API Usage<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="jdohelper.html">JDO Helper</a></li> |
| <li><a href="pmf.html">PersistenceManagerFactory</a></li> |
| <li><a href="pm.html">PersistenceManager</a></li> |
| <li><a href="transactions.html">Transactions</a></li> |
| <li><a href="attach_detach.html">Attach-Detach</a></li> |
| <li><a href="fetchgroups.html">Fetch Groups</a></li> |
| <li><a href="state_transition.html">Object States</a></li> |
| <li><a href="object_retrieval.html">Object Retrieval</a></li> |
| <li><a href="exceptions.html">Exceptions</a></li> |
| <li role="separator" class="divider"></li> |
| <li><a href="guides-replication.html">Data Replication</a></li> |
| </ul> |
| </li> |
| |
| <!-- menu item Types & Metadata --> |
| |
| <li class="dropdown"> |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Types & Metadata<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="class_types.html">Types of Classes</a></li> |
| <li><a href="field_types.html">Types of Fields</a></li> |
| <li role="separator" class="divider"></li> |
| <!-- <li class="dropdown-header">Metadata</li> --> |
| <li><a href="metadata.html">MetaData</a></li> |
| <li><a href="annotations.html">Annotations</a></li> |
| <li><a href="jdo_dtd.html">jdo DTD/XSD</a></li> |
| <li><a href="orm_dtd.html">orm DTD/XSD</a></li> |
| <li><a href="jdoquery_dtd.html">jdoquery DTD/XSD</a></li> |
| <li><a href="jdoconfig_dtd.html">jdoconfig DTD/XSD</a></li> |
| <li role="separator" class="divider"></li> |
| <li><a href="enhancement.html">Bytecode Enhancement</a></li> |
| </ul> |
| </li> |
| |
| <!-- menu item Query --> |
| |
| <li class="dropdown"> |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="background-color:#2385c6">Query<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="jdoql.html">JDOQL</a></li> |
| <li><a href="jdoql_result.html">Result</a></li> |
| <li><a href="jdoql_methods.html">Methods</a></li> |
| <li><a href="jdoql_quickref.pdf">Quick Ref PDF</a></li> |
| <li role="separator" class="divider"></li> |
| <li><a href="extents.html">Extents</a></li> |
| </ul> |
| </li> |
| |
| <!-- menu item Community --> |
| |
| <li class="dropdown"> |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Community<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="get-involved.html">Get Involved</a></li> |
| <li><a href="team-list.html">Project Team</a></li> |
| <li><a href="mail-lists.html">Mailing Lists</a></li> |
| <li><a href="faq.html">FAQ</a></li> |
| </ul> |
| </li> |
| |
| <!-- menu item Development --> |
| |
| <li class="dropdown"> |
| |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Development<span class="caret"></span></a> |
| |
| <ul class="dropdown-menu"> |
| <li><a href="roadmap.html">RoadMap / TODO</a></li> |
| <li><a href="downloads.html">Downloads</a></li> |
| <li><a href="source-code.html">Source Code</a></li> |
| <li><a href="coding-standards.html">Coding Standards</a></li> |
| <li><a href="issuetracking.html">Issue Tracking</a></li> |
| </ul> |
| </li> |
| </ul> |
| <!-- 'style' added to fix height of input box. FIX THIS --> |
| <form class="navbar-form navbar-left" role="search" id="search-form" action="https://www.google.com/search" method="get" style="padding: 1px 15px;"> |
| <div class="form-group"> |
| <input name="sitesearch" value="db.apache.org/jdo" type="hidden"> |
| <input name="q" type="text" class="form-control" placeholder="Search" style="margin-top: 7px; padding: 1px; border-radius: 5px; height: 30px; vertical-align: middle;"> |
| </div> |
| </form> |
| </div> |
| </div> |
| </nav> |
| <div class="container"> |
| |
| <div class="row-fluid"> |
| <div class="col-sm-9"> |
| <!-- <div class="page-title"> |
| <h3>JDOQL<a id="JDOQL"></a></h3> |
| </div> |
| --> |
| <div id="doc-content"> |
| <div class="sect1"> |
| <h2 id="index">JDOQL<a id="JDOQL"></a></h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>JDO defines ways of querying objects persisted into the datastore. It |
| provides its own object-based query language (JDOQL). JDOQL is designed |
| as the Java developers way of having the power of SQL queries, yet |
| retaining the Java object relationship that exist in their application |
| model. A typical JDOQL query may be set up in one of 2 ways. Here’s an |
| example</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Declarative JDOQL : |
| Query q = pm.newQuery(mydomain.Person.class, "lastName == \"Jones\" && age < age_limit"); |
| q.declareParameters("double age_limit"); |
| List results = (List)q.execute(20.0); |
| |
| Single-String JDOQL : |
| Query q = pm.newQuery("SELECT FROM mydomain.Person WHERE lastName == \"Jones\"" + |
| " && age < :age_limit PARAMETERS double age_limit"); |
| List results = (List)q.execute(20.0);</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>So here in our example we select all "Person" objects with surname of |
| "Jones" and where the persons age is below 20. The language is intuitive |
| for Java developers, and is intended as their interface to accessing the |
| persisted data model. As can be seen above, the query is made up of |
| distinct parts. The class being selected (the SELECT clause in SQL), the |
| filter (which equates to the WHERE clause in SQL), together with any |
| sorting (the ORDER BY clause in SQL), etc.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Before giving details on JDOQL, you can download a quick reference guide |
| <a href="jdoql_quickref.pdf">here</a></p> |
| </div> |
| <div class="paragraph"> |
| <p><br></p> |
| </div> |
| <div class="paragraph"> |
| <p><a id="singlestring"></a></p> |
| </div> |
| <div class="sect2"> |
| <h3 id="_single_string_jdoql_a_id_single_string_jdoql_a">Single-String JDOQL<a id="Single-String_JDOQL"></a></h3> |
| <div class="paragraph"> |
| <p>In traditional (declarative) JDOQL (JDO 1.0) it was necessary to specify |
| the component parts (filter, candidate class, ordering, etc) of the |
| query using the mutator methods on the Query. In JDO 2 you can now |
| specify it all in a single string. This string has to follow a |
| particular pattern, but provides the convenience that many people have |
| been asking for. The pattern to use is as follows</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>SELECT [UNIQUE] [<result>] [INTO <result-class>] |
| [FROM <candidate-class> [EXCLUDE SUBCLASSES]] |
| [WHERE <filter>] |
| [VARIABLES <variable declarations>] |
| [PARAMETERS <parameter declarations>] |
| [<import declarations>] |
| [GROUP BY <grouping>] |
| [ORDER BY <ordering>] |
| [RANGE <start>, <end>]</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The "keywords" in the query are shown in UPPER CASE but can be in |
| <em>UPPER</em> or <em>lower</em> case.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Lets give an example of a query using this syntax</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>SELECT UNIQUE FROM org.datanucleus.samples.Employee ORDER BY departmentNumber</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>so we form the parts of the query as before, yet here we just specify it |
| all in a single call.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_accessing_fields_a_id_accessing_fields_a">Accessing Fields<a id="Accessing_Fields"></a></h3> |
| <div class="paragraph"> |
| <p>In JDOQL you access fields in the query by referring to the field name. |
| For example, if you are querying a class called <em>Product</em> and it has a |
| field "price", then you access it like this</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Query query = pm.newQuery(mydomain.Product.class, "price < 150.0");</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>In addition to the persistent fields, you can also access "public static |
| final" fields of any class. You can do this as follows</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Query query = pm.newQuery(mydomain.Product.class, |
| "taxPercent < mydomain.Product.TAX_BAND_A");</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>So this will find all products that include a tax percentage less than |
| some "BAND A" level. Where you are using "public static final" fields |
| you can either fully-qualify the class name or you can include it in the |
| "imports" section of the query (see later).</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_data_types_literals_a_id_data_types_literals_a">Data types : literals<a id="Data_types_:_literals"></a></h3> |
| <div class="paragraph"> |
| <p>JDOQL supports the following literals: IntegerLiteral, |
| FloatingPointLiteral, BooleanLiteral, CharacterLiteral, StringLiteral, |
| and NullLiteral.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_operators_precedence_a_id_operators_precedence_a">Operators precedence<a id="Operators_precedence"></a></h3> |
| <div class="paragraph"> |
| <p>The following list describes the operator precedence in JDOQL.</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic"> |
| <li> |
| <p>Cast</p> |
| </li> |
| <li> |
| <p>Unary ("~") ("!")</p> |
| </li> |
| <li> |
| <p>Unary ("+") ("-")</p> |
| </li> |
| <li> |
| <p>Multiplicative ("*") ("/") ("%")</p> |
| </li> |
| <li> |
| <p>Additive ("+") ("-")</p> |
| </li> |
| <li> |
| <p>Relational (">=") (">") ("⇐") ("<") ("instanceof")</p> |
| </li> |
| <li> |
| <p>Equality ("==") ("!=")</p> |
| </li> |
| <li> |
| <p>Boolean logical AND ("&")</p> |
| </li> |
| <li> |
| <p>Boolean logical OR ("|")</p> |
| </li> |
| <li> |
| <p>Conditional AND ("&&")</p> |
| </li> |
| <li> |
| <p>Conditional OR ("||")</p> |
| </li> |
| </ol> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_concatenation_expressions_a_id_concatenation_expressions_a">Concatenation Expressions<a id="Concatenation_Expressions"></a></h3> |
| <div class="paragraph"> |
| <p>The concatenation operator(+) concatenates a String to either another |
| String or Number. Concatenations of String or Numbers to null results in |
| null.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_example_1_use_of_explicit_parameters_a_id_example_1_use_of_explicit_parameters_a">Example 1 - Use of Explicit Parameters<a id="Example_1_-_Use_of_Explicit_Parameters"></a></h3> |
| <div class="paragraph"> |
| <p>Here’s a simple example for finding the elements of a class with a field |
| below a particular threshold level. Here we pass in the threshold value |
| (<em>limit</em>), and sort the output in order of ascending price.</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Declarative JDOQL : |
| Query query = pm.newQuery(mydomain.Product.class,"price < limit"); |
| query.declareParameters("double limit"); |
| query.setOrdering("price ascending"); |
| List results = (List)query.execute(150.00); |
| |
| Single-String JDOQL : |
| Query query = pm.newQuery("SELECT FROM mydomain.Product WHERE " + |
| "price < limit PARAMETERS double limit ORDER BY price ASCENDING"); |
| List results = (List)query.execute(150.00);</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>For completeness, the class is shown here</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>class Product |
| { |
| String name; |
| double price; |
| java.util.Date endDate; |
| ... |
| } |
| |
| <jdo> |
| <package name="mydomain"> |
| <class name="Product"> |
| <field name="name"> |
| <column length="100" jdbc-type="VARCHAR"/> |
| </field> |
| <field name="abreviation"> |
| <column length="20" jdbc-type="VARCHAR"/> |
| </field> |
| <field name="price"/> |
| <field name="endDate"/> |
| </class> |
| </package> |
| </jdo></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p><br></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_example_2_use_of_implicit_parameters_a_id_example_2_use_of_implicit_parameters_a">Example 2 - Use of Implicit Parameters<a id="Example_2_-_Use_of_Implicit_Parameters"></a></h3> |
| <div class="paragraph"> |
| <p>Let’s repeat the previous query but this time using <em>implicit</em> |
| parameters.</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Declarative JDOQL : |
| Query query = pm.newQuery(mydomain.Product.class,"price < :limit"); |
| query.setOrdering("price ascending"); |
| List results = (List)query.execute(150.00); |
| |
| Single-String JDOQL : |
| Query query = pm.newQuery("SELECT FROM mydomain.Product WHERE " + |
| "price < :limit ORDER BY price ASCENDING"); |
| List results = (List)query.execute(150.00);</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>So we omitted the declaration of the parameter and just prefixed it with |
| a colon (:)</p> |
| </div> |
| <div class="paragraph"> |
| <p><br></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_example_3_comparison_against_dates_a_id_example_3_comparison_against_dates_a">Example 3 - Comparison against Dates<a id="Example_3_-_Comparison_against_Dates"></a></h3> |
| <div class="paragraph"> |
| <p>Here’s another example using the same Product class as above, but this |
| time comparing to a Date field. Because we are using a type in our |
| query, we need to <em>import</em> it …​ just like you would in a Java class if |
| you were using it there.</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Declarative JDOQL : |
| Query query = pm.newQuery(domain.Product.class, |
| "endDate > best_before_limit"); |
| query.declareImports("import java.util.Date"); |
| query.declareParameters("Date best_before_limit"); |
| query.setOrdering("endDate descending"); |
| Collection results = (Collection)query.execute(my_date_limit); |
| |
| Single-String JDOQL : |
| Query query = pm.newQuery("SELECT FROM mydomain.Product " + |
| "WHERE endDate > best_before_limit " + |
| "PARAMETERS Date best_before_limit " + |
| "import java.util.Date ORDER BY endDate DESC"); |
| List results = (List)query.execute(my_date_limit);</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p><br></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_example_4_instanceof_a_id_example_4_instanceof_a">Example 4 - Instanceof<a id="Example_4_-_Instanceof"></a></h3> |
| <div class="paragraph"> |
| <p>This example demonstrates use of the "instanceof" operator. We have a |
| class A that has a field "b" of type B and B has subclasses B1, B2, B3. |
| Clearly the field "b" of A can be of type B, B1, B2, B3 etc, and we want |
| to find all objects of type A that have the field "b" that is of type |
| B2. We do it like this</p> |
| </div> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>Declarative JDOQL : |
| Query query = pm.newQuery(mydomain.A.class); |
| query.setFilter("b instanceof mydomain.B2"); |
| List results = (List)query.execute(); |
| |
| Single-String JDOQL : |
| Query query = pm.newQuery("SELECT FROM mydomain.A WHERE b instanceof mydomain.B2"); |
| List results = (List)query.execute();</pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="col-sm-3"> |
| <nav id="toc" data-spy="affix" data-toggle="toc"></nav> |
| </div> |
| </div> |
| |
| </div> |
| |
| <footer style="color:#fff; background-color:#222222; padding: 5px;"> |
| <div class="container"> |
| <div class="row" style="margin-top:25px"> |
| <div class="col-sm" align="center"> |
| <a href="https://www.facebook.com/JavaDataObjects" class="externalLink" title="Facebook">Facebook</a> |
| | |
| <a href="https://twitter.com/JavaDataObjects" class="externalLink" title="Twitter">Twitter</a> |
| | |
| <a href="http://wiki.apache.org/jdo" class="externalLink" title="Wiki">Wiki</a> |
| | |
| <a href="http://issues.apache.org/jira/secure/BrowseProject.jspa?id=10630" class="externalLink" title="Issue Tracker">Issue Tracker</a> |
| | |
| <a href="mail-lists.html" title="Mailing Lists">Mailing Lists</a> |
| | |
| <a href="api31/apidocs/index.html" title="Latest Javadocs">Latest Javadocs</a> |
| </div> |
| </div> |
| <p class="text-center" style="margin-top:16px">© 2005-2020 Apache Software Foundation. All Rights Reserved.</p> |
| </div> |
| </footer> |
| |
| </body> |
| </html> |