Search in sources :

Example 1 with DelSecondLevelServiceIPInfoResponse

use of beans.response.DelSecondLevelServiceIPInfoResponse in project MSEC by Tencent.

the class DelSecondLevelServiceIPInfo method exec.

public DelSecondLevelServiceIPInfoResponse exec(DelSecondLevelServiceIPInfoRequest request) {
    DelSecondLevelServiceIPInfoResponse response = new DelSecondLevelServiceIPInfoResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getIpToDel() == null || request.getIpToDel().length == 0) {
        response.setMessage("IP /port to be deleted 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;
    }
    try {
        int total = 0;
        IPPortPair[] ipToDel = request.getIpToDel();
        for (int i = 0; i < ipToDel.length; i++) {
            String sql = "delete from t_second_level_service_ipinfo where ip=? and port=? and status='disabled'";
            List<Object> params = new ArrayList<Object>();
            params.add(ipToDel[i].getIp());
            params.add(ipToDel[i].getPort());
            try {
                int delNum = util.updateByPreparedStatement(sql, params);
                if (delNum > 0) {
                    total += delNum;
                    continue;
                } 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;
            }
        }
        response.setMessage("success");
        response.setDelNumber(total);
        response.setStatus(0);
        return response;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DelSecondLevelServiceIPInfoResponse(beans.response.DelSecondLevelServiceIPInfoResponse)

Aggregations

IPPortPair (beans.request.IPPortPair)1 DelSecondLevelServiceIPInfoResponse (beans.response.DelSecondLevelServiceIPInfoResponse)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DBUtil (ngse.org.DBUtil)1