WebSphere Application Server - Express, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Using the dynamic query service

Why and when to perform this task

Following are common reasons for using the dynamic query service rather than the regular EJB query service (which can be referred to as deployment query):
  • You need to programmatically define a query at application run time, rather than at deployment.
  • You need to return multiple CMP or CMR fields from a query. (Deployment queries allow only a single element to be specified in the SELECT clause.) For more information, see the Example: EJB queries article.
  • You want to return a computed expression in the query.
  • You want to use value object methods or bean methods in the query statement. For more information, see Path expressions.
  • You want to interactively test an EJB query during development, but do not want to repeatedly deploy your application each time you update a finder or select query.

The dynamic query API is a stateless session bean; using it is similar to using any other J2EE EJB application bean. You can consult the API specifications in Reference: Generated API documentation (the section for package com.ibm.websphere.ejbquery).

The dynamic query bean has both a remote and a local interface. If you want to return remote EJB references from the query, or if the query statement contains remote methods, you must use the query remote interface:

remote interface = com.ibm.websphere.ejbquery.Query
remote home interface = com.ibm.websphere.ejbquery.QueryHome

If you want to return local EJB references from the query, or if the query statement contains local methods, you must use the query local interface:

local interface = com.ibm.websphere.ejbquery.QueryLocal
local home interface = com.ibm.websphere.ejbquery.QueryLocalHome

Because it uses less application server memory, the local interface ensures better overall EJB performance than the remote.

Steps for this task

  1. Verify that the query.ear application file is installed on the application server on which your application is to run, if that server is different from the default application server created during installation of the product.
    The query.ear file is located in the <WAS_HOME>/installableApps directory, where <WAS_HOME> is the location of the WebSphere Application Server. The product installation program installs the query.ear file on the default application server using a JNDI name of
    com/ibm/websphere/ejbquery/Query
    (You or the system administrator can change this name.)
  2. Set up authorization for the methods executeQuery(), prepareQuery(), and executePlan() in the remote and local dynamic query interfaces to control access to sensitive data. (This step is necessary only if your application requires security.)

    Because you cannot control which ASN names, CMP fields, or CMR fields can be used in a dynamic EJB query, you or your system administrator must place restrictions on use of the methods. If, for example, a user is permitted to run the executeQuery method, he or she can run any valid dynamic query. In a production environment, you certainly want to restrict access to the remote query interface methods.

  3. Write the dynamic query as part of your application client code. You can consult the following examples as query models; they illustrate which import statements to use, and so on:
  4. If the CMP you want to query is on a different module, you should:
    1. do a remote lookup on query.ear
    2. map the query.ear file to the server that the queried CMP bean is installed on.
  5. Compile and run your client program with the file qryclient.jar in the classpath.




Sub-topics
Example: Dynamic query remote interface
Example: Dynamic query local interface
Dynamic query performance considerations
Access intent implications for dynamic query
Dynamic query API: prepareQuery() and executePlan() methods
Comparison of the dynamic and deployment EJB query services

Related concepts
EJB query language
Path expressions

Related reference
Example: EJB queries

Task topic    

Terms of Use | Feedback

Last updated: Jun 8, 2005 12:45:23 PM EDT
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/query/tasks/tque_dynamic.html

© Copyright IBM Corporation 2002, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)