Developing a custom query builder
You develop a query builder using standard web application components, JavaServer Pages (JSPs) and servlets. After creating the necessary components, you perform a series of tasks to integrate the components with Information Console. This section describes the sample query builder, on which you can base your own query builder. This section also describes the procedures for compiling and deploying your own query builder components.
The sample query builder consists of the following components:
*ClassicModelQueryBuilder.jsp. This JSP displays the page in Figure 5‑21. It also contains JavaScript functions to build the string that contains information about the data that the user selected and to send the request to a servlet. To view the code, see ClassicModelQueryBuilder.jsp in the following location:
<context root>\bizRD\oda\sample
*SampleServlet.java. This servlet communicates with ClassicModelQueryBuilder.jsp, creates a design session, and creates the query using information from the JSP. To view the code, see SampleServlet.java in the following location:
<context root>\iportal\examples\oda\classes\com\actuate\erni\oda\ClassicModels
Creating the servlet
A servlet performs the main tasks for getting and managing data for Report Studio users, and it is the key piece of any custom query builder. The example servlet, SampleServlet.java, extends the HTTPServlet class, and performs the following tasks:
*Manages design sessions for concurrent Report Studio users
*Uses ODA API to define the basic methods for constructing a query, result set, and column objects
*Processes the information sent by ClassicModelQueryBuilder.jsp, and creates a query
*Returns dynamic content that appears in Available Data, as shown in Figure 5‑22
The servlet contains declarations of the ODA data driver’s data source and data set extensions:
private final static String Datasource_Extension_Id = "org.eclipse.birt.report.data.oda.jdbc";
 
private final static String Dataset_Extension_Id = "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet";
These extension IDs are used to construct the definitions of the data source connection and data set query in the report design.
The servlet supports the GET method only. Its doGet method retrieves request parameters, creates a unique ODA design session, and stores a session ID in the ODA session, so that other requests in the same session can access the same ODA session object. In any given session, the servlet can receive multiple requests with different parameter values. Table 5‑2 describes the supported parameters.
Table 5‑2 Session request parameters
Parameter
Description
inedit
Indicates whether the user has started editing the values on the query builder page. Values are null or true.
state
Shows the editing status. Values are null, ok, or cancel.
selection
Contains information about the selected data fields.
sessionId
Contains the session ID.
The servlet executes a different action, depending on the parameter values. Table 5‑3 describes the actions taken with the different inedit and state values.
Table 5‑3 Actions corresponding to inedit and state values
inedit value
state value
Action
null
any
Generates a new session ID. Stores the ID and the callback URL in the session map. Changes the inedit parameter to true and sends a response to the calling page.
not null
null
Redirects the response to ClassicModelQueryBuilder.jsp.
not null
ok
The user has finished selecting data fields. The servlet deletes the session ID, and parses the value in the selection parameter to build the query. The response is redirected to a Report Studio page.
not null
cancel
The user cancelled out of the query builder page. The servlet deletes the session ID.
Compiling the servlet
After you develop your servlet, you must compile the class. You can use a javac compiler from the command prompt or any Java IDE, such as Eclipse. To compile a servlet class, the following JAR files must be in your Java classpath:
*com.actuate.iportal.jar
*org.eclipse.emf.common.jar
*org.eclipse.emf.ecore.jar
*org.eclipse.datatools.connectivity.oda.design.jar
These files are in the following location:
<context root>\WEB-INF\lib
*servlet.jar
You can find this file in different places, depending on the Actuate products installed on your computer. For example, servlet.jar can be found in the following location:
<ACTUATE_HOME>\iHub\servletcontainer\webapps\acrsse\WEB_INF\lib
Deploying the servlet
After you compile the servlet class, deploy the servlet to your application. You can deploy your servlet as a class file, or packaged as a JAR file. The SampleServlet.class servlet is deployed to your application packaged in iportal.jar.
If you deploy the servlet using a JAR file, copy the JAR file to the following location:
<context root>\WEB-INF\lib
If you deploy the servlet as a class file, copy the servlet class to the following location:
<context root>\WEB-INF\classes
Registering the servlet
After you compile your servlet, you also need to register the servlet with the web application. To register the servlet, you add two entries to web.xml, which is stored in the following location:
<context root>\WEB-INF
The first entry, under the <servlet> element, defines a name for the servlet and specifies the compiled class that executes the servlet. The following example shows the <servlet> entry for the sample servlet:
<servlet>
<servlet-name>OdaSampleServlet</servlet-name>
<servlet-class>
com.actuate.erni.oda.ClassicModels.SampleServlet
</servlet-class>
</servlet>
The second entry, under the <servlet-mapping> element, defines the URL pattern that calls this servlet. The following example shows the <servlet-mapping> entry for the sample servlet:
<servlet-mapping>
<servlet-name>OdaSampleServlet</servlet-name>
<url-pattern>/OdaSample</url-pattern>
</servlet-mapping>