Java 2EE and XML Development

Скачать в pdf «Java 2EE and XML Development»


The requirements for this example are simple but sufficient for our purposes. We are required to retrieve detailed customer information from an enterprise data source based on the customer’s unique identifier. To accomplish this, we use the Data Access Object design pattern. In this pattern, the data access object (DAO) hides the complexity of interacting with a persistent


data source and provides a simple interface for other components to use. The Data Access Object pattern is discussed in detail in appendix A.


To implement this pattern, we use an EJB session bean called the Cus-tomerDataBean. This bean will obtain the customer data using a CustomerDAO (data access object), which obtains customer data in their raw format from a JDBC data source, converts them to XML using JDOM, and returns them to the CustomerDataBean. The CustomerDataBean then returns the JDOM Document to the remote caller. This scenario is depicted in figure 3.3.


EJB Container








Figure 3.3


Customer data retrieval scenario


using data access object JDBC Data Source

The CustomerDataBean


First, we implement the CustomerDataBean session EJB. This bean declares an instance variable to hold a reference to its CustomerDAO helper object.


public transient CustomerDAO cDAO;


At creation time, the bean obtains a reference to the JDBC data source using JNDI and instantiates its CustomerDAO object.

Скачать в pdf «Java 2EE and XML Development»