Operating Systems: i5/OS
             Personalize the table of contents and search results

 

Use the dynamic query service

 

There are times in the development process when you might prefer to use the dynamic query service rather than the regular Enterprise JavaBean (EJB) query service (which can be referred to as deployment query). During testing, for instance, the dynamic query service can be used at application run time, so you do not have to re-deploy your application.

 

Overview

Following are common reasons for using the dynamic query service rather than the regular EJB query service:

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 Developer 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, 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, 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.

 

Procedure

  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 app_server_root 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.




}
Example: Using the remote interface for Dynamic query

Example: Using the local interface for Dynamic query

Dynamic query performance considerations

Access intent implications for dynamic query

Dynamic query API: prepareQuery() and executePlan() methods

 

Related concepts


EJB query language
Path expressions

 

Related Reference


Example: Queries with EJB