import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
public boolean store() {
System.out.println("Store begin: type = MetricsPaper.");
LOGGER.info("本次更新论文" + Log.getUpdateTotalNumbers().get() + "篇,"
+ "正在更新第" + Log.getCurrentUpdateNumbers().incrementAndGet() + "篇\n"
+ "链接为:" + getUrl());
final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
// 加上选择条件 URL
REF_UPDATE_SQL = REF_UPDATE_SQL + "'" + getUrl() + "'";
try (final Connection connection = mysqlDataSource.getConnection()){
try (final PreparedStatement preparedStatement = connection.prepareStatement(REF_UPDATE_SQL)) {
bindUpdateSql(preparedStatement);
// 判断执行是否成功
boolean succeed = preparedStatement.executeUpdate() != 0;
if (succeed) {
LOGGER.info("当前共有" + getUpdateSucceedNumbers().incrementAndGet() + "篇论文相关指标更新成功...\n"
+ "链接为;" + getUrl());
}else {
LOGGER.info("当前共有" + getUpdateFailedNumbers().incrementAndGet() + "篇论文相关指标更新失败...\n"
+ "链接为;" + getUrl());
}
boolean isSuccess= updateRefDataIntoES();//更新论文指标到ElasticSearch中的REF_DATA
if (!isSuccess){
LOGGER.info("更新论文指标到ElasticSearch中的REF_DATA失败");
}else {
LOGGER.info("更新论文指标到ElasticSearch中的REF_DATA成功");
}
//保存更新的具体数据到数据库中
DBLog.saveUpdateDetailLog(getUrl(),getCurrentUpdateNumbers().get(),getUpdateTotalNumbers().get(),succeed,
DetailCrawler.getUpdateTime());
if (getCurrentUpdateNumbers().get() == getUpdateTotalNumbers().get()) {
LOGGER.info("更新完成,本次更新相关指标论文总量:" +getUpdateTotalNumbers().get()
+ " 成功数:" + getUpdateSucceedNumbers().get()
+ " 失败数:" + getUpdateFailedNumbers());
long startTime= DetailCrawler.getUpdateMillisecond();//开始更新的时间
long endTime=System.currentTimeMillis();//结束更新的时间
long total=endTime-startTime;
String averageTime=Helper.getSeconds(total/getUrlNumbers().get());
//保存更新完成后的总体情况数据到数据库中
DBLog.saveFinalUpdateLog(DetailCrawler.getUpdateTime(),getUpdateSucceedNumbers().get(),
getUpdateFailedNumbers().get(),getUpdateTotalNumbers().get());
}
return succeed;
}
}catch (SQLException e){
e.printStackTrace();
}
return false;
}