@Test @DisplayName("Retrieve table definitions from INFORMATION_SCHEMA") public void tableDefinitions(final Connection connection) throws Exception { final String definition = "TEST Table definition"; final InformationSchemaViews informationSchemaViews = InformationSchemaViewsBuilder.builder() .withSql( EXT_TABLES, String.format( "SELECT DISTINCT TABLE_CAT AS TABLE_CATALOG, TABLE_SCHEM AS TABLE_SCHEMA, " + "TABLE_NAME, '%s' AS TABLE_DEFINITION " + "FROM INFORMATION_SCHEMA.SYSTEM_TABLES", definition)) .toOptions(); final SchemaRetrievalOptionsBuilder schemaRetrievalOptionsBuilder = SchemaRetrievalOptionsBuilder.builder(); schemaRetrievalOptionsBuilder.withInformationSchemaViews(informationSchemaViews); final SchemaRetrievalOptions schemaRetrievalOptions = schemaRetrievalOptionsBuilder.toOptions(); final RetrieverConnection retrieverConnection = new RetrieverConnection(connection, schemaRetrievalOptions); final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions(); final TableExtRetriever tableExtRetriever = new TableExtRetriever(retrieverConnection, catalog, options); tableExtRetriever.retrieveTableDefinitions(); final Collection<Table> tables = catalog.getTables(); assertThat(tables, hasSize(19)); for (final Table table : tables) { assertThat(table.getDefinition(), is(definition)); } }
void retrieveTableDefinitions() throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(EXT_TABLES)) { LOGGER.log(Level.INFO, "Not retrieving table definitions, since this was not requested"); LOGGER.log(Level.FINE, "Table definitions SQL statement was not provided"); return; } LOGGER.log(Level.INFO, "Retrieving table definitions"); final Query tableDefinitionsInformationSql = informationSchemaViews.getQuery(EXT_TABLES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet( tableDefinitionsInformationSql, statement, getSchemaInclusionRule())) { while (results.next()) { final String catalogName = normalizeCatalogName(results.getString("TABLE_CATALOG")); final String schemaName = normalizeSchemaName(results.getString("TABLE_SCHEMA")); final String tableName = results.getString("TABLE_NAME"); final Optional<MutableTable> tableOptional = lookupTable(catalogName, schemaName, tableName); if (!tableOptional.isPresent()) { LOGGER.log( Level.FINE, new StringFormat("Cannot find table <%s.%s.%s>", catalogName, schemaName, tableName)); continue; } final MutableTable table = tableOptional.get(); LOGGER.log(Level.FINER, new StringFormat("Retrieving table information <%s>", tableName)); final String definition = results.getString("TABLE_DEFINITION"); table.appendDefinition(definition); table.addAttributes(results.getAttributes()); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve table definitions", e); } }
TableExtRetriever extends AbstractRetriever { void retrieveTableDefinitions() throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(EXT_TABLES)) { LOGGER.log(Level.INFO, "Not retrieving table definitions, since this was not requested"); LOGGER.log(Level.FINE, "Table definitions SQL statement was not provided"); return; } LOGGER.log(Level.INFO, "Retrieving table definitions"); final Query tableDefinitionsInformationSql = informationSchemaViews.getQuery(EXT_TABLES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet( tableDefinitionsInformationSql, statement, getSchemaInclusionRule())) { while (results.next()) { final String catalogName = normalizeCatalogName(results.getString("TABLE_CATALOG")); final String schemaName = normalizeSchemaName(results.getString("TABLE_SCHEMA")); final String tableName = results.getString("TABLE_NAME"); final Optional<MutableTable> tableOptional = lookupTable(catalogName, schemaName, tableName); if (!tableOptional.isPresent()) { LOGGER.log( Level.FINE, new StringFormat("Cannot find table <%s.%s.%s>", catalogName, schemaName, tableName)); continue; } final MutableTable table = tableOptional.get(); LOGGER.log(Level.FINER, new StringFormat("Retrieving table information <%s>", tableName)); final String definition = results.getString("TABLE_DEFINITION"); table.appendDefinition(definition); table.addAttributes(results.getAttributes()); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve table definitions", e); } } }
TableExtRetriever extends AbstractRetriever { void retrieveTableDefinitions() throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(EXT_TABLES)) { LOGGER.log(Level.INFO, "Not retrieving table definitions, since this was not requested"); LOGGER.log(Level.FINE, "Table definitions SQL statement was not provided"); return; } LOGGER.log(Level.INFO, "Retrieving table definitions"); final Query tableDefinitionsInformationSql = informationSchemaViews.getQuery(EXT_TABLES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet( tableDefinitionsInformationSql, statement, getSchemaInclusionRule())) { while (results.next()) { final String catalogName = normalizeCatalogName(results.getString("TABLE_CATALOG")); final String schemaName = normalizeSchemaName(results.getString("TABLE_SCHEMA")); final String tableName = results.getString("TABLE_NAME"); final Optional<MutableTable> tableOptional = lookupTable(catalogName, schemaName, tableName); if (!tableOptional.isPresent()) { LOGGER.log( Level.FINE, new StringFormat("Cannot find table <%s.%s.%s>", catalogName, schemaName, tableName)); continue; } final MutableTable table = tableOptional.get(); LOGGER.log(Level.FINER, new StringFormat("Retrieving table information <%s>", tableName)); final String definition = results.getString("TABLE_DEFINITION"); table.appendDefinition(definition); table.addAttributes(results.getAttributes()); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve table definitions", e); } } TableExtRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options); }
TableExtRetriever extends AbstractRetriever { void retrieveTableDefinitions() throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(EXT_TABLES)) { LOGGER.log(Level.INFO, "Not retrieving table definitions, since this was not requested"); LOGGER.log(Level.FINE, "Table definitions SQL statement was not provided"); return; } LOGGER.log(Level.INFO, "Retrieving table definitions"); final Query tableDefinitionsInformationSql = informationSchemaViews.getQuery(EXT_TABLES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet( tableDefinitionsInformationSql, statement, getSchemaInclusionRule())) { while (results.next()) { final String catalogName = normalizeCatalogName(results.getString("TABLE_CATALOG")); final String schemaName = normalizeSchemaName(results.getString("TABLE_SCHEMA")); final String tableName = results.getString("TABLE_NAME"); final Optional<MutableTable> tableOptional = lookupTable(catalogName, schemaName, tableName); if (!tableOptional.isPresent()) { LOGGER.log( Level.FINE, new StringFormat("Cannot find table <%s.%s.%s>", catalogName, schemaName, tableName)); continue; } final MutableTable table = tableOptional.get(); LOGGER.log(Level.FINER, new StringFormat("Retrieving table information <%s>", tableName)); final String definition = results.getString("TABLE_DEFINITION"); table.appendDefinition(definition); table.addAttributes(results.getAttributes()); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve table definitions", e); } } TableExtRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);  }
TableExtRetriever extends AbstractRetriever { void retrieveTableDefinitions() throws SQLException { final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(EXT_TABLES)) { LOGGER.log(Level.INFO, "Not retrieving table definitions, since this was not requested"); LOGGER.log(Level.FINE, "Table definitions SQL statement was not provided"); return; } LOGGER.log(Level.INFO, "Retrieving table definitions"); final Query tableDefinitionsInformationSql = informationSchemaViews.getQuery(EXT_TABLES); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet( tableDefinitionsInformationSql, statement, getSchemaInclusionRule())) { while (results.next()) { final String catalogName = normalizeCatalogName(results.getString("TABLE_CATALOG")); final String schemaName = normalizeSchemaName(results.getString("TABLE_SCHEMA")); final String tableName = results.getString("TABLE_NAME"); final Optional<MutableTable> tableOptional = lookupTable(catalogName, schemaName, tableName); if (!tableOptional.isPresent()) { LOGGER.log( Level.FINE, new StringFormat("Cannot find table <%s.%s.%s>", catalogName, schemaName, tableName)); continue; } final MutableTable table = tableOptional.get(); LOGGER.log(Level.FINER, new StringFormat("Retrieving table information <%s>", tableName)); final String definition = results.getString("TABLE_DEFINITION"); table.appendDefinition(definition); table.addAttributes(results.getAttributes()); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve table definitions", e); } } TableExtRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);   }