Core J2EE
Pattern Catalog
Last
Updated:
January 29, 2006 8:54 PM
In Association with Amazon.com
Domain Store
See Core J2EE Patterns,
2nd Edition for full description of this pattern and its strategies.
Problem
You want to separate persistence from your object model.
Forces
- You want to avoid putting persistence details in your Business Objects.
- You do not want to use entity beans.
- Your application might be running in a web container.
- Your object model uses inheritance and complex relationships.
Solution
Use a Domain Store to transparently persist an object
model. Unlike J2EE’s container-managed persistence and bean-managed
persistence, which include persistence support code in the object model,
Domain Store's persistence mechanism is separate from the object
model.
Class Diagram
Sequence Diagram
Strategies
- Custom Persistence Strategy
- JDO Strategy
Consequences
- Creating a custom persistence framework is a complex task
- Multi-layer object tree loading and storing requires optimization
techniques
- Improves understanding of persistence frameworks
- A full-blown persistence framework might be overkill for a small object
model
- Improves testability of your persistent object model
- Separates business object model from persistence logic
Related Patterns
- Unit of Work [PEAA]
Maintains a list objects affected by a business transaction. Unit of
Work closely relates to PersistenceManager.
- Query Object [PEAA]
An object that represents a database query. Relates to the Query role
described in Domain Store.
- Data Mapper [PEAA]
A layer of Mappers that moves data between objects and database. Relates
to StateManager.
- Table Data Gateway [PEAA]
An object that acts as gateway to a database table. Relates to StoreManager.
- Dependent Mapping [PEAA]
Has one class perform the database mapping for a child class. Relates
to parent dependent object and PersistMap.
- Domain Model [PEAA]
An object model that has behavior and data. Relates to BusinessObject.
- Data Transfer Object [PEAA]
Same as Transfer Object.
- Identity Map [PEAA]
Ensures each object only gets loaded once. Relates to StateManager.
- Lazy Load [PEAA]
An object which contains partial data and knows how to get complete
data. Relates to StateManager and StoreManager interaction for lazy
loading.
Excerpted from Core J2EE
Patterns, 2nd Edition. See the book for full description of the pattern
including class diagrams, sequence diagrams and sample code.