A stored procedure serves as an extension to clients that run on a backend datastore. The stored procedure can be invoked with a CALL statement from a client application or from another routine.
The Container-Managed Persistence (CMP) Entity JavaBeans (EJBs) in WebSphere Business Integration Server Foundation version 5.1 extends the existing J2EE CMP EJB programming model to utilize the well-known stored procedure feature to push down the CMP EJB methods to the backend store. A mapping mechanism is provided by the Application Server Toolkit (ASTk) and WebSphere Studio Application Developer-IE 5.1 to enable bean developers to map the bean's data logic methods and the CMP EJB accessor methods to the legacy procedures.
The trigger to this mechanism is the PME deployment descriptor extensions. There is a PushDownMethodElement defined for each method that you want to implement with a stored procedure. The logic that accesses the stored procedure (legacy or specially-written) is provided by a user-writtenclass which plugs in to the CMP EJB support of WebSphere. The result is that the bean's data logic is simplified and utilizes the existing legacy procedures that have been fully tested.
A beanUserDefinedPushDownMethod interface is introduced so you can provide the implementation of this interface to access the stored procedures during the deployment of a CMP EJB.
The UserDefinedPushDownMethod interface and implementation class are generated when you use the ASTk to generate the push down method template. You must inject the logic that accesses the stored procedures in this implementation class. This class is called by WebSphere to perform the procedure invocation during runtime.
There are three kinds of stored procedures in a business environment:
These stored procedures are used to perform EJB CRUD functions, such as ejbCreate, ejbRemove and ejbStore methods.
These stored procedures perform logic related to this CMP EJB's persistent data. For example, the logic might perform calculations using data not surfaced as attributes of the bean, or it might update persistent fields of a bean based on information more efficiently accessed in the backend system.
This kind of stored procedure does not relate to any persistent fields or any functions of this CMP EJB. This stored procedure is typically used in a session bean, instead of a CMP EJB. For example, an issueAnnualReport stored procedure queries multiple tables to get the annual report for a company.
A stored procedure can be an SQL procedure, a Java procedure, or any existing legacy procedure. You can use JDBC or SQLJ to access an SQL stored procedure or Java stored procedure, or you can use a mechanism such as WSIFOperation to execute any non-relational procedure.
The ability to create a CMP EJB as the front-end to appropriate stored procedures lets you enjoy the benefits of using CMP EJBs and stored procedures at the same time. These benefits include:
To summarize, all the reasons for using CMP EJBs still apply, when you choose to use stored procedures instead of a direct SQL operation to access your persistent data.
The following links provide additional information concerning the relational stored procedure that uses a CMP EJB. For non-relational stored procedure information, refer to Container Managed Persistence over anything.