日期:2014-05-20 浏览次数:20913 次
Byte mainsrv = as.getIsDomainSrv();
List<AccessServer> serverList = serverDao.findAll();
if(serverList != null){
for(AccessServer server : serverList){
if(server.getServerIp().equals(as.getServerIp())){
System.out.println("要添加的服务器已存在");
oplogmgr.add(as.getServerIp(), 21, 1, as.getServerName(), 10);
return -10; //返回一个特殊类型的错误代码
}
if ( (mainsrv.intValue() == 1) && (server.getIsDomainSrv().intValue() == 1) ){
System.out.println("已经存在主服务器");
oplogmgr.add(as.getServerIp(), 21, 1, as.getServerName(), 11);
return -11;
}
}
}
if (mainsrv.intValue() == 0 && countSelectServer().compareTo(getUkeyServerNumber()) >= 0) {
System.out.println("ukey限制添加服务器");
oplogmgr.add(as.getServerIp(), 21, 1, null, ErrorCode.UKEYDENEY);
return ErrorCode.UKEYDENEY;
}
Session session=null;
Transaction tx=null;
try{
session = serverDao.getSessionFactory().openSession();
tx=session.beginTransaction();
session.save(as);
tx.commit();
}
catch (RuntimeException e) {
e.printStackTrace();
if (tx != null){
tx.rollback();
}
}
finally{
if(session!=null){
session.close();
}
}
oplogmgr.add(as.getServerIp(), 21, 1, as.getServerName(), 0);