当前位置:网站首页>一个可以兼容各种数据库事务的使用范例
一个可以兼容各种数据库事务的使用范例
2022-07-05 10:12:00 【全栈程序员站长】
传入实体执行(可添加 修改 删除)事务。
IDbHelper dbHelper = new OracleHelper(ConfigHelper.GetConfigString("BusinessDbConnection"));
bool result = true;
try
{
dbHelper.BeginTransaction();
//主表
TE_AREAManager manager = new TE_AREAManager(dbHelper, userInfo);
TE_AREAEntity tE_AREAEntity = manager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
manager.Delete(tE_AREAEntity);
//子表
TE_AREA_SUBManager submanager = new TE_AREA_SUBManager(dbHelper, userInfo);
TE_AREA_SUBEntity tE_AREA_SUBEntity = submanager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
submanager.Delete(tE_AREA_SUBEntity);
//事务提交
dbHelper.CommitTransaction();
}
catch(Exception ex)
{
//事务回滚
dbHelper.RollbackTransaction();
result=false;
}
可以传入sql语句执行事务
IDbHelper dbHelper = new OracleHelper(ConfigHelper.GetConfigString("BusinessDbConnection"));
bool result = true;
try
{
dbHelper.BeginTransaction();
string commandText = " DELETE FROM TE_AREA WHERE ID=" + dbHelper.SqlSafe(id);
dbHelper.ExecuteNonQuery(sqlString);
commandText = " DELETE FROM TE_AREA_SUB WHERE ID=" + dbHelper.SqlSafe(id);
dbHelper.ExecuteNonQuery(commandText);
dbHelper.CommitTransaction();
}
catch(Exception ex)
{
dbHelper.RollbackTransaction();
result=false;
}
还可以同时传入实体,SQL语句
IDbHelper dbHelper = new OracleHelper(ConfigHelper.GetConfigString("BusinessDbConnection"));
bool result = true;
try
{
dbHelper.BeginTransaction();
//主表
TE_AREAManager manager = new TE_AREAManager(dbHelper, userInfo);
TE_AREAEntity tE_AREAEntity = manager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
manager.Delete(tE_AREAEntity);
//子表
TE_AREA_SUBManager submanager = new TE_AREA_SUBManager(dbHelper, userInfo);
TE_AREA_SUBEntity tE_AREA_SUBEntity = submanager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
submanager.Delete(tE_AREA_SUBEntity);
//执行SQL语句
string commandText = " DELETE FROM JINTIANDA WHERE ID=" + dbHelper.SqlSafe(id);
dbHelper.ExecuteNonQuery(commandText);
//事务提交
dbHelper.CommitTransaction();
}
catch(Exception ex)
{
//事务回滚
dbHelper.RollbackTransaction();
result=false;
}
以上事务处理方法是基于吉日嘎拉通用权限管理组件底层的代码上实现的,dbHelper,兼容各种数据库事务处理,非常省心省事。
欢迎大家提供自己的使用经验,共同提高开发效率。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/109843.html原文链接:https://javaforall.cn
边栏推荐
- 微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
- Learning Note 6 - satellite positioning technology (Part 1)
- How did automated specification inspection software develop?
- @Jsonadapter annotation usage
- php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
- Workmanager learning 1
- flink cdc不能监听mysql日志,大家遇到过这个问题吧?
- QT VT100 parser
- Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges
- mongoDB副本集
猜你喜欢
Learning Note 6 - satellite positioning technology (Part 1)
Constraintlayout officially provides rounded imagefilterview
Secteur non technique, comment participer à devops?
Energy momentum: how to achieve carbon neutralization in the power industry?
Idea create a new sprintboot project
A high density 256 channel electrode cap for dry EEG
程序员如何活成自己喜欢的模样?
Workmanager learning 1
到底谁才是“良心”国产品牌?
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
随机推荐
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
AtCoder Beginner Contest 258「ABCDEFG」
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
【Vite】1371- 手把手开发 Vite 插件
如何判断线程池已经执行完所有任务了?
微信小程序触底加载与下拉刷新的实现
Learning notes 5 - high precision map solution
Excerpt from "sword comes" (VII)
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
WorkManager的学习二
《天天数学》连载58:二月二十七日
Idea create a new sprintboot project
橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
想请教一下,十大券商有哪些?在线开户是安全么?
Usage differences between isempty and isblank
学习笔记5--高精地图解决方案
自动化规范检查软件如何发展而来?
"Everyday Mathematics" serial 58: February 27
Qt实现json解析
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning