@Test @DisplayName("Retrieve tables from data dictionary") public void tablesFromDataDictionary(final TestContext testContext, final Connection connection) throws Exception { final InformationSchemaViews informationSchemaViews = InformationSchemaViewsBuilder.builder() .withSql(InformationSchemaKey.TABLES, "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES") .toOptions(); final SchemaRetrievalOptionsBuilder schemaRetrievalOptionsBuilder = SchemaRetrievalOptionsBuilder.builder(); schemaRetrievalOptionsBuilder .with(tablesRetrievalStrategy, data_dictionary_all) .withInformationSchemaViews(informationSchemaViews); final SchemaRetrievalOptions schemaRetrievalOptions = schemaRetrievalOptionsBuilder.toOptions(); final RetrieverConnection retrieverConnection = new RetrieverConnection(connection, schemaRetrievalOptions); final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions(); final TableRetriever tableRetriever = new TableRetriever(retrieverConnection, catalog, options); tableRetriever.retrieveTables( catalog.getAllSchemas(), "", TableTypes.from("TABLE", "VIEW"), new IncludeAll()); final TestWriter testout = new TestWriter(); try (final TestWriter out = testout) { final Schema[] schemas = ((Catalog) catalog).getSchemas().toArray(new Schema[0]); assertThat("Schema count does not match", schemas, arrayWithSize(5)); for (final Schema schema : schemas) { final Table[] tables = ((Catalog) catalog).getTables(schema).toArray(new Table[0]); Arrays.sort(tables, NamedObjectSort.alphabetical); for (final Table table : tables) { out.println(String.format("%s [%s]", table.getFullName(), table.getTableType())); } } } assertThat( outputOf(testout), hasSameContentAs(classpathResource(testContext.testMethodFullName()))); }
void retrieveTables( final NamedObjectList<SchemaReference> schemas, final String tableNamePattern, final TableTypes tableTypes, final InclusionRule tableInclusionRule) throws SQLException { requireNonNull(schemas, "No schemas provided"); requireNonNull(tableTypes, "No table types provided"); final InclusionRuleFilter<Table> tableFilter = new InclusionRuleFilter<>(tableInclusionRule, false); if (tableFilter.isExcludeAll()) { LOGGER.log(Level.INFO, "Not retrieving tables, since this was not requested"); return; } switch (getRetrieverConnection().get(tablesRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving tables, using fast data dictionary retrieval"); retrieveTablesFromDataDictionary(schemas, tableNamePattern, tableTypes, tableFilter); break; case metadata: LOGGER.log(Level.INFO, "Retrieving tables"); retrieveTablesFromMetadata(schemas, tableNamePattern, tableTypes, tableFilter); break; default: break; } }
TableRetriever extends AbstractRetriever { void retrieveTables( final NamedObjectList<SchemaReference> schemas, final String tableNamePattern, final TableTypes tableTypes, final InclusionRule tableInclusionRule) throws SQLException { requireNonNull(schemas, "No schemas provided"); requireNonNull(tableTypes, "No table types provided"); final InclusionRuleFilter<Table> tableFilter = new InclusionRuleFilter<>(tableInclusionRule, false); if (tableFilter.isExcludeAll()) { LOGGER.log(Level.INFO, "Not retrieving tables, since this was not requested"); return; } switch (getRetrieverConnection().get(tablesRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving tables, using fast data dictionary retrieval"); retrieveTablesFromDataDictionary(schemas, tableNamePattern, tableTypes, tableFilter); break; case metadata: LOGGER.log(Level.INFO, "Retrieving tables"); retrieveTablesFromMetadata(schemas, tableNamePattern, tableTypes, tableFilter); break; default: break; } } }
TableRetriever extends AbstractRetriever { void retrieveTables( final NamedObjectList<SchemaReference> schemas, final String tableNamePattern, final TableTypes tableTypes, final InclusionRule tableInclusionRule) throws SQLException { requireNonNull(schemas, "No schemas provided"); requireNonNull(tableTypes, "No table types provided"); final InclusionRuleFilter<Table> tableFilter = new InclusionRuleFilter<>(tableInclusionRule, false); if (tableFilter.isExcludeAll()) { LOGGER.log(Level.INFO, "Not retrieving tables, since this was not requested"); return; } switch (getRetrieverConnection().get(tablesRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving tables, using fast data dictionary retrieval"); retrieveTablesFromDataDictionary(schemas, tableNamePattern, tableTypes, tableFilter); break; case metadata: LOGGER.log(Level.INFO, "Retrieving tables"); retrieveTablesFromMetadata(schemas, tableNamePattern, tableTypes, tableFilter); break; default: break; } } TableRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options); }
TableRetriever extends AbstractRetriever { void retrieveTables( final NamedObjectList<SchemaReference> schemas, final String tableNamePattern, final TableTypes tableTypes, final InclusionRule tableInclusionRule) throws SQLException { requireNonNull(schemas, "No schemas provided"); requireNonNull(tableTypes, "No table types provided"); final InclusionRuleFilter<Table> tableFilter = new InclusionRuleFilter<>(tableInclusionRule, false); if (tableFilter.isExcludeAll()) { LOGGER.log(Level.INFO, "Not retrieving tables, since this was not requested"); return; } switch (getRetrieverConnection().get(tablesRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving tables, using fast data dictionary retrieval"); retrieveTablesFromDataDictionary(schemas, tableNamePattern, tableTypes, tableFilter); break; case metadata: LOGGER.log(Level.INFO, "Retrieving tables"); retrieveTablesFromMetadata(schemas, tableNamePattern, tableTypes, tableFilter); break; default: break; } } TableRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);  }
TableRetriever extends AbstractRetriever { void retrieveTables( final NamedObjectList<SchemaReference> schemas, final String tableNamePattern, final TableTypes tableTypes, final InclusionRule tableInclusionRule) throws SQLException { requireNonNull(schemas, "No schemas provided"); requireNonNull(tableTypes, "No table types provided"); final InclusionRuleFilter<Table> tableFilter = new InclusionRuleFilter<>(tableInclusionRule, false); if (tableFilter.isExcludeAll()) { LOGGER.log(Level.INFO, "Not retrieving tables, since this was not requested"); return; } switch (getRetrieverConnection().get(tablesRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving tables, using fast data dictionary retrieval"); retrieveTablesFromDataDictionary(schemas, tableNamePattern, tableTypes, tableFilter); break; case metadata: LOGGER.log(Level.INFO, "Retrieving tables"); retrieveTablesFromMetadata(schemas, tableNamePattern, tableTypes, tableFilter); break; default: break; } } TableRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);   }