当前位置:网站首页>一个可以兼容各种数据库事务的使用范例
一个可以兼容各种数据库事务的使用范例
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‘
- 字节跳动面试官:一张图片占据的内存大小是如何计算
- Singleton mode encapsulates activity management class
- RMS to EAP is simply implemented through mqtt
- Should the dependency given by the official website be Flink SQL connector MySQL CDC, with dependency added
- Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
- Go项目实战—参数绑定,类型转换
- 《剑来》语句摘录(七)
- 历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
- 一个程序员的职业生涯到底该怎么规划?
猜你喜欢

"Everyday Mathematics" serial 58: February 27

Comparative learning in the period of "arms race"

Swift tableview style (I) system basic

Usage differences between isempty and isblank

RMS to EAP is simply implemented through mqtt

StaticLayout的使用详解

“军备竞赛”时期的对比学习

What is the most suitable book for programmers to engage in open source?

如何判断线程池已经执行完所有任务了?

A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
随机推荐
QT VT100 parser
Redis如何实现多可用区?
Energy momentum: how to achieve carbon neutralization in the power industry?
Universal double button or single button pop-up
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
What is the most suitable book for programmers to engage in open source?
Implementation of wechat applet bottom loading and pull-down refresh
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
A high density 256 channel electrode cap for dry EEG
AD20 制作 Logo
Tianlong Babu TLBB series - about items dropped from packages
isEmpty 和 isBlank 的用法区别
Applet image height adaptation and setting text line height
The most complete is an I2C summary
Write double click event
Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges
uniapp + uniCloud+unipay 实现微信小程序支付功能
Constrained layout flow
NCP1342芯片替代料PN8213 65W氮化镓充电器方案