@Test public void grepColumnsAndIncludeChildTables(final Connection connection) throws Exception { SchemaCrawlerOptions schemaCrawlerOptions = SchemaCrawlerOptionsBuilder .builder() .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS\\..*")) .toOptions(); Catalog catalog; Schema schema; Table table; catalog = getCatalog(connection, schemaCrawlerOptions); schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("Schema PUBLIC.BOOKS not found", schema, notNullValue()); assertThat(catalog.getTables(schema), hasSize(1)); table = catalog.lookupTable(schema, "BOOKAUTHORS").get(); assertThat("Table BOOKAUTHORS not found", table, notNullValue()); schemaCrawlerOptions = SchemaCrawlerOptionsBuilder.builder() .fromOptions(schemaCrawlerOptions).parentTableFilterDepth(1).toOptions(); catalog = getCatalog(connection, schemaCrawlerOptions); schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("Schema PUBLIC.BOOKS not found", schema, notNullValue()); assertThat(catalog.getTables(schema).size(), is(3)); table = catalog.lookupTable(schema, "BOOKAUTHORS").get(); assertThat("Table BOOKAUTHORS not found", table, notNullValue()); table = catalog.lookupTable(schema, "BOOKS").get(); assertThat("Table BOOKS not found", table, notNullValue()); table = catalog.lookupTable(schema, "AUTHORS").get(); assertThat("Table AUTHORS not found", table, notNullValue()); }
@Test public void fkReferencesForGreppedTables1(final Connection connection) throws Exception { final SchemaCrawlerOptions schemaCrawlerOptions = SchemaCrawlerOptionsBuilder .builder() .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS\\..*")) .toOptions(); int fkReferenceCount = 0; final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); final Collection<Table> tables = catalog.getTables(); for (final Table table: tables) { final Collection<ForeignKey> foreignKeys = table.getForeignKeys(); for (final ForeignKey foreignKey: foreignKeys) { for (final ForeignKeyColumnReference fkColumnRef: foreignKey) { assertReferencedColumnDoesNotExist(catalog, fkColumnRef.getPrimaryKeyColumn(), false); assertReferencedColumnExists(catalog, fkColumnRef.getForeignKeyColumn()); fkReferenceCount++; } } } assertThat(fkReferenceCount, is(2)); }
@Test public void fkReferencesForGreppedTables2(final Connection connection) throws Exception { final SchemaCrawlerOptions schemaCrawlerOptions = SchemaCrawlerOptionsBuilder .builder() .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.AUTHORS\\..*")) .toOptions(); int fkReferenceCount = 0; final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); final Collection<Table> tables = catalog.getTables(); for (final Table table: tables) { final Collection<ForeignKey> foreignKeys = table.getForeignKeys(); for (final ForeignKey foreignKey: foreignKeys) { for (final ForeignKeyColumnReference fkColumnRef: foreignKey) { assertReferencedColumnExists(catalog, fkColumnRef.getPrimaryKeyColumn()); assertReferencedColumnDoesNotExist(catalog, fkColumnRef.getForeignKeyColumn(), false); fkReferenceCount++; } } } assertThat(fkReferenceCount, is(1)); }
.includeGreppedColumns(new RegularExpressionInclusionRule(".*\\..*\\.BOOKID")) .toOptions();
.builder() .includeTables(new RegularExpressionInclusionRule(".*\\.AUTHORS")) .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.AUTHORS\\..*")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions();
.includeGreppedColumns(new RegularExpressionInclusionRule(".*\\..*\\.BOOKID")) .includeGreppedDefinitions(new RegularExpressionInclusionRule(".*book author.*")) .toOptions();
.builder() .includeTables(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS")) .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS\\..*")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions();
optionsBuilder.includeGreppedColumns(grepColumnInclusionRule); consumeOption("grepcolumns"); optionsBuilder.includeGreppedColumns(null);
optionsBuilder.includeGreppedColumns(grepColumnInclusionRule); consumeOption("grepcolumns"); optionsBuilder.includeGreppedColumns(null);
optionsBuilder.includeGreppedColumns(grepColumnInclusionRule); consumeOption("grepcolumns"); optionsBuilder.includeGreppedColumns(null);
optionsBuilder.includeGreppedColumns(grepColumnInclusionRule); consumeOption("grepcolumns"); optionsBuilder.includeGreppedColumns(null);