1.Spring 的事务抽象

Spring提供了一致的事务模型

  • JDBC/Hibernate/Mybatis 操作数据
  • DataSource/JTA 事务

2.事务抽象的核心接口

PlatformTransactionManage

  • DateSourceTransactionManage
  • HibernateTransactionManage
  • JtaTransactionManage

TransactionDefinition

  • Propagation
  • lsolation
  • Timeout
  • Read-only status

3.事务传播特性7个

4.事务隔离特性

5.编程式事务

在spring 提供的事务里面经常用下面两种进行事务的操作

TransactionTemplate

  • TransactionCallback
  • TransactionCallbackWithoutResult

PlatformTransactionManage

  • 可以传入TransactionDefinition

6.测试编程式事务

@SpringBootApplication
public class DemoApplication implements CommandLineRunner { @Autowired
private TransactionTemplate transactionTemplate; @Autowired
private JdbcTemplate jdbcTemplate; public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
} @Override
public void run(String... args) throws Exception { System.out.println("事务执行前---》"+getCount()); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override
protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) { //事务执行中
jdbcTemplate.execute("insert into user(id,username,password) values(1,1,1)");
System.out.println("事务执行中---》"+getCount());
//回滚W
transactionStatus.setRollbackOnly();
}
});
System.out.println("事务执行后---》"+getCount()); } //统计数据条数
public long getCount() {
return jdbcTemplate.queryForObject("select count(*) from user", Long.class);
} }

7.申明式事务

8.基于注解的配置方式

开启事务注解的方式 @EnableTransactionManagement

@Transactional

  1. transactionManage
  2. propagation
  3. isolation
  4. timeout
  5. readOnly
  6. 判断回滚

9.代码参考:https://gitee.com/mrc1999/SpringBoot-study-book/tree/master/04TransactionTemplate

玩转Spring全家桶笔记 04 Spring的事务抽象、事务传播特性、编程式事务、申明式事务的更多相关文章

  1. 玩转Spring全家桶笔记 03 Spring的JDBC操作以及SQL批处理的实现

    1 spring-jdbc core JdbcTemplate 等相关核心接口和类(核心) datesource 数据源相关的辅助类(内嵌数据源的初始化) object 将基本的JDBC操作封装成对象 ...

  2. 玩转Spring全家桶笔记 02 那些好用的连接池HikariCP

    1.前言 简单了解一下来自日本的一个新起之秀连接池---HikariCP github:https://github.com/brettwooldridge/HikariCP 2.HikariCP为什 ...

  3. Spring全家桶系列–SpringBoot渐入佳境

    //本文作者:cuifuan //本文将收录到菜单栏:<Spring全家桶>专栏中 首发地址:https://www.javazhiyin.com/20913.html 萌新:小哥,我在实 ...

  4. Java秋招面试复习大纲(二):Spring全家桶+MyBatis+MongDB+微服务

    前言 对于那些想面试高级 Java 岗位的同学来说,除了算法属于比较「天方夜谭」的题目外,剩下针对实际工作的题目就属于真正的本事了,热门技术的细节和难点成为了面试时主要考察的内容. 这里说「天方夜谭」 ...

  5. 最全153道Spring全家桶面试题,你都碰到过哪些?(含答案解析)

    前言 Spring 框架自诞生以来一直备受开发者青睐,有人亲切的称之为:Spring 全家桶. 毋庸置疑,Spring 早已成为 Java 后端开发的行业标准,无数的公司选择 Spring 作为基础的 ...

  6. 10分钟详解Spring全家桶7大知识点

    Spring框架自2002年诞生以来一直备受开发者青睐,它包括SpringMVC.SpringBoot.Spring Cloud.Spring Cloud Dataflow等解决方案.有人亲切的称之为 ...

  7. Spring全家桶–SpringBoot Rest API

    Spring Boot通过提供开箱即用的默认依赖或者转换来补充Spring REST支持.在Spring Boot中编写RESTful服务与SpringMVC没有什么不同.总而言之,基于Spring ...

  8. Spring全家桶系列–SpringBoot之AOP详解

    //本文作者:cuifuan //本文将收录到菜单栏:<Spring全家桶>专栏中 面向方面编程(AOP)通过提供另一种思考程序结构的方式来补充面向对象编程(OOP). OOP中模块化的关 ...

  9. Spring全家桶系列–[SpringBoot入门到跑路]

    //本文作者:cuifuan Spring全家桶————[SpringBoot入门到跑路] 对于之前的Spring框架的使用,各种配置文件XML.properties一旦出错之后错误难寻,这也是为什么 ...

随机推荐

  1. 深入浅出的Java网络通信

    已经发表个人公众号 代码展示 package two; import java.io.BufferedReader; import java.io.InputStreamReader; import ...

  2. GoCN每日新闻(2019-10-04)

    GoCN每日新闻(2019-10-04) 国庆专辑:GopherChina祝大家国庆节快乐 GoCN每日新闻(2019-10-04) 1. Go提议流程:代表 https://research.swt ...

  3. Exception in thread "main" java.lang.IllegalStateException: Failed to read 问题解决

    开发中偶尔遇到这样的问题:Exception in thread "main" java.lang.IllegalStateException: Failed to read .. ...

  4. 20189220 余超《Linux内核原理与分析》第六周作业

    系统调用的三层机制 实验过程 1.克隆MenuOS rm menu -rf //强制删除当前menu git clone http://git.shiyanlou.com/mengning/menu. ...

  5. 团队作业-Alpha(3/4)

    队名:软工9组 组长博客:https://www.cnblogs.com/cmlei/ 作业博客:https://edu.cnblogs.com/campus/fzu/SoftwareEngineer ...

  6. Unity 现代室内环境场景高效流程视频教程 附源文件 中文字幕

    大小1.83G,中文字幕 章节内容:1.项目介绍2.准备maya工程文件3.素材资产(assets)结构4.管理unity中的maya资产5.整合场景6.unity游戏对象及材质7.第一人称控制器8. ...

  7. Calcite分析 - RelTrait

    RelTrait 表示RelNode的物理属性 由RelTraitDef代表RelTrait的类型 /** * RelTrait represents the manifestation of a r ...

  8. java对压缩文件进行加密,winrar和好压 直接输入解密密码来使用

    <!-- https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j --> <dependency> <gro ...

  9. gdb命名记录

    gdb常用命令 显示类 info locals 显示当前局部变量 info args 显示当前函数的参数 info sharedlibrary 显示当前程序依赖的动态库 ptype val 打印变量类 ...

  10. dockerfile运行mysql并初始化数据

    本文目的不仅仅是创建一个MySQL的镜像,而是在其基础上再实现启动过程中自动导入数据及数据库用户的权限设置,并且在新创建出来的容器里自动启动MySQL服务接受外部连接,主要是通过Dockerfile和 ...