user manual

Chapter 17: EJB-QL and Data Access Support 185
Dynamic Queries
Dynamic queries don't need to be added to the deployment descriptor. They
are declared in the bean class for dynamic ejbSelects, or in the local or remote
home interfaces for dynamic finders.
A finder method for a dynamic query is:
public java.util.Collection findDynamic(java.lang.String ejbql, Class[]
types, Object[] args)
throws javax.ejb.FinderException
The ejbSelects for dynamic queries are:
public java.util.Collection selectDynamicLocal(java.lang.String ejbql,
Class[] types, Object[] params)
throws javax.ejb.FinderException
public java.util.Collection selectDynamicRemote(java.lang.String ejbql,
Class[] types, Object[] params)
throws javax.ejb.FinderException
public java.sql.ResultSet selectDynamicResultSet(java.lang.String ejbql,
Class[] types, Object[] params)
throws javax.ejb.FinderException
where the following applies:
java.lang.String ejbql: this represents the actual EJB-QL syntax.
Class[] types: this array gives the class types of the parameters to the
select or finder method (it can be an empty array if there are no
parameters).
Object[] params: this array gives the actual values of the parameters. This is
the same as the parameters argument of the regular select or finder
method.
The return type of a dynamic select or finder is always java.util.Collection,
with the exception of the selectDynamicResultSet. If there is a single instance
of the object or value type returned from the query, it is the first member of
the collection. Dynamic queries follow the same rules as regular queries.
Note There should not be any trace of the four methods associated with dynamic
queries in your deployment descriptor.
Overriding SQL generated from EJB-QL by the CMP engine
Important This feature is for advanced users only!
The Borland CMP engine generates SQL calls to your database based on the
EJB-QL you enter in your deployment descriptors. Depending on your
database implementation, the generated SQL may be less than optimal. You
can capture the generated SQL using tools supplied by your backing-store
implementation or another development tool. If the generated SQL is not
optimal, you can replace it with your own. However, we offer no validation on
the user SQL.