@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 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")); }
@Test public void viewDefinitions(final TestContext testContext, final Connection connection) throws Exception { final Config config = loadHsqldbConfig(); final SchemaRetrievalOptions schemaRetrievalOptions = SchemaRetrievalOptionsBuilder .newSchemaRetrievalOptions(config); final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder .builder(); schemaCrawlerOptionsBuilder.tableTypes("VIEW"); schemaCrawlerOptionsBuilder .withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()); final Catalog catalog = getCatalog(connection, schemaRetrievalOptions, schemaCrawlerOptionsBuilder.toOptions()); final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); final View view = (View) catalog.lookupTable(schema, "AUTHORSLIST").get(); assertThat("View not found", view, notNullValue()); assertThat("View definition not found", view.getDefinition(), notNullValue()); assertThat("View definition not found", isBlank(view.getDefinition()), is(false)); }
@Test public void routineDefinitions(final TestContext testContext, final Connection connection) throws Exception { final Config config = loadHsqldbConfig(); final SchemaRetrievalOptions schemaRetrievalOptions = SchemaRetrievalOptionsBuilder .newSchemaRetrievalOptions(config); final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder .builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeAllRoutines(); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions(); final Catalog catalog = getCatalog(connection, schemaRetrievalOptions, schemaCrawlerOptions); final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); final Routine[] routines = catalog.getRoutines(schema) .toArray(new Routine[0]); assertThat("Wrong number of routines", routines, arrayWithSize(4)); for (final Routine routine: routines) { assertThat("Routine definition not found, for " + routine, isBlank(routine.getDefinition()), is(false)); } }
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeAllRoutines(); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeSchemas(new RegularExpressionExclusionRule(".*\\.FOR_LINT")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeAllRoutines(); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeSchemas(new RegularExpressionExclusionRule(".*\\.FOR_LINT")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeSchemas(new RegularExpressionExclusionRule(".*\\.FOR_LINT")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder