Entity bean pattern framework
The first two pattern frameworks are designed for simple Web applications developed with servlets and JSPs deployed in a Web container. The third and fourth pattern frameworks are used in Web and EJB containers.
The Web Container Pattern Framework
This architecture is used for database access from a Web container. The Intercepting Filter is the first point of contact for all client requests. It is used to control access and authentication. Once requests are received and filtered using the Intercepting Filter, they are forwarded to the Front Controller, which is the central dispatcher for the application. The Front Controller dispatches the request to the appropriate View Helper. A View Helper is a set of helper functions used to collect specific data. The Composite View is used to build the response to the client, and is also responsible for calling the appropriate Business Object, which calls the Data Access Object pattern to get the related data. This framework is shown in Figure 1.
Figure 1 outlines how the Web Container pattern framework is used for an inventory requirement. If a client requests a list of inventory, the Intercepting Filter checks for authentication and forwards the request to the Inventory Controller (Front Controller), which in turn dispatches the request to the Inventory Helper (View Helper). The Inventory Helper can be a normal JavaBean or a bean that will talk to the Inventory Business Object to get the appropriate inventory data. The Inventory Business Object contains business logic to process the inventory and asks the Inventory Data Access Object (DAO) to get the data from the database. The Inventory DAO contains database communication and SQL code to get the inventory-related data. This simple example shows how you can apply this pattern framework easily for inventory functionality. The advantage is that the application architecture is well documented and can be easily understood.
The Command Pattern Framework
The second framework is similar to the Web Container pattern framework, but uses the Command pattern, as shown in Figure 2. The Command pattern provides decoupling, which can make it easier to add more functionality to an application in the future. The controller requests the command, gets the results, and forwards them to the Composite View.
If you apply this framework to the Inventory example, there would be an Inventory Command pattern that contains business logic to process the inventory request. The Inventory Command pattern calls the Inventory DAO to get the related data. When using the command it is an advantage to use the Command Helper and Command Factory patterns to call and create appropriate commands.
The Session Bean Pattern Framework
The third framework adds Session Bean patterns to the Web Container pattern framework, as shown in Figure 3. While this framework adds more complexity to the architecture, using this pattern-oriented architecture allows greater flexibility for adding features to the application. Session Bean patterns are used to simplify the J2EE container development when introducing session beans in an application. The Command pattern framework can also be used instead of the Web Container pattern framework, depending on flexibility and maintenance requirements. As a Web site becomes more complex and requires handling of multiple transactions, the introduction of a command factory provides the application developer with a single location to modify existing features and introduce new functions. This allows features to be incrementally added to Web sites with little effect on the existing function.
The Business Delegate, Session Facade, Service Locator, and Value Object patterns are introduced in this framework. The View Helper pattern calls the Business Delegate pattern to delegate the request to the Session Facade pattern. The Business Delegate pattern is responsible for looking up the Session Facade pattern using the Service Locator pattern. The data is transferred from the Business Delegate pattern to the Session Facade pattern using the Value Object pattern. The Session Facade pattern calls the DAO to get the data from the persistent store. Applying this framework to the Inventory example, there will be Inventory Delegate, Inventory Facade, Service Locator, and Inventory Value Object pattern.
The Session Bean pattern framework takes full advantage of the capabilities provided by Web and J2EE containers. It provides a set of common functions that relieve the programmer of the responsibility of looking up and calling specific EJBs. Instead, this pattern framework includes a set of commonly used design patterns that make it easier to develop EJB-based solutions.
The Entity Bean Pattern Framework
This framework (see Figure 4) adds entity bean patterns to the Session Bean pattern framework. The Entity Beans pattern can be used, as shown here, when choosing entity beans in an application. The general recommendation for entity beans is to use container-managed entity beans. This process removes the SQL from the Java code and places it in the XML definitions. The coding of SQL in XML takes time to learn and understand. This pattern also includes the Value List Handler pattern, which is very important when dealing with large database records.
We introduce the Composite Entity pattern and the Value List Handler pattern in this framework to improve the performance of the application. In this framework, the Session Facade pattern calls composite entities and/or DAOs. When dealing with large database results, the framework uses the Value List Handler pattern to send a small set of processed results iteratively to the client. The implementation of the Value List Handler framework is done using a normal Java class that contains the SQL. For example, when inventory functionality is implemented, you can have Inventory Entity and All Inventory Handler patterns. The Inventory Entity pattern acts as a Composite Entity pattern and the All Inventory Handler pattern acts as a Value List Handler pattern to deal with a large inventory search.
Conclusion
Pattern frameworks enable developers to achieve highly functional, modular architectures for their applications. They also enable developers to implement pattern-oriented architectures that clearly identify where requirements can be implemented. We have presented four types of frameworks by connecting different patterns depending on two common types of J2EE applications. We encourage developers to leverage the power of pattern frameworks by taking the examples presented here as a base and extending them as needed, or by building new pattern frameworks that meet unique application requirements.
Page 1 of 2
next page »
About Lloyd HagemoLloyd Hagemo is a senior director for Candle Corporations Application Infrastructure Management Group. He is responsible for WebSphere tools development. Lloyd has led the successful development of more than 20 products for the WebSphere environment, including operating system utilities, network performance and tuning products, WebSphere MQ configuration and management tools, and application integration solutions.