我有一个MongoDB数据库,其中有一个文档Connection,其中保存了MySQL url,用户和密码,查询,结果以及刷新时间。 对于“连接”文档中的每个元素,我创建一个Quartz Job,在其中将Quartz刷新时间设置为数据库元素的刷新时间值。 此Job将执行数据库元素的查询,并将结果设置为查询的结果,这是为了始终使结果保持最新信息。 现在的问题是,有时有效,有时无效。有时它会正确刷新所有数据库元素,但有时它不刷新某些元素。 我的代码如下所示:
try {
Configuration grafica = mapper.convertvalue(objeto,Configuration.class);
System.out.println("actualizare la " + representacion + " con Id " + grafica.getId() + " correspondiente a la " +
fuenteDeDatos + " con Id " + conexion.getId());
String info = database(
"mysql",conexion.getconnectionUrl(),conexion.getusername(),conexion.getPassword(),grafica.getQuery());
JSONArray arreglo = new JSONArray(info);
BasicDBObject resultado = new BasicDBObject();
for (Object object: arreglo) {
JSONObject jsonObject = new JSONObject(object.toString());
resultado.put(jsonObject.get("name").toString(),new BasicDBObject(jsonObject.toMap()));
}
grafica.setResult(resultado);
List < Dashboard > dashboards = dashboardRepository.findAll();
for (Dashboard dashboard: dashboards) {
for (Tab tab: dashboard.getTabs()) {
for (Object object: tab.getObjects()) {
Map < String,Object > map = mapper.convertvalue(object,Map.class);
if (Long.parseLong(map.get("objetoId").toString()) == grafica.getId()) {
map.put("result",resultado);
}
}
}
dashboardRepository.save(dashboard);
}
} catch (Exception e) {
Configuration grafica = mapper.convertvalue(objeto,Configuration.class);
System.out.println("-------------------------------------");
System.out.println("HUBO UN PROBLEMA EN LA " + representacion + " con Id " + conexion.getId() +
" de la " + fuenteDeDatos + " CON ID " + grafica.getId());
System.out.println(e);
System.out.println("-------------------------------------");
} finally {
connectionRepository.save(conexion);
}
首先,我更新了数据库的一个文档的所有元素,这很好,但是随后我迭代List<Dashoboard> dashboards
时,在每次迭代的最后,我保存了更新的结果,有时可以工作,有时不可以。