PEAA notes seven: data mapper

xiaoxiao2021-03-06  47

What is it data mapper is an intermediate layer that passes data between data objects and databases, so that both the independent data object can contain data and business logic. Data access logic has DataMapper completion, which makes data objects and databases can be used In line with your own method to organize the data structure, the data objects in the memory need to know SQL and databases, and even Data Mapper is unknown for business layers.

How IT Works Data Mapper can be replaced entirely, or for testing, or for database operations for use in the same set of business logic, the Data Mapper layer needs to know which changes have a database in order to correspond to the data object, so Often the entire operation in a transaction framework, you can use the Unit of Work mode to organize. When using Data Mapper, you can also generate multiple related object instances using a query. An application can have one or more Data Mapper, if you hardly encode mapper, then it is best to use a mapper every business domain or business system; if you use MAPPER, you can use it. For the latter case, complexity is transferred to the Finder method, a separate MAPper uses a lot of Finder methods, we can manage similar Finder in accordance with the business system in a Finder class. When using the finder class, the Finder class also uses the Identity Map to maintain the uniqueness of the object.

Handling Finders We can launch all objects to memory when the business system is started, or Lazy Load, whenever an object is used, there are two ways to create an object via the Finder to increase the efficiency to create an object, one It is a fat structure, that is, it is incoming a lot of data to build the object; one is to build an empty object and then assign a value through the setter function. The former is very good, but must pay attention to the problem of cyclic references, that is, two objects are cited to each other, and the result is caught when it is created. The solution is to create an empty object, then setter settings, and supervise through the Identity Map. Once the loop is falling, the Identity Map returns the object that has been created, not to continue to create an object.

Metadata based mappings When the data object and database domain are mapped, an explicit mapping is clearly configured with object properties and database domains; the other is to communicate the original data as a data transfer, which can pass the original data. Process mapping relationship.

The main role of WHEN to Use IT using Data Mapper is to make Domain Model ignore the database, whether it is designed, created or testing. The coding personnel use as long as the business logic is known without having to care about the data store. The disadvantage is of course a Mapper layer. When not using Domain Model, it is generally not used to use Data Mapper.

转载请注明原文地址:https://www.9cbs.com/read-77302.html

New Post(0)