@Override public DataStructureDataUpdateModel createUpdate(String location, String name, String hash) throws DataStructuresException { DataStructureDataUpdateModel dataModel = new DataStructureDataUpdateModel(); dataModel.setLocation(location); dataModel.setName(name); dataModel.setType(IDataStructureModel.TYPE_UPDATE); dataModel.setHash(hash); dataModel.setCreatedBy(UserFacade.getName()); dataModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); try { Connection connection = null; try { connection = dataSource.getConnection(); updatePersistenceManager.insert(connection, dataModel); return dataModel; } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
/** * Synchronize update. * * @param dataModel * the data model * @throws SynchronizationException * the synchronization exception */ private void synchronizeUpdate(DataStructureDataUpdateModel dataModel) throws SynchronizationException { try { if (!dataStructuresCoreService.existsUpdate(dataModel.getLocation())) { dataStructuresCoreService.createUpdate(dataModel.getLocation(), dataModel.getName(), dataModel.getHash()); DATA_STRUCTURE_UPDATE_MODELS.put(dataModel.getName(), dataModel); logger.info("Synchronized a new Update Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation()); } else { DataStructureDataUpdateModel existing = dataStructuresCoreService.getUpdate(dataModel.getLocation()); if (!dataModel.equals(existing)) { dataStructuresCoreService.updateUpdate(dataModel.getLocation(), dataModel.getName(), dataModel.getHash()); DATA_STRUCTURE_UPDATE_MODELS.put(dataModel.getName(), dataModel); logger.info("Synchronized a modified Update Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation()); } } UPDATE_SYNCHRONIZED.add(dataModel.getLocation()); } catch (DataStructuresException e) { throw new SynchronizationException(e); } }
/** * Process the data rows in the 'update' mode * * @param model * the model * @throws Exception * in case of database error */ public void executeUpdateUpdate(DataStructureDataUpdateModel model) throws Exception { logger.info("Processing rows in mode 'update': " + model.getLocation()); String tableName = model.getName(); String primaryKey = getPrimaryKey(tableName); byte[] content = model.getContent().getBytes(); updateRowsDataInTable(tableName, primaryKey, content); }
/** * Creates a data model from the raw content. * * @param content * the data definition * @return the data model instance */ public static DataStructureDataUpdateModel parseUpdate(String location, String content) { DataStructureDataUpdateModel result = new DataStructureDataUpdateModel(); setContentModelAttributes(location, content, result, IDataStructureModel.TYPE_UPDATE); return result; }
@Override public void updateUpdate(String location, String name, String hash) throws DataStructuresException { try { Connection connection = null; try { connection = dataSource.getConnection(); DataStructureDataUpdateModel dataModel = getUpdate(location); dataModel.setName(name); dataModel.setHash(hash); updatePersistenceManager.update(connection, dataModel); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
if (!UPDATE_SYNCHRONIZED.contains(dataModel.getLocation())) { dataStructuresCoreService.removeUpdate(dataModel.getLocation()); logger.warn("Cleaned up Update Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation());
dataModel.setLocation(registryPath); synchronizeUpdate(dataModel); return;