当前位置:网站首页>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:框架会综合考虑相关领域中在实际开发环境下有可能遇到的各种问题,进行了健壮性、性能等各个方面的优化
所以,我们可以总结
下面两个概念:
编程式
:自己写代码实现功能- `声明式:通过配置让框架实现功能
边栏推荐
- Gartner 权威预测未来4年网络安全的8大发展趋势
- Uni-app 小程序 App 的广告变现之路:全屏视频广告
- Redis common interview questions
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
- C语言 -- 操作符详解
- 力扣:96.不同的二叉搜索树
- 你以为border-radius只是圆角吗?【各种角度】
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
- [C language advanced] program environment and preprocessing
- Introduction and application of go module
猜你喜欢
Do you think border-radius is just rounded corners?【Various angles】
你以为border-radius只是圆角吗?【各种角度】
部署LVS-DR群集【实验】
Delphi-C端有趣的菜单操作界面设计
心余力绌:企业面临的软件供应链安全困境
How to simplify the automation of modern e-procurement?
Shocked, 99.9% of the students didn't really understand the immutability of strings
【云原生--Kubernetes】Pod资源管理与探针检测
编程大杂烩(四)
嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
随机推荐
Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
There is an 8 hour difference between the docker installation of mysql and the host.
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
MySQL日期函数
【JS】js给对象动态添加、设置、删除属性名和属性值
Performance testing with Loadrunner
Introduction and application of go module
力扣:509. 斐波那契数
[SemiDrive source code analysis] [MailBox inter-core communication] 47 - Analysis of RPMSG_IPCC_RPC mode limit size of single transmission and limit bandwidth test
Write golang simple C2 remote control based on gRPC
word 公式编辑器 键入技巧 | 写数学作业必备速查表
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
[One step in place] Jenkins installation, deployment, startup (complete tutorial)
Gartner 权威预测未来4年网络安全的8大发展趋势
Converts XML tags to TXT format (voc conversion for yolo convenient training)
C专家编程 第5章 对链接的思考 5.6 轻松一下---看看谁在说话:挑战Turning测验
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
Large chain best freight d audit with what software?What are the functions?
About yolo7 and gpu
深度学习21天——准备(环境配置)