|
||||||||||
|
||||||||||
Batch Session Bean | ||||||||||
|
||||||||||
Batch-updates multiple server-side objects within the context of a single network communication. Avoids the unnecessary overhead of constructing and interating collections of Entity beans when a collection of objects all need to be updated in the same way. Can also decrease network traffic by moving the update iteration into the database. | ||||||||||
|
||||||||||
Efficiently update multiple server-side objects | ||||||||||
|
||||||||||
Object Behavioral | ||||||||||
|
||||||||||
Occasionally a distributed application will need to update multiple server objects simultaneously. But updating a large number of server objects one at a time, with each update requiring one or more remote method invocations, can be very expensive. In the case of a client program accessing Entity beans, for example, the client acquires a list of primary keys from an EJB finder method, and then individually updates the enterprise beans through those Beans' remote interface. Unfortunately, the server has to create and perform transaction management for each of these instances, resulting in unacceptable overhead. One solution to this problem is the Batch Session Bean pattern, which encapsulates the transaction to be performed on multiple server objects into a server-side stateless session bean. This object receives a collection of objects to be used as parameters for updating the collection of Entity beans. For example, the Java Pet Store allows an administrator to individually mark orders as "approved" or "denied". Once the entire batch of orders has been marked, the user submits the update to the Java Pet Store control servlet, which builds a list of order numbers and status strings, and passes that list to a stateless session bean, AdminOrdersDAO. AdminOrdersDAO iterates the collection of order number/status pairs it receives, building an SQL statement that updates all orders in the collection (with the same status) in a single operation. Essentially, the Batch Session Bean pattern improves performance by modifying multiple database rows with a single database update statement, thereby avoiding the unnecessary overhead of Entity bean construction and maintenance. It also decreases network traffic by moving iteration on collections of server-side objects to the server. |
||||||||||
|
||||||||||
Use the Batch Session Bean pattern:
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
The Batch Session Bean pattern has the following consequences:
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
The classes implementing the Batch Session Bean participant in
the example above are:
The class BatchSessionDAO participant class in the example above is:
The Client classes are:
|