当前位置:网站首页>一个可以兼容各种数据库事务的使用范例
一个可以兼容各种数据库事务的使用范例
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
边栏推荐
- 报错:Module not found: Error: Can‘t resolve ‘XXX‘ in ‘XXXX‘
- Click the picture in the mobile browser and the picture will not pop up
- WorkManager的学习二
- Workmanager Learning one
- Glide advanced level
- What is the most suitable book for programmers to engage in open source?
- Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
- @Jsonadapter annotation usage
- To bring Euler's innovation to the world, SUSE should be the guide
- 微信小程序触底加载与下拉刷新的实现
猜你喜欢
Advanced opencv:bgr pixel intensity map
如何判断线程池已经执行完所有任务了?
WorkManager學習一
【小技巧】获取matlab中cdfplot函数的x轴,y轴的数值
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
Window下线程与线程同步总结
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
Swift tableview style (I) system basic
《微信小程序-基础篇》小程序中的事件与冒泡
随机推荐
Glide conclusion
SLAM 01.人类识别环境&路径的模型建立
Pagoda panel MySQL cannot be started
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
StaticLayout的使用详解
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
IDEA新建sprintboot项目
Implementation of wechat applet bottom loading and pull-down refresh
How does redis implement multiple zones?
5g NR system architecture
驱动制造业产业升级新思路的领域知识网络,什么来头?
如何判断线程池已经执行完所有任务了?
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
uniapp + uniCloud+unipay 实现微信小程序支付功能
C function returns multiple value methods
【Vite】1371- 手把手开发 Vite 插件
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
横向滚动的RecycleView一屏显示五个半,低于五个平均分布