当前位置:网站首页>4.2 声明式事务概念
4.2 声明式事务概念
2022-08-04 05:24:00 【猿 白】
声明式事务
4.2、声明式事务概念
4.2.1、编程式事务
事务功能的相关操作全部通过自己编写代码来实现:
Connection conn = ...;
try {
// 开启事务:关闭事务的自动提交
conn.setAutoCommit(false);
// 核心操作
// 提交事务
conn.commit();
}catch(Exception e){
// 回滚事务
conn.rollBack();
}finally{
// 释放数据库连接
conn.close();
}
编程式的实现方式存在缺陷
:
- 细节没有被屏蔽:具体操作过程中,所有细节都需要程序员自己来完成,比较繁琐。
- 代码复用性不高:如果没有有效抽取出来,每次实现功能都需要自己编写代码,代码就没有得到复用。
4.2.2、声明式事务
既然事务控制的代码有规律可循,代码的结构基本是确定的,所以框架就可以将固定模式的代码抽取出来,进行相关的封装。
封装起来后,我们只需要在配置文件中进行简单的配置即可完成操作。
- 好处1:提高开发效率
- 好处2:消除了冗余的代码
- 好处3:框架会综合考虑相关领域中在实际开发环境下有可能遇到的各种问题,进行了健壮性、性能等各个方面的优化
所以,我们可以总结
下面两个概念:
编程式
:自己写代码实现功能- `声明式:通过配置让框架实现功能
边栏推荐
- C专家编程 第5章 对链接的思考 5.2 动态链接的优点
- [21 Days Learning Challenge] Image rotation problem (two-dimensional array)
- 一个对象引用的思考
- How to dynamically add script dependent scripts
- Programming hodgepodge (4)
- [One step in place] Jenkins installation, deployment, startup (complete tutorial)
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
- DataTable uses Linq for grouping and summarization, and converts the Linq result set into DataTable
- Chapter 5 C programming expert thinking 5.4 alert Interpositioning of links
- px、em、rem的区别
猜你喜欢
信息学奥赛一本通 1312:【例3.4】昆虫繁殖
About yolo7 and gpu
Mini program + e-commerce, fun new retail
Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
Shocked, 99.9% of the students didn't really understand the immutability of strings
What is the salary of a software testing student?
el-Select selector bottom fixed
触觉智能分享-SSD20X实现升级显示进度条
应届生软件测试薪资大概多少?
深度学习21天——卷积神经网络(CNN):实现mnist手写数字识别(第1天)
随机推荐
Shocked, 99.9% of the students didn't really understand the immutability of strings
Programming hodgepodge (4)
8大软件供应链攻击事件概述
高性能高可靠性高扩展性分布式防火墙架构
idea设置识别.sql文件类型以及其他文件类型
[C language advanced] program environment and preprocessing
flink cdc一启动,源端Oracle那台服务器的CPU就飙升到80%以上,会是啥原因呢?
Uni-app 小程序 App 的广告变现之路:全屏视频广告
获取单选框选中内容
Delphi-C端有趣的菜单操作界面设计
嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型
C专家编程 第5章 对链接的思考 5.2 动态链接的优点
Gartner 权威预测未来4年网络安全的8大发展趋势
应届生软件测试薪资大概多少?
DataTable使用Linq进行分组汇总,将Linq结果集转化为DataTable
【流程图】
Will the 2023 PMP exam use the new version of the textbook?Reply is here!
信息学奥赛一本通 1312:【例3.4】昆虫繁殖
Introduction and application of go module
MySQL日期函数