当前位置:网站首页>一个可以兼容各种数据库事务的使用范例
一个可以兼容各种数据库事务的使用范例
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
边栏推荐
- Go项目实战—参数绑定,类型转换
- 面试:List 如何根据对象的属性去重?
- Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges
- Personal website construction tutorial | local website environment construction | website production tutorial
- 一个程序员的职业生涯到底该怎么规划?
- QT VT100 parser
- Lepton 无损压缩原理及性能分析
- Detailed explanation of the use of staticlayout
- 手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
- 《剑来》语句摘录(七)
猜你喜欢
![[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems](/img/6c/5b14f47503033bc2c85a259a968d94.png)
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems

@Serializedname annotation use

到底谁才是“良心”国产品牌?

Constraintlayout officially provides rounded imagefilterview

AtCoder Beginner Contest 258「ABCDEFG」

学习笔记5--高精地图解决方案

The most complete is an I2C summary

AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」

一个程序员的职业生涯到底该怎么规划?

重磅:国产IDE发布,由阿里研发,完全开源!
随机推荐
程序员搞开源,读什么书最合适?
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
钉钉、企微、飞书学会赚钱了吗?
Who is the "conscience" domestic brand?
伪类元素--before和after
“军备竞赛”时期的对比学习
最全是一次I2C总结
MySQL digital type learning notes
字节跳动面试官:一张图片占据的内存大小是如何计算
PHP solves the problems of cache avalanche, cache penetration and cache breakdown of redis
Zblogphp breadcrumb navigation code
【小技巧】获取matlab中cdfplot函数的x轴,y轴的数值
Constraintlayout officially provides rounded imagefilterview
《剑来》语句摘录(七)
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
程序员如何活成自己喜欢的模样?
Redis如何实现多可用区?
驱动制造业产业升级新思路的领域知识网络,什么来头?
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)