Day 10 – Enterprise Application Architecture Patterns – Data Source Architecture Patterns

Time:2019-2-21

1. Table data entry

Acting as an object for database table access entry, an instance handles all rows in the table.

1) Operating mechanism:

Table data entry contains all the SQL used to access a single table or attempt, such as selection, insertion, update, deletion, etc. Other code calls its methods to implement all interactions with the database.
Table data entry can be used with table module, which generates a recordset data structure to be processed by table module

2) Use time:

Data entry is especially suitable for transaction scripts. The choice between row data entry and table data entry is attributed to how to handle multiple rows. Table data entry is used when the representation of result set is convenient for transaction script processing.

3) Examples:

The following two graphs are the implementation of table data entry under normal circumstances and fully utilizing. net features:
Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns
Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns    

    

2. Line Data Entry

Act as an object for a single entry to a record in a data source, one instance per row.

1) Operating mechanism:

Features: Row data entry is an object similar to a single record, such as a row in a database (where each column in the database becomes a domain)

Question: Where do I store the lookup operations that generate this pattern? Since the choice of static lookup methods does not support the polymorphism of different lookup methods for different data sources, it is necessary to set up a separate lookup method object (so that each table in the relational database has a lookup method class and an entry to get the results).

The difference between row data entry and activity record: whether there is any domain logic, and if so, activity record

2) Use time:

Transaction scripts (about the choice between table data entry and row data entry, reference table data entry)

The row data entry can be used in conjunction with the data mapper: the row data entry is automatically generated from metadata, and the data mapper is implemented manually.

3) Examples:

    Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns

3. Activity records

An object that contains a row in a database table or view, encapsulates database access, and adds domain logic to that data

1) Operating mechanism:

The essence of activity record is a domain model, in which the class and the record structure in the base database are very consistent.

Activity records usually have the following methods:

An active record instance is constructed from a row in the SQL result set.

Construct a new instance for future insertion of tables;

Packing commonly used SQL queries and returning activity records with static lookup methods (can also be separated into a separate class);

Update the database and insert the data from the active records into the database.

Gets or sets the domain;

Implement part of business logic.

2) Use time:

Suitable for creating, reading, updating, deleting less complex domain logic;

Advantages: Simple, easy to create, easy to understand;

Disadvantages: It is difficult to reconstruct the project because of the tight coupling between object design and database design; when business logic is complex and there are concerns about reference, collection and inheritance among objects, it is difficult to map to activity records.

3) Examples:

    Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns

Among them, the domain logic implementation is the mark circle.

4. Data Mapper

A mapper layer that moves data between objects and databases (and mappers themselves) while maintaining their independence is as follows:
    Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns

1) Operating mechanism:

Main Functions: Separating Domain and Data Sources

Lazy loading

Metadata based Mapping

2) Use time:

When business logic is complex and database schemas and object models need to evolve independently of each other

3) Examples:

    Day 10 - Enterprise Application Architecture Patterns - Data Source Architecture Patterns
Among them, DataMapper implements the IPersonFinder interface for the implementation of lookup methods.