use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelLibraryFile method exec.
public DelLibraryFileResponse exec(LibraryFile request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelLibraryFileResponse response = new DelLibraryFileResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getFile_name() == null || request.getFile_name().equals("") || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().equals("") || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().equals("")) {
response.setMessage("file name and service name should NOT be empty.");
response.setStatus(100);
return response;
}
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
response.setMessage("DB connect failed.");
response.setStatus(100);
return response;
}
String sql = "delete from t_library_file where file_name=? and first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(request.getFile_name());
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
try {
int delNum = util.updateByPreparedStatement(sql, params);
String filename = LibraryFile.getLibraryFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getFile_name());
logger.error("delte file:" + filename);
RemoveFile(filename);
if (delNum > 0) {
response.setMessage("success");
response.setDelNumber(delNum);
response.setStatus(0);
return response;
} else {
response.setMessage("delete record number is " + delNum);
response.setDelNumber(delNum);
response.setStatus(100);
return response;
}
} catch (SQLException e) {
response.setMessage("Delete record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelOddSecondLevelServiceIPInfo method deleteAll.
public static String deleteAll(String flsn, String slsn) {
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
return "DB connect failed.";
}
String sql = "delete from t_second_level_service_ipinfo where " + "first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(flsn);
params.add(slsn);
try {
int delNum = util.updateByPreparedStatement(sql, params);
return "success";
} catch (SQLException e) {
e.printStackTrace();
return e.getMessage();
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class LibrarayFileUpload method insertTable.
private String insertTable(String firstName, String secondName, String baseFileName, String memo) {
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
return "DB connect failed.";
}
String sql;
List<Object> params = new ArrayList<Object>();
sql = "insert into t_library_file(first_level_service_name, second_level_service_name,file_name, memo) values(?,?,?,?)";
params.add(firstName);
params.add(secondName);
params.add(baseFileName);
params.add(memo);
try {
int addNum = util.updateByPreparedStatement(sql, params);
if (addNum >= 0) {
return "success";
}
return "insert failed";
} catch (SQLException e) {
return "insert failed";
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class AddAlarmSetting method initMonitorIPAndPort.
public static void initMonitorIPAndPort() throws Exception {
DBUtil util = new DBUtil();
Logger logger = Logger.getLogger(MonitorBySvcOrIP.class);
try {
if (util.getConnection() == null) {
Exception e = new Exception("connect db failed.");
throw e;
}
String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='monitor' and " + "first_level_service_name='RESERVED' and status='enabled'";
ArrayList<OddSecondLevelServiceIPInfo> list = util.findMoreRefResult(sql, null, OddSecondLevelServiceIPInfo.class);
if (list == null || list.size() < 1) {
throw new Exception("no db record exists.");
}
monitor_server_ip = list.get(0).getIp();
//为什么加1,是个很长的故事,源于monitor的开发者将读写分离成两个端口
monitor_server_port = list.get(0).getPort().intValue() + 1;
logger.info(String.format("monitor server:%s:%d", monitor_server_ip, monitor_server_port));
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelSecondLevelServiceConfigTag method deleteAll.
public static String deleteAll(String flsn, String slsn) {
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
return "DB connect failed.";
}
try {
String sql = "select tag_name from t_config_tag where first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(flsn);
params.add(slsn);
ArrayList<SecondLevelServiceConfigTag> result = util.findMoreRefResult(sql, params, SecondLevelServiceConfigTag.class);
for (int i = 0; i < result.size(); i++) {
String tag_name = result.get(i).getTag_name();
sql = "delete from t_config_tag where tag_name=? and first_level_service_name=? and second_level_service_name=?";
params = new ArrayList<Object>();
params.add(tag_name);
params.add(flsn);
params.add(slsn);
//删除数据库记录
int delNum = util.updateByPreparedStatement(sql, params);
String filename = SecondLevelServiceConfigTag.getConfigFileName(flsn, slsn, tag_name);
RemoveFile(filename);
}
return "success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
} finally {
util.releaseConn();
}
}
Aggregations