31.6.4. JBossQL
JBossQL is a superset of EJB-QL that is designed to address some of the inadequacies of EJB-QL. In addition to a more flexible syntax, new functions, key words, and clauses have been added to JBossQL. At the time of this writing, JBossQL includes support for an
ORDER BY
, OFFSET
and LIMIT
clauses, parameters in the IN
and LIKE
operators, the COUNT
, MAX
, MIN
, AVG
, SUM
, UCASE
and LCASE
functions. Queries can also include functions in the SELECT
clause for select methods.
JBossQL is declared in the
jbosscmp-jdbc.xml
file with a jboss-ql
element containing the JBossQL query. The following example provides an example JBossQL declaration.
<jbosscmp-jdbc>
<enterprise-beans>
<entity>
<ejb-name>GangsterEJB</ejb-name>
<query>
<query-method>
<method-name>findBadDudes_jbossql</method-name>
<method-params>
<method-param>int</method-param>
</method-params>
</query-method>
<jboss-ql>SELECT OBJECT(g) FROM gangster g WHERE g.badness > ?1 ORDER BY g.badness DESC</jboss-ql>
</query>
</entity>
</enterprise-beans>
</jbosscmp-jdbc>
The corresponding generated SQL is straightforward.
SELECT t0_g.id FROM gangster t0_g WHERE t0_g.badness > ? ORDER BY t0_g.badness DESC
Another capability of JBossQL is the ability to retrieve finder results in blocks using the
LIMIT
and OFFSET
functions. For example, to iterate through the large number of jobs performed, the following findManyJobs_jbossql
finder may be defined.
<jbosscmp-jdbc>
<enterprise-beans>
<entity>
<ejb-name>GangsterEJB</ejb-name>
<query>
<query-method>
<method-name>findManyJobs_jbossql</method-name>
<method-params>
<method-param>int</method-param>
</method-params>
<method-params>
<method-param>int</method-param>
</method-params>
</query-method>
<jboss-ql>SELECT OBJECT(j) FROM jobs j OFFSET ?1 LIMIT ?2</jboss-ql>
</query>
</entity>
</enterprise-beans>
</jbosscmp-jdbc>