Customizing and integrating BIRT Studio : Providing data : Creating a custom data source : Developing a custom query builder : Creating the servlet
 
Creating the servlet
A servlet performs the main tasks for getting and managing data for BIRT 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 BIRT 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 14‑16
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 14‑2 describes the supported parameters.
Table 14‑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 14‑3 describes the actions taken with the different inedit and state values.
Table 14‑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 BIRT Studio page.
not null
cancel
The user cancelled out of the query builder page. The servlet deletes the session ID.