J2EE Design Pattern : Integration Tier Patterns : Data Access Object Design Pattern
Data Access Object Design Pattern? |
Data Access Object abstracts data sources provides transparent access to data.
Problem
You want to encapsulate data access and manipulation in a separate layer.
Mingling persistence logic with application logic creates a direct dependency between the application and the persistence storage implementation.
Such code dependencies in components make it difficult and tedious to migrate the application from one type of data source to another.
Context
Data Access Object, Service Activator, Domain Store, Web Service Broker.
Solution
Use a Data Access Object to abstract and encapsulate all access to the persistent store. The Data Access Object manages the connection with the data source to obtain and store data. The DAO completely hides the data source implementation details from its clients. Because the interface exposed by the DAO to clients does not change when the underlying data source implementation changes, this allows you to change a DAO implementation without changing the DAO client’s implementation.
Participants and Collaborations
Client
The Client is an object that requires access to the data source to obtain and store data. The Client can be a Business Object, a Session Façade, an Application Services, a Value List Handler, a Transfer Object Assembler, or any other helper object that needs access to persistent data.
DataAccessObject
The DataAccessObject is the primary role object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the Client to enable transparent access to the data source. The DataAccessObject implements create (insert), find (load), update (store), and delete operations.
DataSource
The DataSource represents a data source implementation. A DataSource could be a database, such as an RDBMS, OODBMS, XML repository, flat file system, and so on. A DataSource can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).
ResultSet
The ResultSet represents the results of a query execution. For an RDMBS DataSource, when an application is using JDBC API, this role is fulfilled by an instance of the java.sql.ResultSet.
Data
The Data represents a transfer object used as a data carrier. The DataAccessObject can use a Transfer Object to return data to the client. The DataAccessObject could also receive the data from the client as a Transfer Object to update the data in the data source.
Implementation Strategies
- Custom Data Access Object Strategy
- Data Access Object Factory Strategies
- Transfer Object Collection Strategy
- Cached Rowset Strategy
- Read Only Rowset Strategy
Example for Data Access Object |
Recent Comments