@Override public boolean existsSchema(String location) throws DataStructuresException { return getSchema(location) != null; }
@Override public void updateSchema(String location, String name, String hash) throws DataStructuresException { try { Connection connection = null; try { connection = dataSource.getConnection(); DataStructureSchemaModel schemaModel = getSchema(location); schemaModel.setName(name); schemaModel.setHash(hash); schemaPersistenceManager.update(connection, schemaModel); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
/** * Synchronize schema. * * @param schemaModel * the schema model * @throws SynchronizationException * the synchronization exception */ private void synchronizeSchema(DataStructureSchemaModel schemaModel) throws SynchronizationException { try { if (!dataStructuresCoreService.existsSchema(schemaModel.getLocation())) { dataStructuresCoreService.createSchema(schemaModel.getLocation(), schemaModel.getName(), schemaModel.getHash()); DATA_STRUCTURE_SCHEMA_MODELS.put(schemaModel.getName(), schemaModel); addDataStructureModelsFromSchema(schemaModel); logger.info("Synchronized a new Schema file [{}] from location: {}", schemaModel.getName(), schemaModel.getLocation()); } else { DataStructureSchemaModel existing = dataStructuresCoreService.getSchema(schemaModel.getLocation()); if (!schemaModel.equals(existing)) { dataStructuresCoreService.updateSchema(schemaModel.getLocation(), schemaModel.getName(), schemaModel.getHash()); DATA_STRUCTURE_SCHEMA_MODELS.put(schemaModel.getName(), schemaModel); addDataStructureModelsFromSchema(schemaModel); logger.info("Synchronized a modified Schema file [{}] from location: {}", schemaModel.getName(), schemaModel.getLocation()); } } SCHEMA_SYNCHRONIZED.add(schemaModel.getLocation()); } catch (DataStructuresException e) { throw new SynchronizationException(e); } }