com.ibm.websphere.samples.ejbquery.ejbmediatorwar
Class EjbMediatorSample

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.ibm.websphere.samples.ejbquery.ejbmediatorwar.EjbMediatorSample
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class EjbMediatorSample
extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet

This is a sample program showing how to call the EJB Data Mediator Service. The simplest way to run the sample is to open a browser to the url http://localhost:9080/DynamicQuery/EjbMediatorWeb/index.html, enter EJB query select statements and press the "Submit" button. The EJB query can be on multiple lines but the select statements must be separated by semicolon (";") characters. Example: select d.deptno, d.name from DeptBean as d; select e.* from in (d.emps) as e

See Also:
Serialized Form

Constructor Summary
EjbMediatorSample()
           
 
Method Summary
 void _processQuery(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          The _processQuery method uses the input query to create a mediator and then calls getGraph() on the EJB Mediator.
 void displayGraph(javax.servlet.http.HttpSession thisSession, javax.servlet.http.HttpServletRequest req, java.io.PrintWriter out, commonj.sdo.DataGraph g)
          /** The displayGraph method shows the DataGraph that is returned after the mediator query and any subsequent DataObject commands are issued.
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          The doPost method checks if the ejb application is installed and started then processes the query.
 void init()
          The init method is used to retrieve the InitialContext for the application server namespace and the UserTransaction from the application server namespace.
 void installCheck()
          The installCheck method checks if the datasource and ejb home for the sample are installed correctly.
protected  java.lang.Object lookup(java.lang.String name, java.lang.String message)
          The lookup method is a utility method to retrieve references from the application server namespace.
protected  java.lang.String[] parse(java.lang.String qs)
          The parse method converts a select query String which may contain several select statements separated by semicolons on one or more lines into an array of single select statements.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.Servlet
destroy, getServletConfig, getServletInfo, init, service
 

Constructor Detail

EjbMediatorSample

public EjbMediatorSample()
Method Detail

_processQuery

public void _processQuery(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse resp)
                   throws java.lang.Exception
The _processQuery method uses the input query to create a mediator and then calls getGraph() on the EJB Mediator. The createMediator and getGraph methods must be run in a transaction context.

Parameters:
req - javax.servlet.HttpServletRequest
resp - javax.servlet.HttpServletResponse
Throws:
java.lang.Exception

displayGraph

public void displayGraph(javax.servlet.http.HttpSession thisSession,
                         javax.servlet.http.HttpServletRequest req,
                         java.io.PrintWriter out,
                         commonj.sdo.DataGraph g)
                  throws java.lang.Exception
/** The displayGraph method shows the DataGraph that is returned after the mediator query and any subsequent DataObject commands are issued. You can choose to display the entire DataGraph, including the schema and change log, or choose to display SDO values only.

Parameters:
thisSession - javax.servlet.HttpSession
req - javax.servlet.HttpServletRequest
out - java.io.PrintWriter
Throws:
java.lang.Exception

doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      java.io.IOException
The doPost method checks if the ejb application is installed and started then processes the query. It forwards Exceptions to error.jsp.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - javax.servlet.HttpServletRequest
resp - javax.servlet.HttpServletResponse
Throws:
javax.servlet.ServletException, - java.io.IOException
javax.servlet.ServletException
java.io.IOException

init

public void init()
          throws javax.servlet.ServletException
The init method is used to retrieve the InitialContext for the application server namespace and the UserTransaction from the application server namespace.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

installCheck

public void installCheck()
                  throws java.lang.Exception
The installCheck method checks if the datasource and ejb home for the sample are installed correctly. It runs in doPost so exceptions can be returned to the web browser.

Throws:
java.lang.Exception

lookup

protected java.lang.Object lookup(java.lang.String name,
                                  java.lang.String message)
                           throws javax.servlet.ServletException
The lookup method is a utility method to retrieve references from the application server namespace.

Parameters:
name - String Name of Application Object to be retrieved.
message - String Error message to return
Returns:
Object
Throws:
javax.servlet.ServletException

parse

protected java.lang.String[] parse(java.lang.String qs)
                            throws java.lang.Exception
The parse method converts a select query String which may contain several select statements separated by semicolons on one or more lines into an array of single select statements.

Parameters:
qs - java.lang.String
Returns:
java.lang.String[]
Throws:
java.lang.Exception