Posts

Showing posts from April, 2018

Identity Map Pattern

Image
This pattern belongs to  Object-Relational Behavioral Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them. An Identity Map keeps a record of all objects that have been read from the database in a single business transaction. Whenever you want an object, you check the Identity Map first to see if you already have it. How It Works The basic idea behind the Identity Map is to have a series of maps containing objects that have been pulled from the database. In a simple case, with an isomorphic schema, you�ll have one Map per database table.  When you load an object from the database, you first check the map. If there�s an object in it that corresponds to the one you�re loading, you return it. If not, you go to the database, putting the objects on the map for future...

Unit Of Work

Image
This pattern belongs to  Object-Relational Behavioral Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent When a business transaction is completed, all these updates are sent as one big unit of work to be persisted in a database in one go so as to minimize database trips. Explanation Unit of Work design pattern does two important things: first, it maintains in-memory updates and second it sends these in-memory updates as one transaction to the database. So to achieve the above goals it goes through two steps: It maintains lists of business objects in-memory which have been changed (inserted, updated, or deleted) during a transaction. Once the transaction is completed, all these updates are sent as one big unit of work to be persisted physically in a database in one go. What is � Work � and � Unit � in a software application? A simple definition of Work means performing some task.  From a software appl...

Repository Pattern

Image
This pattern belongs to  Object-Relational Metadata Mapping Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent Repository layer is added between the domain and data mapping layers to isolate domain objects from details of the database access code and to minimize scattering and duplication of query code.  The Repository pattern is especially useful in systems where a number of domain classes are large or heavy querying is utilized. Real World Examples Spring Data Applicability Use the Repository pattern when the number of domain objects is large you want to avoid duplication of query code you want to keep the database querying code in a single place you have multiple data sources Explanation A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper , that isolates domain objects from details of the database access code. In such systems, it can be worthwh...