当前位置:网站首页>一个可以兼容各种数据库事务的使用范例
一个可以兼容各种数据库事务的使用范例
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
边栏推荐
- Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
- Idea create a new sprintboot project
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
- MySQL digital type learning notes
- PHP solves the problems of cache avalanche, cache penetration and cache breakdown of redis
- How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
- 《天天数学》连载58:二月二十七日
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- Learning II of workmanager
猜你喜欢
5g NR system architecture
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
isEmpty 和 isBlank 的用法区别
How does redis implement multiple zones?
StaticLayout的使用详解
Fluent generates icon prompt logo widget
How to judge that the thread pool has completed all tasks?
@SerializedName注解使用
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
程序员如何活成自己喜欢的模样?
随机推荐
Comparative learning in the period of "arms race"
历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
@JsonAdapter注解使用
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
Advanced opencv:bgr pixel intensity map
Detailed explanation of the use of staticlayout
Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
AtCoder Beginner Contest 258「ABCDEFG」
Uni app running to wechat development tool cannot Preview
学习笔记5--高精地图解决方案
LDAP概述
SAP UI5 ObjectPageLayout 控件使用方法分享
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
How to plan the career of a programmer?
Go项目实战—参数绑定,类型转换
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
Interview: is bitmap pixel memory allocated in heap memory or native
Usage differences between isempty and isblank
请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
Learning notes 5 - high precision map solution