CheckConnectionDao.java
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.sitech.ismp.check.downtime;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.sitech.util.SqlMapFactory;
import org.apache.log4j.Logger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/**
* @author frank zmm@honggroup.com.cn
* @Description: 检查主机,数据库,中间件的连接状态dao.
* @Package com.sitech.ismp.check.downtime
* @ClassName: com.sitech.ismp.check.downtime.CheckConnectionDao
* @date 2017年04月22日 15:05
*/
public class CheckConnectionDao {
protected static SqlMapClient sqlmapClient;
protected static SqlMapClient oracleSqlMapClient ;
/**
* 因为继承 basedao 后,报basedao 找不到,因此写到方法里面。
*/
static {
sqlmapClient = SqlMapFactory.getDefaultSqlMapClient();
oracleSqlMapClient= SqlMapFactory.getOracleSqlMapClient("oracle_sqlmap.xml");
}
private static Logger log=Logger.getLogger(CheckConnectionDao.class);
/**
* 插入ping结果。在插入数据之前,删除掉当前时间前30分钟的数据,即只保留30分钟的数据。
* @param bean
*/
public void addPingConnectionState(ConnectionStateBean bean){
try {
deleteBeforeData();
sqlmapClient.insert("addPingConnectionState", bean);
} catch (SQLException e) {
log.error("Exception while addPingConnectionState.",e);
}
}
/**
* 清除TB_CONNECTION_STATE表里30分钟前的数据。
*/
public void deleteBeforeData(){
long temp=new Date().getTime()-1000*60*30;
String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp;
try {
sqlmapClient.delete("deleteBeforeData", sql);
} catch (Exception e) {
log.error("Exception while deleteBeforeData()", e);
}
}
/**
* 根据IP获取该IP对应ping不通的次数。
* @param map
* @return
*/
public List<ConnectionStateBean> getStatByParam(HashMap<String, Object> map){
List<ConnectionStateBean> beanList=new ArrayList<ConnectionStateBean>();
try {
beanList=sqlmapClient.queryForList("getStatByParam", map);
} catch (SQLException e) {
e.printStackTrace();
}
return beanList;
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param sql
* @return
*/
public String getPingResultByIp(String sql){
List<ConnectionStateBean> beanList=new ArrayList<ConnectionStateBean>();
try {
beanList=sqlmapClient.queryForList("getPingResultByIp", sql);
} catch (SQLException e) {
e.printStackTrace();
}
String result="";
log.info("&&&&&&&& beanList.size()="+beanList.size()+" &&&&&&&&&&&&&&&&&&&&&&");
if(null !=beanList && beanList.size()>0){
ConnectionStateBean bean=beanList.get(0);
log.info("&&&&&&&& ConnectionStateBean ="+bean.toString()+" &&&&&&&&&&&&&&&&&&&&&&");
result=bean.getDEVICE_STATE();
}
return result;
}
}