Name
Transactional Context Pattern
Goal
Allow multiple objects to participate in a single transaction without imposing a large amount of overhead on the programmer (Figure B-20).
Participants
- Business delegates
Provide access to business logic.
- Data access objects
Provide access to persistence resources, such as a database.
- Transactional context object
Coordinates activities between business delegates, data access objects, and the underlying database.
- Transaction-aware database
Provides system level transaction support.
Interactions
When an application needs to begin a transaction, it obtains a transactional context object from the system and initiates a transaction with the context. All classes with access to the context use it to access transaction-sensitive resources, such as database connections, allowing multiple objects to share a single database transaction.
Notes
This pattern is particularly useful when building servlet-based applications with business delegate and DAO objects. You can associate a transactional context with each request, allowing business delegates to easily manage a transaction involving multiple DAOs and even multiple business delegates. See Chapter 10 for extensive examples.
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.