当前位置:网站首页>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
边栏推荐
- [vite] 1371 - develop vite plug-ins by hand
- Glide Mastery
- 分享.NET 轻量级的ORM
- 官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
- 数据类型、
- 请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
- Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
- uniapp
- IDEA新建sprintboot项目
- 脚手架开发进阶
猜你喜欢

双向RNN与堆叠的双向RNN

Apple 5g chip research and development failure? It's too early to get rid of Qualcomm

How does redis implement multiple zones?

Universal double button or single button pop-up

Workmanager learning 1

Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!

Idea create a new sprintboot project

How to write high-quality code?

微信核酸检测预约小程序系统毕业设计毕设(7)中期检查报告

ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
随机推荐
Shortcut keys for vscode
How does redis implement multiple zones?
括号匹配问题(STL)
Pseudo class elements -- before and after
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
正则表达式
2022年流动式起重机司机考试题库及模拟考试
flex4 和 flex3 combox 下拉框长度的解决办法
2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
Glide Mastery
WorkManager的学习二
2022鹏城杯web
[vite] 1371 - develop vite plug-ins by hand
What are the top ten securities companies? Is it safe to open an account online?
Singleton mode encapsulates activity management class
请问大佬们 有遇到过flink cdc mongdb 执行flinksql 遇到这样的问题的么?
How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同