public static Connection checkConnection(final Connection connection) throws SchemaCrawlerSQLException { try { requireNonNull(connection, "No connection provided"); if (connection.isClosed()) { throw new SQLException("Connection is closed"); } } catch (final NullPointerException | SQLException e) { throw new SchemaCrawlerSQLException("Bad database connection", e); } return connection; }
public static Connection checkConnection(final Connection connection) throws SchemaCrawlerSQLException { try { requireNonNull(connection, "No connection provided"); if (connection.isClosed()) { throw new SQLException("Connection is closed"); } } catch (final NullPointerException | SQLException e) { throw new SchemaCrawlerSQLException("Bad database connection", e); } return connection; }
public static ResultSet checkResultSet(final ResultSet resultSet) throws SchemaCrawlerSQLException { try { requireNonNull(resultSet, "No result-set provided"); if (resultSet.isClosed()) { throw new SQLException("Result-set is closed"); } } catch (final NullPointerException | SQLException e) { throw new SchemaCrawlerSQLException("Bad result-set", e); } return resultSet; }
public static ResultSet checkResultSet(final ResultSet resultSet) throws SchemaCrawlerSQLException { try { requireNonNull(resultSet, "No result-set provided"); if (resultSet.isClosed()) { throw new SQLException("Result-set is closed"); } } catch (final NullPointerException | SQLException e) { throw new SchemaCrawlerSQLException("Bad result-set", e); } return resultSet; }
private final Driver getJdbcDriver(final String connectionUrl) throws SQLException { try { return DriverManager.getDriver(connectionUrl); } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not find a suitable JDBC driver for database connection URL, " + getConnectionUrl(), e); } }
private void retrievePrimaryKeysFromMetadataForAllTables(final NamedObjectList<MutableTable> allTables) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getPrimaryKeys(null, null, "%"));) { while (results.next()) { final Optional<MutableTable> optionalTable = lookupTable(allTables, results); if (!optionalTable.isPresent()) { continue; } final MutableTable table = optionalTable.get(); createPrimaryKeyForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve primary keys for tables", e); } }
private void retrievePrimaryKeysFromMetadataForAllTables(final NamedObjectList<MutableTable> allTables) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getPrimaryKeys(null, null, "%"));) { while (results.next()) { final Optional<MutableTable> optionalTable = lookupTable(allTables, results); if (!optionalTable.isPresent()) { continue; } final MutableTable table = optionalTable.get(); createPrimaryKeyForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve primary keys for tables", e); } }
private void retrieveIndexesFromMetadataForAllTables(final NamedObjectList<MutableTable> allTables, final boolean unique) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getIndexInfo(null, null, "%", unique, true/* approximate */));) { while (results.next()) { final Optional<MutableTable> optionalTable = lookupTable(allTables, results); if (!optionalTable.isPresent()) { continue; } final MutableTable table = optionalTable.get(); createIndexForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve indexes for tables", e); } }
private void retrieveIndexesFromMetadataForAllTables(final NamedObjectList<MutableTable> allTables, final boolean unique) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getIndexInfo(null, null, "%", unique, true/* approximate */));) { while (results.next()) { final Optional<MutableTable> optionalTable = lookupTable(allTables, results); if (!optionalTable.isPresent()) { continue; } final MutableTable table = optionalTable.get(); createIndexForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve indexes for tables", e); } }
private void retrieveIndexesFromMetadata(final MutableTable table, final boolean unique) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getIndexInfo(table.getSchema().getCatalogName(), table.getSchema().getName(), table.getName(), unique, true/* approximate */));) { createIndexes(table, results); } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve indexes for table " + table, e); } }
private void retrieveIndexesFromMetadata(final MutableTable table, final boolean unique) throws SQLException { try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getIndexInfo(table.getSchema().getCatalogName(), table.getSchema().getName(), table.getName(), unique, true/* approximate */));) { createIndexes(table, results); } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve indexes for table " + table, e); } }
private void retrievePrimaryKeysFromMetadata(final NamedObjectList<MutableTable> allTables) throws SQLException { for (final MutableTable table: allTables) { if (table instanceof View) { continue; } try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getPrimaryKeys(table.getSchema().getCatalogName(), table.getSchema().getName(), table.getName()));) { while (results.next()) { createPrimaryKeyForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve primary keys for table " + table, e); } } }
private void retrievePrimaryKeysFromMetadata(final NamedObjectList<MutableTable> allTables) throws SQLException { for (final MutableTable table: allTables) { if (table instanceof View) { continue; } try (final MetadataResultSet results = new MetadataResultSet(getMetaData() .getPrimaryKeys(table.getSchema().getCatalogName(), table.getSchema().getName(), table.getName()));) { while (results.next()) { createPrimaryKeyForTable(table, results); } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve primary keys for table " + table, e); } } }
private void retrieveTableColumnsFromDataDictionary(final NamedObjectList<MutableTable> allTables, final InclusionRuleFilter<Column> columnFilter, final Set<List<String>> hiddenColumns) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(InformationSchemaKey.TABLE_COLUMNS)) { throw new SchemaCrawlerSQLException("No table columns SQL provided", null); } final Query tableColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.TABLE_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(tableColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveTableColumnsFromDataDictionary"); while (results.next()) { createTableColumn(results, allTables, columnFilter, hiddenColumns); } } }
private void retrieveProcedureColumnsFromDataDictionary(final NamedObjectList<MutableRoutine> allRoutines, final InclusionRuleFilter<ProcedureColumn> columnFilter) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews .hasQuery(InformationSchemaKey.PROCEDURE_COLUMNS)) { throw new SchemaCrawlerSQLException("No procedure columns SQL provided", null); } final Query procedureColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.PROCEDURE_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(procedureColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveProcedureColumnsFromDataDictionary"); while (results.next()) { createProcedureColumn(results, allRoutines, columnFilter); } } }
private void retrieveFunctionColumnsFromDataDictionary(final NamedObjectList<MutableRoutine> allRoutines, final InclusionRuleFilter<FunctionColumn> columnFilter) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(InformationSchemaKey.FUNCTION_COLUMNS)) { throw new SchemaCrawlerSQLException("No function columns SQL provided", null); } final Query functionColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.FUNCTION_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(functionColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveFunctionColumnsFromDataDictionary"); while (results.next()) { createFunctionColumn(results, allRoutines, columnFilter); } } }
private void retrieveFunctionColumnsFromDataDictionary(final NamedObjectList<MutableRoutine> allRoutines, final InclusionRuleFilter<FunctionColumn> columnFilter) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(InformationSchemaKey.FUNCTION_COLUMNS)) { throw new SchemaCrawlerSQLException("No function columns SQL provided", null); } final Query functionColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.FUNCTION_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(functionColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveFunctionColumnsFromDataDictionary"); while (results.next()) { createFunctionColumn(results, allRoutines, columnFilter); } } }
private void retrieveTableColumnsFromDataDictionary(final NamedObjectList<MutableTable> allTables, final InclusionRuleFilter<Column> columnFilter, final Set<List<String>> hiddenColumns) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(InformationSchemaKey.TABLE_COLUMNS)) { throw new SchemaCrawlerSQLException("No table columns SQL provided", null); } final Query tableColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.TABLE_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(tableColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveTableColumnsFromDataDictionary"); while (results.next()) { createTableColumn(results, allTables, columnFilter, hiddenColumns); } } }
private void retrieveProcedureColumnsFromDataDictionary(final NamedObjectList<MutableRoutine> allRoutines, final InclusionRuleFilter<ProcedureColumn> columnFilter) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews .hasQuery(InformationSchemaKey.PROCEDURE_COLUMNS)) { throw new SchemaCrawlerSQLException("No procedure columns SQL provided", null); } final Query procedureColumnsSql = informationSchemaViews .getQuery(InformationSchemaKey.PROCEDURE_COLUMNS); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(procedureColumnsSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveProcedureColumnsFromDataDictionary"); while (results.next()) { createProcedureColumn(results, allRoutines, columnFilter); } } }
private void retrieveProceduresFromDataDictionary(final NamedObjectList<SchemaReference> schemas, final InclusionRuleFilter<Procedure> procedureFilter) throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection() .getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(InformationSchemaKey.PROCEDURES)) { throw new SchemaCrawlerSQLException("No procedures SQL provided", null); } final Query proceduresSql = informationSchemaViews .getQuery(InformationSchemaKey.PROCEDURES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(proceduresSql, statement, getSchemaInclusionRule());) { results.setDescription("retrieveProceduresFromDataDictionary"); int numProcedures = 0; while (results.next()) { numProcedures = numProcedures + 1; createProcedure(results, schemas, procedureFilter); } LOGGER.log(Level.INFO, new StringFormat("Processed %d procedures", numProcedures)); } }