@Override public Optional<? extends Schema> lookupSchema(final String name) { return catalog.lookupSchema(name); }
@Override public Optional<? extends Schema> lookupSchema(final String name) { return catalog.lookupSchema(name); }
@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)); }
@Test public void columnLookup(final TestContext testContext, final Connection connection) throws Exception { final SchemaCrawlerOptions schemaCrawlerOptions = SchemaCrawlerOptionsBuilder .newSchemaCrawlerOptions(); final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); assertThat(catalog, notNullValue()); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat(schema, notNullValue()); final Table table = catalog.lookupTable(schema, "AUTHORS").get(); assertThat(table, notNullValue()); assertThat(table.lookupColumn(null), is(emptyOptional())); assertThat(table.lookupColumn(""), is(emptyOptional())); assertThat(table.lookupColumn("NO_COLUMN"), is(emptyOptional())); assertThat(table.lookupColumn("ID"), is(not(emptyOptional()))); }
@Test public void tableUtilities(final TestContext testContext, final Connection connection) throws Exception { final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder .builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions(); final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("BOOKS Schema not found", schema, notNullValue()); final Table table = catalog.lookupTable(schema, "BOOKS").get(); assertThat("BOOKS Table not found", table, notNullValue()); assertThat(MetaDataUtility.allIndexCoumnNames(table).stream() .flatMap(List::stream).collect(Collectors.toSet()), containsInAnyOrder("PUBLIC.BOOKS.BOOKS.ID", "PUBLIC.BOOKS.BOOKS.PREVIOUSEDITIONID")); assertThat(MetaDataUtility.uniqueIndexCoumnNames(table).stream() .flatMap(List::stream).collect(Collectors.toSet()), containsInAnyOrder("PUBLIC.BOOKS.BOOKS.ID", "PUBLIC.BOOKS.BOOKS.PREVIOUSEDITIONID")); final Index index = table.getIndexes().toArray(new Index[0])[0]; assertThat("Index not found", index, notNullValue()); assertThat(MetaDataUtility.columnNames(index), containsInAnyOrder("PUBLIC.BOOKS.BOOKS.ID")); assertThat(MetaDataUtility.containsGeneratedColumns(index), is(false)); }
@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 fkUtilities(final TestContext testContext, final Connection connection) throws Exception { final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder .builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions(); final Catalog catalog = getCatalog(connection, schemaCrawlerOptions); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("BOOKS Schema not found", schema, notNullValue()); final Table table = catalog.lookupTable(schema, "BOOKS").get(); assertThat("BOOKS Table not found", table, notNullValue()); final ForeignKey fk = table.getForeignKeys().toArray(new ForeignKey[0])[0]; assertThat("Foreign key not found", fk, notNullValue()); final ColumnReference columnReference = fk.getColumnReferences() .toArray(new ColumnReference[0])[0]; assertThat("Column reference not found", columnReference, notNullValue()); assertThat(MetaDataUtility .constructForeignKeyName(columnReference.getForeignKeyColumn(), columnReference.getPrimaryKeyColumn()), is("SC_AA4376_AFD2BA21")); assertThat(MetaDataUtility.findForeignKeyCardinality(fk), is(ForeignKeyCardinality.zero_many)); assertThat(MetaDataUtility.foreignKeyColumnNames(fk), containsInAnyOrder("PUBLIC.BOOKS.BOOKAUTHORS.BOOKID")); }
@Override public Optional<? extends Schema> lookupSchema(final String name) { return catalog.lookupSchema(name); }
@Override public Optional<? extends Schema> lookupSchema(final String name) { return catalog.lookupSchema(name); }
schemaRetrievalOptions, schemaCrawlerOptions); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("BOOKS Schema not found", schema, notNullValue()); final Synonym[] synonyms = catalog.getSynonyms(schema)
schemaRetrievalOptions, schemaCrawlerOptions); final Schema schema = catalog.lookupSchema("PUBLIC.BOOKS").get(); assertThat("BOOKS Schema not found", schema, notNullValue()); final Sequence[] sequences = catalog.getSequences(schema)