当前位置:网站首页>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
边栏推荐
猜你喜欢
Workmanager Learning one
Comparative learning in the period of "arms race"
2022年T电梯修理操作证考试题及答案
2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
"Everyday Mathematics" serial 58: February 27
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
Timed disappearance pop-up
双向RNN与堆叠的双向RNN
【js学习笔记五十四】BFC方式
Go-3-第一个Go程序
随机推荐
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
微信小程序触底加载与下拉刷新的实现
沟通的艺术III:看人之间 之倾听
Go-3-第一个Go程序
【JS】提取字符串中的分数,汇总后算出平均分,并与每个分数比较,输出
Have you learned to make money in Dingding, enterprise micro and Feishu?
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Node の MongoDB Driver
“军备竞赛”时期的对比学习
Ad20 make logo
Activity enter exit animation
数据库中的范式:第一范式,第二范式,第三范式
请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
【Vite】1371- 手把手开发 Vite 插件
Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
Universal double button or single button pop-up
【js学习笔记五十四】BFC方式
Web Components
Go项目实战—参数绑定,类型转换