@Override public DataStructureDataAppendModel createAppend(String location, String name, String hash) throws DataStructuresException { DataStructureDataAppendModel dataModel = new DataStructureDataAppendModel(); dataModel.setLocation(location); dataModel.setName(name); dataModel.setType(IDataStructureModel.TYPE_APPEND); dataModel.setHash(hash); dataModel.setCreatedBy(UserFacade.getName()); dataModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); try { Connection connection = null; try { connection = dataSource.getConnection(); appendPersistenceManager.insert(connection, dataModel); return dataModel; } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
/** * Synchronize append. * * @param dataModel * the data model * @throws SynchronizationException * the synchronization exception */ private void synchronizeAppend(DataStructureDataAppendModel dataModel) throws SynchronizationException { try { if (!dataStructuresCoreService.existsAppend(dataModel.getLocation())) { dataStructuresCoreService.createAppend(dataModel.getLocation(), dataModel.getName(), dataModel.getHash()); DATA_STRUCTURE_APPEND_MODELS.put(dataModel.getName(), dataModel); logger.info("Synchronized a new Append Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation()); } else { DataStructureDataAppendModel existing = dataStructuresCoreService.getAppend(dataModel.getLocation()); if (!dataModel.equals(existing)) { dataStructuresCoreService.updateAppend(dataModel.getLocation(), dataModel.getName(), dataModel.getHash()); DATA_STRUCTURE_APPEND_MODELS.put(dataModel.getName(), dataModel); logger.info("Synchronized a modified Append Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation()); } } APPEND_SYNCHRONIZED.add(dataModel.getLocation()); } catch (DataStructuresException e) { throw new SynchronizationException(e); } }
@Override public void updateAppend(String location, String name, String hash) throws DataStructuresException { try { Connection connection = null; try { connection = dataSource.getConnection(); DataStructureDataAppendModel dataModel = getAppend(location); dataModel.setName(name); dataModel.setHash(hash); appendPersistenceManager.update(connection, dataModel); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
/** * Process the data rows in the 'append' mode * * @param model * the model * @throws Exception * in case of database error */ public void executeAppendUpdate(DataStructureDataAppendModel model) throws Exception { logger.info("Processing rows in mode 'append': " + model.getLocation()); String tableName = model.getName(); int tableRowsCount = getTableRowsCount(tableName); if (tableRowsCount == 0) { byte[] content = model.getContent().getBytes(); if (content.length != 0) { TableImporter tableDataInserter = new TableImporter(dataSource, content, tableName); tableDataInserter.insert(); moveSequence(tableName); // move the sequence, to be able to add more records after the initial import } } }
/** * Creates a data model from the raw content. * * @param content * the data definition * @return the data model instance */ public static DataStructureDataAppendModel parseAppend(String location, String content) { DataStructureDataAppendModel result = new DataStructureDataAppendModel(); setContentModelAttributes(location, content, result, IDataStructureModel.TYPE_APPEND); return result; }
if (!APPEND_SYNCHRONIZED.contains(dataModel.getLocation())) { dataStructuresCoreService.removeAppend(dataModel.getLocation()); logger.warn("Cleaned up Append Data file [{}] from location: {}", dataModel.getName(), dataModel.getLocation());
dataModel.setLocation(registryPath); synchronizeAppend(dataModel); return;