|
@@ -18,7 +18,7 @@ public class DatabaseMonitor implements Runnable {
|
|
|
private static final Logger logger = ESPluginLoggerFactory.getLogger(DatabaseMonitor.class.getName());
|
|
|
|
|
|
private static final String JDBC_URL = "jdbc.url";
|
|
|
- private static final String JDBC_USERNAME = "jdbc.username";
|
|
|
+ private static final String JDBC_USERNAME = "jdbc.user";
|
|
|
private static final String JDBC_PASSWORD = "jdbc.password";
|
|
|
private static final String JDBC_DRIVER = "jdbc.driver";
|
|
|
|
|
@@ -78,20 +78,17 @@ public class DatabaseMonitor implements Runnable {
|
|
|
|
|
|
try {
|
|
|
|
|
|
- if (connection == null || statement == null) {
|
|
|
+ connection = DriverManager.getConnection(
|
|
|
+ dbProps.getProperty(JDBC_URL),
|
|
|
+ dbProps.getProperty(JDBC_USERNAME),
|
|
|
+ dbProps.getProperty(JDBC_PASSWORD)
|
|
|
+ );
|
|
|
|
|
|
- connection = DriverManager.getConnection(
|
|
|
- dbProps.getProperty(JDBC_URL),
|
|
|
- dbProps.getProperty(JDBC_USERNAME),
|
|
|
- dbProps.getProperty(JDBC_PASSWORD)
|
|
|
- );
|
|
|
+ statement = connection.createStatement();
|
|
|
|
|
|
- statement = connection.createStatement();
|
|
|
- }
|
|
|
-
|
|
|
- logger.info("获取新词库上一次修改的时间"+lastModified);
|
|
|
+ logger.info("从mysql加载热更新词典上一次修改的时间:"+lastModified);
|
|
|
|
|
|
- String sql = "select *,UNIX_TIMESTAMP(update_time) as version from sys_hot_word where UNIX_TIMESTAMP(update_time) >= "+lastModified;
|
|
|
+ String sql = "select *,UNIX_TIMESTAMP(update_time) as version from sys_hot_word where UNIX_TIMESTAMP(update_time) >"+lastModified;
|
|
|
|
|
|
rs = statement.executeQuery(sql);
|
|
|
|
|
@@ -137,27 +134,50 @@ public class DatabaseMonitor implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- logger.info("获取新词库下一次修改的时间"+lastModified);
|
|
|
-
|
|
|
if(stopWordList.size() > 0){
|
|
|
|
|
|
+ for(String word : stopWordList){
|
|
|
+
|
|
|
+ logger.info("从数据库加载停用词条到主内存词典中->" + word);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
Dictionary.getSingleton().addStopWords(stopWordList);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(mainWordList.size() > 0){
|
|
|
+
|
|
|
+ for(String word : mainWordList){
|
|
|
+
|
|
|
+ logger.info("从数据库加载新词条到主内存词典中->" + word);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
Dictionary.getSingleton().addMainWords(mainWordList);
|
|
|
}
|
|
|
|
|
|
if(disStopWordList.size() > 0){
|
|
|
+
|
|
|
+ for(String word : disStopWordList){
|
|
|
+
|
|
|
+ logger.info("从主内存词典中屏蔽停用词条->" + word);
|
|
|
+
|
|
|
+ }
|
|
|
Dictionary.getSingleton().disableStopWords(disStopWordList);
|
|
|
}
|
|
|
|
|
|
if(disMainWordList.size() > 0){
|
|
|
+
|
|
|
+ for(String word : disMainWordList){
|
|
|
+
|
|
|
+ logger.info("从主内存词典中屏蔽词条->" + word);
|
|
|
+
|
|
|
+ }
|
|
|
Dictionary.getSingleton().disableMainWords(disMainWordList);
|
|
|
}
|
|
|
|
|
|
- logger.info("从mysql加载热更新词典成功!");
|
|
|
+ logger.info("从mysql加载热更新词典下一次修改的时间:"+lastModified);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -165,13 +185,42 @@ public class DatabaseMonitor implements Runnable {
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
- if (rs != null) {
|
|
|
- try {
|
|
|
- rs.close();
|
|
|
- } catch (SQLException e) {
|
|
|
- logger.error("error", e);
|
|
|
- }
|
|
|
+ close(connection, statement,rs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param connection
|
|
|
+ * @param statement
|
|
|
+ * @param resultSet
|
|
|
+ * select 查询关闭发方法:关闭结果集,SQL执行对象,连接对象三个的资源
|
|
|
+ */
|
|
|
+ public void close(Connection connection, Statement statement, ResultSet resultSet){
|
|
|
+
|
|
|
+ if (resultSet != null){
|
|
|
+ try{
|
|
|
+ resultSet.close();
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (statement != null){
|
|
|
+ try{
|
|
|
+ statement.close();
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (connection != null){
|
|
|
+ try{
|
|
|
+ connection.close();
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|