Sunday, September 5, 2010

The stored procedure method of packaging for the EJB component

Integrated Web application server and database management (DBMS) technology is a lot of common needs of new business applications. In this article, we will discuss the integration of De one aspect: how the session Enterprise JavaBeans (EJB) component in the design and development package, or call Xianyou DBMS Cunchu process method. You should be familiar with EJB technologies, structured query language (SQL) and Java Database Connectivity (JDBC) basic knowledge in order to fully understand this article. 

If you are working in the DMBS need to access or modify data in Web application development, it may have been transferred to the design based on EJB. You may find that the session EJB components by making use of DBMS stored procedures can reduce coding and maintenance work, and may improve data access performance.


Some company has been in use stored procedures (stored procedure), yes Yinwei they can Bangzhu reduce network traffic, Bing the distributed Jisuan environment Xingneng. Typically, these processes involve multiple database operations include important business logic. Remote application calls these processes, the DMBS server implementation of the SQL statements they contain. Of course, the process is completed, all results are returned to the application.

The old stored procedures on the Web application is often useful. Instead of copying the EJB component logic, why do not these processes in a session bean as a method of packaging the same time? This DBMS server and EJB components to avoid redundancy in the code - in considering the development, debugging and maintenance costs, the loss of redundant code development efficiency. It may also bring the benefits of improved performance. Call a stored procedure can reduce the EJB components have issued the original number of SQL statements, thereby reducing the communication overhead with the remote DBMS.

Getting Started

Now understand why the session bean to call a stored procedure from the right, let's take a look at how to get started. First, the need to use the appropriate development environment, the environment should include an EJB with a built-in support for Java development tools, a Web application server and a relational DBMS. My reference configuration, including VisualAge for Java Enterprise Edition 3.0.2, WebSphere Application Server Advanced Edition 3.0.2.1, as well as DB2 V7.1, all of which are installed on a Windows NT system. About how to configure the environment to support the work described in this article For more information, see "Leveraging DBMS Stored Procedures through Enterprise JavaBeans" (in reference) or the reference product manuals.

With the right software environment, you can begin. Although we discuss the encoding mode may be suitable for stateless session (stateless session) bean, but it can also use stateful session (stateful session) bean component. However, because stateless session bean stateful session bean than consume fewer system resources, and less code involved, it is generally recommended to use a stateless session bean.

First thing to consider is how the design of stored procedures and mapping data between the EJB components. Stored procedure may require multiple input, output and input / output parameters and returns one or more of the result set (on behalf of the data lines). Except to process different types using different encoding mode, you need to write EJB components to address all these possibilities.

Processing input (or input / output) parameter is simple: each parameter stored procedure requires mapping EJB component input parameters. However, processing the stored procedure's output can be tricky. May have multiple output parameters and return multiple result sets will be calling program, you need to these as a serializable object to return, to meet the EJB specification. You can write your own class, so the data can be packaged into an object, and the object all the necessary meta-data. (The metadata describes the internal structure of objects so that clients know what to do.) But this requires a lot of work.

If you are using VisualAge for Java and WebSphere, then there is a better option: the use of their data access Bean (DAB) library. The library contains a number of available functions in the layer above the basic JDBC classes. May find it particularly convenient com.ibm.db.CallableStatement class, because Ta allows to create a serializable object, The object contains Suoyou from Cunchuguocheng return of output, including the number of results Ji (if any) and Xiang Guan yuan data. Another advantage is that the library is designed to support any JDBC data source support, so it can make bean "has nothing to do with the DBMS." With DAB library, you can use a coding mode in the session EJB component package any stored procedure. EJB client can even use a common coding patterns to deal with any from the wrapper method returns the results.

No comments:

Post a Comment