private void addDataStructureModelsFromSchema(DataStructureSchemaModel schemaModel) { for (DataStructureTableModel tableModel : schemaModel.getTables()) { DATA_STRUCTURE_MODELS.put(tableModel.getName(), tableModel); } for (DataStructureViewModel viewModel : schemaModel.getViews()) { DATA_STRUCTURE_MODELS.put(viewModel.getName(), viewModel); } }
/** * Execute the corresponding statement. * * @param connection the connection * @param viewModel the view model * @throws SQLException the SQL exception */ public static void execute(Connection connection, DataStructureViewModel viewModel) throws SQLException { logger.info("Processing Drop View: " + viewModel.getName()); if (SqlFactory.getNative(connection).exists(connection, viewModel.getName())) { String sql = SqlFactory.getNative(connection).drop().view(viewModel.getName()).build(); PreparedStatement statement = connection.prepareStatement(sql); try { logger.info(sql); statement.executeUpdate(); } catch (SQLException e) { logger.error(sql); logger.error(e.getMessage(), e); } finally { if (statement != null) { statement.close(); } } } }
/** * Execute the corresponding statement. * * @param connection the connection * @param viewModel the view model * @throws SQLException the SQL exception */ public static void execute(Connection connection, DataStructureViewModel viewModel) throws SQLException { logger.info("Processing Create View: " + viewModel.getName()); if (!SqlFactory.getNative(connection).exists(connection, viewModel.getName())) { String sql = SqlFactory.getNative(connection).create().view(viewModel.getName()).asSelect(viewModel.getQuery()).build(); PreparedStatement statement = connection.prepareStatement(sql); try { logger.info(sql); statement.executeUpdate(); } catch (SQLException e) { logger.error(sql); logger.error(e.getMessage(), e); } finally { if (statement != null) { statement.close(); } } } }
try { if (!dataStructuresCoreService.existsView(viewModel.getLocation())) { DataStructureViewModel duplicated = dataStructuresCoreService.getViewByName(viewModel.getName()); if (duplicated != null) { throw new SynchronizationException( format("View [{0}] defined by the model at: [{1}] has already been defined by the model at: [{2}]", viewModel.getName(), viewModel.getLocation(), duplicated.getLocation())); dataStructuresCoreService.createView(viewModel.getLocation(), viewModel.getName(), viewModel.getHash()); DATA_STRUCTURE_MODELS.put(viewModel.getName(), viewModel); logger.info("Synchronized a new View [{}] from location: {}", viewModel.getName(), viewModel.getLocation()); } else { DataStructureViewModel existing = dataStructuresCoreService.getView(viewModel.getLocation()); if (!viewModel.equals(existing)) { dataStructuresCoreService.updateView(viewModel.getLocation(), viewModel.getName(), viewModel.getHash()); DATA_STRUCTURE_MODELS.put(viewModel.getName(), viewModel); logger.info("Synchronized a modified View [{}] from location: {}", viewModel.getName(), viewModel.getLocation());
dataStructuresCoreService.removeView(viewModel.getLocation()); executeViewDrop(connection, viewModel); logger.warn("Cleaned up View [{}] from location: {}", viewModel.getName(), viewModel.getLocation());