public static SchemaCrawlerOptions newSchemaCrawlerOptions() { return builder().toOptions(); }
public static SchemaCrawlerOptions newSchemaCrawlerOptions() { return builder().toOptions(); }
@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")); }
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.detailed()) .includeAllRoutines(); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
@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)); }
public static void main(final String[] args) throws Exception { // Turn application logging on by applying the correct log level applyApplicationLogLevel(Level.OFF); // Log system properties and classpath logSystemProperties(); logSystemClasspath(); // Create the options final SchemaCrawlerOptionsBuilder optionsBuilder = SchemaCrawlerOptionsBuilder .builder() // Set what details are required in the schema - this affects the // time taken to crawl the schema .withSchemaInfoLevel(SchemaInfoLevelBuilder.standard()) .includeSchemas(new RegularExpressionInclusionRule("PUBLIC.BOOKS")); final SchemaCrawlerOptions options = optionsBuilder.toOptions(); final Path outputFile = getOutputFile(args); final OutputOptions outputOptions = OutputOptionsBuilder .newOutputOptions(TextOutputFormat.html, outputFile); final String command = "schema"; final SchemaCrawlerExecutable executable = new SchemaCrawlerExecutable(command); executable.setSchemaCrawlerOptions(options); executable.setOutputOptions(outputOptions); executable.setConnection(getConnection()); executable.execute(); System.out.println("Created output file, " + outputFile); }
@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)); } }
private Path createDiagram(final Connection connection, final String extension) throws Exception { checkConnection(connection); final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder .builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.standard()) .includeRoutines(new ExcludeAll()); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions(); final Path diagramFile = createTempFilePath("schemacrawler", extension); final OutputOptions outputOptions = OutputOptionsBuilder .newOutputOptions(extension, diagramFile); final SchemaCrawlerExecutable executable = new SchemaCrawlerExecutable("schema"); executable.setSchemaCrawlerOptions(schemaCrawlerOptions); executable.setOutputOptions(outputOptions); executable.setConnection(connection); executable.execute(); return diagramFile; }
.builder().tableNamePattern(tableNamePattern); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder .toOptions();
.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()) .includeAllRoutines(); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
@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)); }
.builder() .includeSchemas(new RegularExpressionExclusionRule(".*\\.FOR_LINT")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder() .includeTables(new RegularExpressionInclusionRule(".*\\.AUTHORS")); final SchemaCrawlerOptions schemaCrawlerOptions = schemaCrawlerOptionsBuilder
.builder() .includeTables(new RegularExpressionInclusionRule(".*\\.AUTHORS")) .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.AUTHORS\\..*"));
.builder() .includeTables(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS")) .includeGreppedColumns(new RegularExpressionInclusionRule(".*\\.BOOKAUTHORS\\..*"));
public SchemaCrawlerOptionsParser(final Config config) { super(config); normalizeOptionName("title"); normalizeOptionName("infolevel", "i"); normalizeOptionName("schemas"); normalizeOptionName("tabletypes"); normalizeOptionName("tables"); normalizeOptionName("excludecolumns"); normalizeOptionName("synonyms"); normalizeOptionName("sequences"); normalizeOptionName("routinetypes"); normalizeOptionName("routines"); normalizeOptionName("excludeinout"); normalizeOptionName("grepcolumns"); normalizeOptionName("grepinout"); normalizeOptionName("grepdef"); normalizeOptionName("invert-match"); normalizeOptionName("only-matching"); normalizeOptionName("noemptytables", "hideemptytables"); normalizeOptionName("parents"); normalizeOptionName("children"); optionsBuilder = SchemaCrawlerOptionsBuilder.builder().fromConfig(config); }
public SchemaCrawlerOptionsParser(final Config config) { super(config); normalizeOptionName("title"); normalizeOptionName("infolevel", "i"); normalizeOptionName("schemas"); normalizeOptionName("tabletypes"); normalizeOptionName("tables"); normalizeOptionName("excludecolumns"); normalizeOptionName("synonyms"); normalizeOptionName("sequences"); normalizeOptionName("routinetypes"); normalizeOptionName("routines"); normalizeOptionName("excludeinout"); normalizeOptionName("grepcolumns"); normalizeOptionName("grepinout"); normalizeOptionName("grepdef"); normalizeOptionName("invert-match"); normalizeOptionName("only-matching"); normalizeOptionName("noemptytables", "hideemptytables"); normalizeOptionName("parents"); normalizeOptionName("children"); optionsBuilder = SchemaCrawlerOptionsBuilder.builder().fromConfig(config); }