Authored by zhangmingm

添加deleteBeforeData方法,删除内存数据库中历史数据。

... ... @@ -6,6 +6,7 @@ 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;
... ... @@ -34,18 +35,34 @@ public class CheckConnectionDao {
/**
* 插入ping结果。
* 插入ping结果。在插入数据之前,删除掉当前时间前1小时的数据,即只保留1小时的数据。
* @param bean
*/
public void addPingConnectionState(ConnectionStateBean bean){
try {
deleteBeforeData();
sqlmapClient.insert("addPingConnectionState", bean);
log.info("******* CheckConnectionDao **** execute method addPingConnectionState ******");
} catch (SQLException e) {
log.error("Exception while addPingConnectionState.",e);
}
}
/**
* 清除TB_CONNECTION_STATE表里1小时前的数据。
*/
public void deleteBeforeData(){
long temp=new Date().getTime()-1000*60*60;
String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp;
log.info("******* deleteBeforeData **** sql["+sql+"]******");
try {
sqlmapClient.delete("deleteBeforeData", sql);
} catch (Exception e) {
log.error("Exception while deleteBeforeData()", e);
}
}
/**
* 根据IP获取该IP对应ping不通的次数。
* @param map
... ...