@Override public Collection<Table> getTables(final Schema schema) { return catalog.getTables(schema); }
@Override public Collection<Table> getTables(final Schema schema) { return catalog.getTables(schema); }
@Override public Collection<Table> getTables() { return catalog.getTables(); }
@Override public Collection<Table> getTables() { return catalog.getTables(); }
private List<? extends Table> getSortedTables(final Catalog catalog) { final List<? extends Table> tables = new ArrayList<>(catalog.getTables()); tables.sort(NamedObjectSort .getNamedObjectSort(operationOptions.isAlphabeticalSortForTables())); return tables; }
public CatalogWithAssociations(final Catalog catalog) { super(catalog); final List<Table> allTables = new ArrayList<>(catalog.getTables()); final WeakAssociationsAnalyzer weakAssociationsAnalyzer = new WeakAssociationsAnalyzer(allTables); weakAssociations = weakAssociationsAnalyzer.analyzeTables(); }
@Test public void catalogSerialization(final Connection connection) throws Exception { final SchemaCrawlerOptions schemaCrawlerOptions = DatabaseTestUtility.schemaCrawlerOptionsWithMaximumSchemaInfoLevel; final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); assertThat("Could not obtain catalog", catalog, notNullValue()); assertThat("Could not find any schemas", catalog.getSchemas(), is(not(empty()))); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").orElse(null); assertThat("Could not obtain schema", schema, notNullValue()); assertThat("Unexpected number of tables in the schema", catalog.getTables(schema), hasSize(10)); final Catalog clonedCatalog = SerializationUtils.clone(catalog); assertThat(catalog, equalTo(clonedCatalog)); assertThat("Could not obtain catalog", clonedCatalog, notNullValue()); assertThat("Could not find any schemas", clonedCatalog.getSchemas(), is(not(empty()))); final Schema clonedSchema = clonedCatalog.lookupSchema("PUBLIC.BOOKS") .orElse(null); assertThat("Could not obtain schema", clonedSchema, notNullValue()); assertThat("Unexpected number of tables in the schema", clonedCatalog.getTables(clonedSchema), hasSize(10)); }
final Schema schema1 = new SchemaReference("PUBLIC", "BOOKS"); assertThat("Could not find any tables", catalog.getTables(schema1), not(empty())); assertThat("Wrong number of routines", catalog.getTables(schema1), equalTo(catalog.getTables(schema2))); assertThat("Routines do not match", catalog.getRoutines(schema1), final Table table1 = catalog.getTables(schema1).toArray(new Table[0])[0]; final Table table2 = catalog.getTables(schema1).toArray(new Table[0])[1]; assertThat("Tables should not be equal", table1, not(equalTo(table2)));
@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 triggers(final TestContext testContext, final Connection connection) throws Exception { final Config config = loadHsqldbConfig(); final SchemaRetrievalOptions schemaRetrievalOptions = SchemaRetrievalOptionsBuilder .newSchemaRetrievalOptions(config); final SchemaCrawlerOptions schemaCrawlerOptions = DatabaseTestUtility.schemaCrawlerOptionsWithMaximumSchemaInfoLevel; final Catalog catalog = getCatalog(connection, schemaRetrievalOptions, schemaCrawlerOptions); final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); final Table[] tables = catalog.getTables(schema).toArray(new Table[0]); boolean foundTrigger = false; for (final Table table: tables) { for (final Trigger trigger: table.getTriggers()) { foundTrigger = true; assertThat("Triggers full name does not match", trigger.getFullName(), is("PUBLIC.BOOKS.AUTHORS.TRG_AUTHORS")); assertThat("Trigger EventManipulationType does not match", trigger.getEventManipulationType(), is(EventManipulationType.delete)); } } assertThat("No triggers found", foundTrigger, is(true)); }
@Test public void fkReferences(final Connection connection) throws Exception { final SchemaCrawlerOptions schemaCrawlerOptions = DatabaseTestUtility.schemaCrawlerOptionsWithMaximumSchemaInfoLevel; 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()); assertReferencedColumnExists(catalog, fkColumnRef.getForeignKeyColumn()); fkReferenceCount++; } } } assertThat(fkReferenceCount, is(26)); }
final Table[] tables = catalog.getTables(schema).toArray(new Table[0]); Arrays.sort(tables, NamedObjectSort.alphabetical); for (final Table table: tables)
@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)); }
final Table[] tables = catalog.getTables(schema).toArray(new Table[0]); for (final Table table: tables)
final Table[] tables = catalog.getTables(schema).toArray(new Table[0]); for (final Table table: tables)
@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)); }
final Table[] tables = catalog.getTables().toArray(new Table[0]); assertThat("Table count does not match", tables, arrayWithSize(1)); Arrays.sort(tables, NamedObjectSort.alphabetical);
final Table[] tables = catalog.getTables().toArray(new Table[0]); assertThat("Table count does not match", tables, arrayWithSize(13)); Arrays.sort(tables, NamedObjectSort.alphabetical);
final Collection<Table> tables = catalog.getTables(); for (final Table table: tables)
final Collection<Table> tables = catalog.getTables(); for (final Table table: tables)