DekGenius.com
[ Team LiB ] Previous Section Next Section

B.2 Data Transfer Patterns

Data Transfer Hash

Goal

Reduce coupling between objects communicating via DTOs (Figure B-1).

Figure B-1. Data transfer hash classes
figs/j2ee_ab01.gif

Participants

Business objects

Create hashes for sending data, or use values in received hashes.

Data transfer hash

Stores data for transport between layers as a set of values associated with well-known keys.

Presentation tier objects

Create hashes for sending data, or use values in received hashes.

Interactions

A presentation tier object requests data from the business tier. The business object reads the data, and inserts the values into a hash table with well-known keys for transport. The presentation tier object retrieves the data in the received hash by key. The presentation tier object modifies the received hash or creates a new one to transport data back to the business tier.

Notes

Data transfer hashes may be implemented as simple hash tables (or HashMaps). A more robust implementation uses a container object to hold the hash, as well as identifying information, type-safe data retrieval methods, and well-known keys.

Data Transfer Object (DTO)

Goal

Improve performance by reducing the number of objects passed between tiers (Figure B-2).

Figure B-2. Classes in the DTO pattern
figs/j2ee_ab02.gif

Participants

Business objects

Create DTOs for sending data, or use values in received DTOs.

DTO

Stores data for transport between layers.

Presentation tier objects

Create DTOs for sending data, or use values in received DTOs.

Interactions

A presentation tier object requests data from the business tier. The business object reads the data and copies it into a DTO for transport. The presentation tier object uses the data in the received DTO. The presentation tier object modifies the received DTO or creates a new one to transport data back to the business tier.

Notes

DTOs may be data objects used within the business objects themselves, or dedicated classes for transporting data. DTOs often follow JavaBean semantics, but this is not a requirement.

Row Set DTO

Goal

Minimize overhead while transporting the results of a database query.

Participants

Business objects

Perform database query and formats results as row set DTO.

Row set DTO

Stores data for transport between layers in database columns and rows.

Presentation tier objects

Use data from rows and columns.

Interactions

A presentation tier object requests data from the business tier. The business object performs a database query and stores the resulting rows and columns in a row set DTO for transport. The presentation tier object accesses the data in the received DTO as rows and columns.

Notes

In many instances, it is easiest to simply send the JDBC ResultSet object directly to the client. When this is not desirable, a separate class implementing the ResultSet interface can be used, or a lighter-weight interface can be defined.

    [ Team LiB ] Previous Section Next Section