当前位置:网站首页>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
边栏推荐
- Learning note 4 -- Key Technologies of high-precision map (Part 2)
- BOM//
- 2022年化工自动化控制仪表考试试题及在线模拟考试
- Ad20 make logo
- “军备竞赛”时期的对比学习
- flex4 和 flex3 combox 下拉框长度的解决办法
- Who is the "conscience" domestic brand?
- How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
- Activity jump encapsulation
- Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
猜你喜欢
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
Redis如何实现多可用区?
SAP ui5 objectpagelayout control usage sharing
微信核酸检测预约小程序系统毕业设计毕设(8)毕业设计论文模板
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
Learning note 4 -- Key Technologies of high-precision map (Part 2)
Events and bubbles in the applet of "wechat applet - Basics"
Learning II of workmanager
随机推荐
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
C语言活期储蓄账户管理系统
GO项目实战 — Gorm格式化时间字段
Go-2-Vim IDE常用功能
AtCoder Beginner Contest 258「ABCDEFG」
Qt实现json解析
NAS与SAN
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
SAP UI5 ObjectPageLayout 控件使用方法分享
Error: module not found: error: can't resolve 'xxx' in 'XXXX‘
2022年化工自动化控制仪表考试试题及在线模拟考试
Implementation of wechat applet bottom loading and pull-down refresh
Completion report of communication software development and Application
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
2021年山东省赛题库题目抓包
Pseudo class elements -- before and after
Ad20 make logo
ByteDance Interviewer: how to calculate the memory size occupied by a picture
函数///
Node の MongoDB Driver