142 Queries with JDOQL Now that it has
Unconstrained query variables 143 Extent partnerExt = pm.getExtent(BusinessPartner.class, true); String filter = “customer.orders.contains(o) && o.dispatched == false”; Query q = pm.newQuery(partnerExt, filter); q.declareVariables(”Order o”); Collection c = (Collection) q.execute(); The filter criteria could also be legally written using the logical complement operator (!) as follows: customer.orders.contains(o) && !o.dispatched Conceptually, o is set to each contained Order in turn and !o.dispatched is then evaluated. In practice, queries are usually translated into the native query language of the underlying data store in order to take best advantage of the available indexing and query tuning strategies. Thus explicit serial evaluation of individual order entities is unlikely. 8.7 Unconstrained query variables The primary purpose of JDOQL variables is as identifiers for use in contains() clauses, facilitating the iteration through persistent fields of Collection type. However, the JDO specification does allow for the definition of query variables that are subsequently referenced in the filter expression, but not subject to a contains() clause. Such identifiers, known as unconstrained query variables, conceptually iterate across the entire extent (including subclasses) of their persistence-capable type. The specification is particularly vague about the portability of query filters using unconstrained variables, and I will not discuss the concept further here. It has, however, been the subject of several threads of discussion at JDOcentral, and will certainly be clarified in the next version of the specification document. 8.8 Dynamic Query Window You will have noticed that all query elements are passed as strings. This has one disadvantage; query syntax is checked only at query compilation or execution time. In most cases, query errors will be detected only during the running of the application. However, it does facilitate the writing of applications that execute ad hoc queries, the details of which are not known at compile time. An example is the Dynamic Query Window, shown in Figure 8.2. This is a relatively simple Swing application. It uses the JDOBootstrap class to initialize JDO, so all of the configuration parameters can go into the jdo.properties file. It then allows the user to enter the various query element strings. Upon
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider