java_method_删除事务回滚
public String[] deleteEPGroup(String groupID, String groupName) {
String[] operRes=new String[3];
if(!StringUtils.isEmpty(groupID)) {
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,无法获取要删除的组的GroupID");
return operRes;
}
//组名称的验证处理
if(groupName==null || "".equals(groupName)) {
//如果组名称为空就根据Id数据库中查询
Log.getInstance().printInfo(this.getClass().getName(), "删除同步通讯录组,客户端传递组名称失败,开始从数据库中查询组名称");
List<String[]> groupNameList=this.getGroupByID(groupID);
if(groupNameList==null)
{
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,根据ID查询组名称,数据库连接为null");
return operRes;
}
String[] groupNames=groupNameList.get(0);
if(groupNames==null || groupNames.length<2) {
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,根据ID查询组名称查询返回的数组为空或长度小于2");
return operRes;
}
if(groupNames[1]!=null &&"".equals(groupNames[1])) {
groupName=groupNames[1];
} else {
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,根据ID查询组名称为null或者是空");
return operRes;
}
}
//groupID和groupName都不为空之后进行下一步处理
//将数据库中所的同步通讯录组查找出来
List<String[]> groupList=this.getALLGroup();
if(groupList==null){
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录"+groupName+"组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,查询所有的同步通讯录组发送错误");
return operRes;
}
//创建一个List存放要删除的组和该组下的所有子组的Id
List<String> groupIDList=new ArrayList<String>();
//groupIDList存放所有的要删除的组的ID也就是改组以及其所有子组
groupIDList=findAllChildrenGroupID(groupList, groupIDList, groupID);
Connection conn=null;
PreparedStatement pst=null;
Statement st=null;
try{
conn=DataBaseManage.getInstance().getConnection();
st=conn.createStatement();
conn.setAutoCommit(false);
//count是一个计数器
int count=0;
for(int i=0;i<groupIDList.size();i++){
//当组ID不为空
if(groupIDList.get(i)!=null &&!"".equals(groupIDList.get(i))){
//删除组
String deleteGroupSQL="DELETE FROM t_enterprisebookgroup WHERE GroupID='"+groupIDList.get(i)+"'";
st.addBatch(deleteGroupSQL);
//删除该组下的成员
String deleteContactSQL="DELETE FROM t_enterprisegroupmembers WHERE EnterpriseGroupID='"+groupIDList.get(i)+"'";
st.addBatch(deleteContactSQL);
count++;
}
}
//如果批处理之中有要执行是数据执行批处理操作
if(count>0){
st.executeBatch();
}
conn.commit();
conn.setAutoCommit(true);
Log.getInstance().printInfo(this.getClass().getName(), "删除同步通讯录组"+groupName+"成功");
operRes[0]="1";
operRes[1]="删除同步通讯录组"+groupName+"成功";
operRes[2]="删除同步通讯录组"+groupName+"成功";
return operRes;
}catch(Exception ex){
ExceptionHeading.getException(this.getClass().getName(), ex, "删除同步通讯录组,事务操作执行失败,事务开始回轨");
try{
//事务回轨
conn.rollback();
Log.getInstance().printInfo(this.getClass().getName(), "删除同步通讯录组,事务回轨成功");
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录"+groupName+"组失败";
return operRes;
} catch(Exception e){
//事务回轨失败
ExceptionHeading.getException(this.getClass().getName(), ex, "删除同步通讯录组,事务操作回轨失败");
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录"+groupName+"组失败";
return operRes;
}
} finally{
DataBaseManage.getInstance().closeStatement(pst);
DataBaseManage.getInstance().closeStatement(st);
DataBaseManage.getInstance().releaseConnection(conn);
}
}
java_method_删除事务回滚的更多相关文章
- 【Java EE 学习 19】【使用过滤器实现全站压缩】【使用ThreadLocal模式解决跨DAO事务回滚问题】
一.使用过滤器实现全站压缩 1.目标:对网站的所有JSP页面进行页面压缩,减少用户流量的使用.但是对图片和视频不进行压缩,因为图片和视频的压缩率很小,而且处理所需要的服务器资源很大. 2.实现原理: ...
- mysql数据库 索引 事务和事务回滚
mysql索引 索引相当于书的目录优点:加快数据的查询速度缺点:占物理存储空间,添加,删除,会减慢写的速度 查看表使用的索引 mysql> show index from 表名\G;(\G分行显 ...
- [SQL]事务回滚详解及示例
存储过程中的 SET XACT_ABORT ON 和事务 在存储过程中写SET XACT_ABORT ON 有什么用? SET XACT_ABORT ON是设置事务回滚的! 当为ON时,如果你存储中的 ...
- 为什么mysql事务回滚后, 自增ID依然自增
事务回滚后,自增ID仍然增加,回滚后,自增ID仍然增加.比如当前ID是7,插入一条数据后,又回滚了.然后你再插入一条数据,此时插入成功,这时候你的ID不是8,而是9.因为虽然你之前插入回滚,但是ID还 ...
- springboot 事务回滚
在springboot中,使用事务回滚时,添加@Transactional注解,然后在try-catch块中,发生异常时,在catch中 添加 TransactionAspectSupport.cur ...
- mysql分类和事务回滚
主要内容: ***数据定义语言DDL重点 ***数据操纵语言DML重点 数据查询语言DQL重点 ---事务控制语言TCL ---数据库控制语言DCL ---主键(primary key) ---数据冗 ...
- [转] C# mysql 事务回滚
什么是数据库事务 数据库事务是指作为单个逻辑工作单元执行的一系列操作. 设想网上购物的一次交易,其付款过程至少包括以下几步数据库操作: · 更新客户所购商品的库存信息 · 保存客户付款信息--可能包括 ...
- ThinkPHP实现事务回滚示例代码
ThinkPHP的事务回滚示例如下: ? 1 2 3 4 5 6 7 8 9 10 $m=D('YourModel');//或者是M(); $m2=D('YouModel2'); $m->sta ...
- Spring中@Transactional事务回滚
转载: Spring中@Transactional事务回滚 一.使用场景举例 在了解@Transactional怎么用之前我们必须要先知道@Transactional有什么用.下面举个栗子:比如一个部 ...
随机推荐
- 将现有Ubuntu系统做成LiveCD
制作LiveCD包的工具有不少,其中比较出名的就是UCK和Reconstructor.但是这两个工具都不能把当前的操作系统制成LiveCD,备份当前操作系统,并制成LiveCD的工具也有,比如国人编写 ...
- SVN Working Copy xxx locked 并 cleanup失败之解
从cmd 进入到 workspace文件夹 执行 上边的命令 --------------------------------------------------------------------- ...
- json包的loads dumps区分
符合json格式的字符串 --(json.laods)--> json(字典形式或是列表形式) --(json.dumps)--> 符合json格式的字符串
- 【JS】Intermediate7:jQuery:DOM API
1.jQuery also makes performing actions on many elements at the same time simple 2.eg:$('.note').css( ...
- Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP
题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...
- map的基本操作函数及含义
map的基本操作函数: C++ Maps是一种关联式容器,包含“关键字/值”对 begin() 返回指向map头部的迭代器 clear() ...
- 【OpenCV学习笔记】之六 手写图像旋转函数---万丈高楼平地起
话说,平凡之处显真格,这一点也没错! 比如,对旋转图像进行双线性插值,很简单吧? 可,对我,折腾了大半天,也没有达到预期效果! 尤其是三个误区让我抓瞎好久: 1,坐标旋转公式. 这东西,要用 ...
- 对XML和YAML文件实现I/O操作
1.文件的打开关闭 XML\YAML文件在OpenCV中的数据结构为FileStorage,打开操作例如: string filename = "I.xml"; FileStora ...
- MongoDB--使用修改器修改文档
可以使用修改器啦修改文档,比如增加.删除文档的键值.使用修改器首先要定位到某个文档, 然后再增加相应的修改选项,需要使用update语句 1.$inc修改器修改文档 > db.users.fin ...
- cocos2d-x触摸事件优先级的探究与实践
如何让自定义Layer触发触摸事件? bool LayerXXX::init() { this->setTouchEnabled(true); CCTouchDispatcher* td = C ...