-01 towering building a stage, the primary foundation - Chapter 2 single architecture design and preparation work -2-24 Detailed transaction propagation -1

Interview questions: spread spring inside a transaction, which has several, namely what is

the point of coming to see @Transactional source



when using this annotation, in fact, there is a default value. It indicates that the current transaction is sure to use. If things do not currently exist or not, it will create a new thing = own thing. 'If the current method itself, the existence of things, you do not need to create an extra thing. It will join the existing additional things to go inside.

Propagation is an enumeration type

Ctrl + F12 you can put the contents of the current class method inside the show in the form of a list. Let us for quick browsing.

The new method for testing the result of an increase


to create additional service

this service is to call the main method of preservation.


Here is a comment, things spread a total of seven

We caught with one Required


In the api project which joined rely on Junit.

New test class




all do not write things, problems arise


in the database is now one of the data are not





being given.


Open things





Empty data within the database

to run the test class

 
is no data in the database


This is because there were things spread.
Although the method in which the child does not increase the @Transactional comment.

But things will be passed to the next method inside

later when our sub-method exception. Inside the two methods will be rolled back things.

Things opener methods


Methods of things a parent commented.


Run the test. Parent method was successfully saved. The parent level method does not object,

Open things the parent method, child method also opens


子方法的事物也是开启的

数据库内清空

运行测试类

依然报错

数据库依然没有数据

required总结



required多用于增删改的操作。

supports

从字面上看是一种支持。主要是用于做查询的。

父方法事务先注释掉

子方法的事务改为supports


清空数据库,运行测试类。





子方法用了supports。外层方法并没有事务,它就不使用事务,它是跟着外层走的
如果说外层使用了required。子方法还是supports


清空数据库,运行测试。---》数据库为空。事务进行了回滚。

supports总结

主要用于查询。


required和supports是两个最常用的

Mandatory

首先看它的注释。它是支持当前的事物的,如果不存在事物就会抛出异常,它强制了谁调用了我 ,谁就必须要有事物。它没有事务就会抛出异常。

把父方法的事物注释掉。

被调用放,也就是子方法使用mamdatory

运行测试





父方法的事物开启

运行测试,没有报Mandatory抛出的异常。这个错误是我自己代码的异常。

mandatory总结









 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/12046772.html