MyBatis know how much (7) persistence layer

Source: Internet
Author: User

The persistence layer is a suitable place to use MyBatis. In an object-oriented system, the persistence layer focuses on the access of objects (or, more precisely, the data stored in those objects). Persistence tiers in enterprise applications typically use relational database systems to store data, although in some cases other persistent data structures or media may be used. For example, some systems may use a simple comma-delimited tablet or XML file. Considering that the persistence strategy of an enterprise application tends to be heterogeneous, the second problem that a persistence layer needs to focus on is abstraction. The persistence layer should hide all the details about how the data is stored and how it is fetched. Such details must not be exposed to the other layers of the application.

To better understand these concerns and how they are managed, we divide the persistence layer into 3 layers: The abstraction layer, the persistence framework, and the driver/interface layer, for example.

Let's take a closer look at the 3 layers we get from the persistence layer subdivision.

Abstraction Layer

The purpose of the abstraction layer is to provide a consistent and meaningful interface to the persistence layer. It is a collection of classes and methods that are the persistence layer implementation details. Methods in the abstraction layer cannot use implementation-specific parameters, nor can they return specific implementations of specialized classes or throw exceptions that are specific to a particular implementation. Once the appropriate abstraction layer is ready, changes to the entire persistence method (including persistent APIs and storage facilities) no longer involve the abstraction layer, nor can any other dependency layer change. There are many patterns that can be used to help implement an appropriate abstraction layer, the most common of which is the DAO pattern. Many frameworks, including MyBatis, have implemented this pattern for you.

Persistence Framework

The persistence framework is responsible for interacting with the database driver (or interface). The persistence Framework provides methods for storing, retrieving, updating, locating, and managing data. Unlike the abstraction layer, the persistence framework typically targets only a class of storage facilities. For example, you might find a persistence API dedicated to data storage that processes XML files. However, for most modern enterprise applications, relational databases are often the first choice for storage facilities. Most popular programming languages have standard APIs for accessing relational databases. JDBC is a standard framework for Java applications to access databases

① is the "appearance mode", which defines a consistent set of interfaces for a subsystem. The standard persistence framework for the library. These standard APIs can be used for any purpose, so they are very well-implemented, but very lengthy and cumbersome to use. For these reasons, many frameworks have been created on the basis of the standard API to make them more dedicated and therefore more powerful. MyBatis is such a persistence framework that is dedicated to working with any type of relational database and supporting Java in a consistent way.

Driver/Interface Layer

Storage facilities can be as simple as a comma-delimited tablet file, or it can be as complex as a millions of-dollar enterprise database server. In either case, there is always a software driver that communicates with the storage facility at the bottom to exchange data. Some drivers, such as local file system drivers, are functionally generic, but are platform-dependent. You may never see the file I/O driver, but it is certain that it must exist. On the other hand, database drivers are always very complex and differ greatly in implementation, size, and behavior. Therefore, it is necessary for the persistence framework to communicate with these database drivers to simplify and reduce the differences between them to the lowest point.

Series Articles:

MyBatis know how much (1)

MyBatis know how much (2)

MyBatis know how much (3)

MyBatis know how (4) The advantages of MyBatis

MyBatis know how much (5) Business object model

MyBatis know how (6) presentation layer and business logic layer

MyBatis know how much (7) persistence layer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.