Objective
Before this article, has written about the source code analysis of AOP, on this basis to read the source of the transaction is relatively clear. In addition, the need to have a certain understanding of the database, we say that the business is generally referred to as a narrow transaction, that is, database transactions. The database, which is not specifically stated in this article, refers to MySQL, which is followed by an article on the lock and transaction of MySQL.
Overview
A transaction is a program execution unit that either succeeds or fails, and absolutely does not allow an intermediate state, which is the basic unit of our recovery and concurrency control.
Study affairs, generally will take money to do the explanation, here also take Zhang San to Li four turn 100 yuan to explain, this process is divided into two steps, Zhang San account minus 100, John Doe account plus 100.
Four characteristics of a transaction (ACID)
- Atomicity: A transaction is done by a series of operations, or the sequence of operations is guaranteed to work at the same time. For example, Zhang San minus 100, Li Shiga 100. To succeed or fail at the same time, it will not satisfy atomicity.
- Consistency: Transition from a database state to a state. Consistency and atomicity are often thought of as a thing, and personal understanding of consistency is from the point of view of state change, that is, the result, and atomicity is more about the process of looking at the problem. As an example, the state here is that the total amount of money in Zhang San and John Doe has not changed before and after the transfer. It can be said that atomicity guarantees consistency.
- Isolation: Transactions that are executed concurrently are isolated from each other. For example, assuming that the Zhang San account has 1000 yuan, he also transferred to Harry 100, transferred to John Doe, his account deducted 100, only 900, to Harry is, then buckle 100, only 800, if John Doe received money when the problem, and Harry received the money successfully, then 800 write to the database. Zhang San will be very angry, because the account is more than 100 deducted. This is a problem.
- Persistence: Transaction completion, regardless of what happens, has no effect on the operation.
Knowledge points
When we learn spring transactions, we typically analyze three of transaction characteristics, isolation levels, and propagation behavior
- Four characteristics of a transaction
Study affairs, generally will take money to do the explanation, here also take Zhang San to Li four turn 100 yuan to explain, this process is divided into two steps, Zhang San account minus 100, John Doe account plus 100.
Four characteristics of a transaction (ACID)
-
- Atomicity: A transaction is done by a series of operations, or the sequence of operations is guaranteed to work at the same time. For example, Zhang San minus 100, Li Shiga 100. To succeed or fail at the same time, it will not satisfy atomicity.
- Consistency: Transition from a database state to a state. Consistency and atomicity are often thought of as a thing, and personal understanding of consistency is from the point of view of state change, that is, the result, and atomicity is more about the process of looking at the problem. As an example, the state here is that the total amount of money in Zhang San and John Doe has not changed before and after the transfer. It can be said that atomicity guarantees consistency.
- Isolation: Transactions that are executed concurrently are isolated from each other. For example, assuming that the Zhang San account has 1000 yuan, he also transferred to Harry 100, transferred to John Doe, his account deducted 100, only 900, to Harry is, then buckle 100, only 800, if John Doe received money when the problem, and Harry received the money successfully, then 800 write to the database. Zhang San will be very angry, because the account is more than 100 deducted. This is a problem.
- Persistence: Transaction completion, regardless of what happens, has no effect on the operation.
- The isolation level of the MySQL database
Divided into the following four levels, each level is to solve the characteristics of the problem
Summarize
This concludes the analysis of the entire AOP and then makes some analysis of the source code of the transaction.
Reference links
- Https://wenku.baidu.com/view/6ce3121da300a6c30c229f89.html (core concerns vs. Crosscutting concerns)
- Https://www.cnblogs.com/syf/archive/2012/05/09/2491780.html (OOP and AOP)
- 78057107 (connection point land concept)
- Https://docs.spring.io/spring/docs/4.3.18.RELEASE/spring-framework-reference (Spring Official document)
- Http://www.cnblogs.com/xrq730/p/6753160.html (reference article for source analysis)
- 78166296 (@DeclareParents use)
Spring source of the affairs of the article