Name

IsDirty

Goal

To prevent writing data to the database unnecessarily.

Participants

Data object (EJB or Plain Old Java Object)

Makes data available to the application and notes when the data changes.

DAO

Provides access to the persistence layer.

Interactions

A DAO is used to create a data object. When the data object is updated, it records the fact. When the DAO is used to update the database with the changed values, it can use this information to avoid writing to the database when the underlying data hasn’t changed.

Notes

The obvious benefit of this pattern is to eliminate the performance overhead of doing the write operation in the first place. There’s also a hidden benefit when running against databases that perform auditing: the database is spared the overhead of storing huge quantities of unnecessary change tracking. Since in an active database the volume of audit trail information can far exceed the actual volume of data, the performance and storage benefits of this pattern can be huge.

Get J2EE Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.