当前位置:网站首页>A usage example that can be compatible with various database transactions
A usage example that can be compatible with various database transactions
2022-07-05 10:38:00 【Full stack programmer webmaster】
Incoming entity execution ( Additable modify Delete ) Business .
IDbHelper dbHelper = new OracleHelper(ConfigHelper.GetConfigString("BusinessDbConnection"));
bool result = true;
try
{
dbHelper.BeginTransaction();
// Main table
TE_AREAManager manager = new TE_AREAManager(dbHelper, userInfo);
TE_AREAEntity tE_AREAEntity = manager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
manager.Delete(tE_AREAEntity);
// Sub table
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);
// Transaction submission
dbHelper.CommitTransaction();
}
catch(Exception ex)
{
// Transaction rollback
dbHelper.RollbackTransaction();
result=false;
}
You can pass in sql Statements execute transactions
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;
}
You can also pass in entities at the same time ,SQL sentence
IDbHelper dbHelper = new OracleHelper(ConfigHelper.GetConfigString("BusinessDbConnection"));
bool result = true;
try
{
dbHelper.BeginTransaction();
// Main table
TE_AREAManager manager = new TE_AREAManager(dbHelper, userInfo);
TE_AREAEntity tE_AREAEntity = manager.GetObject(dbHelper.SqlSafe(eatxtAREA_ID));
manager.Delete(tE_AREAEntity);
// Sub table
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);
// perform SQL sentence
string commandText = " DELETE FROM JINTIANDA WHERE ID=" + dbHelper.SqlSafe(id);
dbHelper.ExecuteNonQuery(commandText);
// Transaction submission
dbHelper.CommitTransaction();
}
catch(Exception ex)
{
// Transaction rollback
dbHelper.RollbackTransaction();
result=false;
}
The above transaction processing method is based on the underlying code of Jiri Gala general permission management component ,dbHelper, Compatible with all kinds of data Library transactions , It's very easy .
Welcome to provide your own experience , Jointly improve development efficiency .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/109843.html Link to the original text :https://javaforall.cn
边栏推荐
- Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
- SAP ui5 objectpagelayout control usage sharing
- AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
- Taro进阶
- Idea create a new sprintboot project
- Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
- 流程控制、
- Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
- 分享.NET 轻量级的ORM
- ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
猜你喜欢
Ad20 make logo
Timed disappearance pop-up
ByteDance Interviewer: how to calculate the memory size occupied by a picture
微信核酸检测预约小程序系统毕业设计毕设(8)毕业设计论文模板
微信核酸检测预约小程序系统毕业设计毕设(7)中期检查报告
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
Comparative learning in the period of "arms race"
How did automated specification inspection software develop?
AtCoder Beginner Contest 258「ABCDEFG」
随机推荐
Go-3-第一个Go程序
数组、、、
想请教一下,十大券商有哪些?在线开户是安全么?
Who is the "conscience" domestic brand?
Golang应用专题 - channel
How does redis implement multiple zones?
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
uniapp
MFC宠物商店信息管理系统
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
LDAP概述
到底谁才是“良心”国产品牌?
Glide conclusion
Qt实现json解析
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
Nuxt//
报错:Module not found: Error: Can‘t resolve ‘XXX‘ in ‘XXXX‘
脚手架开发进阶