publicString[] 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");returnoperRes;
}//组名称的验证处理
if(groupName==null || "".equals(groupName)) {//如果组名称为空就根据Id数据库中查询
Log.getInstance().printInfo(this.getClass().getName(), "删除同步通讯录组,客户端传递组名称失败,开始从数据库中查询组名称");
List groupNameList=this.getGroupByID(groupID);if(groupNameList==null)
{
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,根据ID查询组名称,数据库连接为null");returnoperRes;
}
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");returnoperRes;
}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或者是空");returnoperRes;
}
}//groupID和groupName都不为空之后进行下一步处理//将数据库中所的同步通讯录组查找出来
List groupList=this.getALLGroup();if(groupList==null){
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录"+groupName+"组失败";
Log.getInstance().printError(this.getClass().getName(),"删除同步通讯录组,查询所有的同步通讯录组发送错误");returnoperRes;
}//创建一个List存放要删除的组和该组下的所有子组的Id
List groupIDList=new ArrayList();//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
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+"成功";returnoperRes;
}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+"组失败";returnoperRes;
}catch(Exception e){//事务回轨失败
ExceptionHeading.getException(this.getClass().getName(), ex, "删除同步通讯录组,事务操作回轨失败");
operRes[0]="3";
operRes[1]="对不起,出现错误,请重试或联系管理员进行处理";
operRes[2]="删除同步通讯录"+groupName+"组失败";returnoperRes;
}
}finally{
DataBaseManage.getInstance().closeStatement(pst);
DataBaseManage.getInstance().closeStatement(st);
DataBaseManage.getInstance().releaseConnection(conn);
}
}