BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Bitemporal Framework Adds Time Dimension To Rich Domain Models

Bitemporal Framework Adds Time Dimension To Rich Domain Models

This item in japanese

Tracking time is a very common requirement in business domain models. Whether it's the history of stock market data in a financial application or tracking the lifecycle of a loan in a mortgage lending system, temporal data management is an important part of the design in the enterprise applications.

Bitemporal framework from ErvaCon is an open source project created based on the Temporal Patterns to address the time related data requirements in rich domain models. This framework was discussed in a recent presentation by Erwin Vervaet at SpringExperience conference. Bitemporal can be used to persist core domain objects and their bitemporal properties (such as Address, Name, Social Status that don't change too frequently) in a relational database like Oracle using an Object Relational Mapping (ORM) framework such as Hibernate.

In the presentation, Erwin explained three different ways of managing the temporal data in an application:

  • Non-temporal: No time tracking is supported in the system and the data can only answer questions about the current situation. Relational databases such as Oracle or Microsoft SQL Server are non-temporal.
  • Single-temporal: This has two variants called actual-temporal and record-temporal. Actual-temporal adds a validity interval to track when a fact is valid in actual time. Record-temporal adds a record interval to track when a fact was recorded in the system. This provides a way to answer questions about what was known about a domain object at a certain point in time.
  • Bi-temporal: This design approach combines actual-temporal and record-temporal change tracking concepts. It allows the system to answer questions about what was known at a certain point in time about a fact at another moment. This design is more complex than the other two options since the system will have to track two time intervals.

Erwin discussed the design options for implementing bi-temporality in domain models by using a Temporal Database or writing custom code. A Temporal Database supports the time aspects like temporal data model and temporal version of SQL. TimeDB is an open-source temporal relational database product. Oracle FlashBack is another temporal database product that supports the record-temporal feature. Using Flashback, the DBAs can restore a table or an entire database to a point in the past using a simple SQL statement with FLASHBACK keyword. FLASHBACK TABLE statement reads the past images of the table from the undo segments and reconstructs the table rows using the flashback queries.

Regarding the custom code, the implementation technique for adding time information to a database is to add four additional columns in the tables (validityFrom, validityTo, recordFrom, and recordTo columns). Speaking of temporal based system design, Erwin listed the following as the key facets of temporal change tracking:

  • Identity
  • Immutability (Temporal properties are immutable in the sense that changing the value results in a new value being added to the properties history).
  • Validity & Recording time details
  • Controlling time

Temporal patterns are not a new concept in the application architecture and design. Martin Fowler documented these patterns on his "Patterns of Enterprise Application Architecture" (PoEAA) website. Temporal Patterns section on the website includes the patterns such as Audit Log, Effectivity, Temporal Property, Temporal Object, and Snapshot.

The key interfaces and classes in Bi-temporal framework are BitemporalTrace, Bitemporal, BitemporalProperty, WrappedBitemporalProperty, BitemporalWrapper, and TimeUtils. The framework uses Joda Time API for handling the date time manipulation logic. The source code of the project is available for download from their Subversion repository.

 

Rate this Article

Adoption
Style

BT