/** * {@inheritDoc} */ @Override public Optional<MutableColumnDataType> lookupSystemColumnDataType(final String name) { return lookupColumnDataType(new SchemaReference(), name); }
/** * {@inheritDoc} */ @Override public Collection<ColumnDataType> getSystemColumnDataTypes() { return getColumnDataTypes(new SchemaReference()); }
/** * {@inheritDoc} */ @Override public Collection<ColumnDataType> getSystemColumnDataTypes() { return getColumnDataTypes(new SchemaReference()); }
/** * {@inheritDoc} */ @Override public Optional<MutableColumnDataType> lookupSystemColumnDataType(final String name) { return lookupColumnDataType(new SchemaReference(), name); }
Schema addSchema(final String catalogName, final String schemaName) { return addSchema(new SchemaReference(catalogName, schemaName)); }
Schema addSchema(final String catalogName, final String schemaName) { return addSchema(new SchemaReference(catalogName, schemaName)); }
MutableColumnDataType lookupColumnDataTypeByType(final int type) { final SchemaReference systemSchema = new SchemaReference(); MutableColumnDataType columnDataType = null; for (final MutableColumnDataType currentColumnDataType: columnDataTypes) { if (type == currentColumnDataType.getJavaSqlType().getVendorTypeNumber()) { columnDataType = currentColumnDataType; if (columnDataType.getSchema().equals(systemSchema)) { break; } } } return columnDataType; }
MutableColumnDataType lookupColumnDataTypeByType(final int type) { final SchemaReference systemSchema = new SchemaReference(); MutableColumnDataType columnDataType = null; for (final MutableColumnDataType currentColumnDataType: columnDataTypes) { if (type == currentColumnDataType.getJavaSqlType().getVendorTypeNumber()) { columnDataType = currentColumnDataType; if (columnDataType.getSchema().equals(systemSchema)) { break; } } } return columnDataType; }
@Test public void schemaRef() { assertThat(new SchemaReference("catalog", "schema").getFullName(), is("catalog.schema")); assertThat(new SchemaReference(null, "schema").getFullName(), is("schema")); assertThat(new SchemaReference("catalog", null).getFullName(), is("catalog")); }
final Schema schema = new SchemaReference(catalogName, schemaName); final Table table = new TablePartial(schema, tableName); column = new ColumnPartial(table, columnName);
final Schema schema = new SchemaReference(catalogName, schemaName); final Table table = new TablePartial(schema, tableName); column = new ColumnPartial(table, columnName);
final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); assertThat("Schema not found", schema, notNullValue());
@Test public void privilege() { final Table table1 = new MutableTable(new SchemaReference("catalog", "schema"), "table1"); final Table table2 = new MutableTable(new SchemaReference("catalog", "schema"), "table2"); EqualsVerifier.forClass(MutablePrivilege.class) .withIgnoredFields("remarks", "grants", "parent", "attributeMap") .withPrefabValues(DatabaseObjectReference.class, new TableReference(table1), new TableReference(table2)) .suppress(Warning.STRICT_INHERITANCE).verify(); }
/** * See: <a href= * "https://github.com/schemacrawler/SchemaCrawler/issues/228">Inconsistent * table comparison</a> */ @Test public void compareTables() { final MutableTable tbl = new MutableTable(new SchemaReference(null, "public"), "booking_detail"); tbl.setTableType(new TableType("table")); final MutableView view = new MutableView(new SchemaReference(null, "public"), "blog_monthly_stat_fa"); view.setTableType(new TableType("materialized view")); assertThat(view, lessThan(null)); assertThat(tbl, lessThan(null)); assertThat(tbl, comparesEqualTo(tbl)); assertThat(view, comparesEqualTo(view)); assertThat(tbl, lessThan(view)); assertThat(view, greaterThan(tbl)); }
final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); assertThat("Schema not found", schema, notNullValue());
final Schema schema = new SchemaReference("PUBLIC", "BOOKS"); final Table[] tables = catalog.getTables(schema).toArray(new Table[0]); assertThat("Table count does not match", tables, arrayWithSize(10));
final Schema schema1 = new SchemaReference("PUBLIC", "BOOKS"); assertThat("Could not find any tables", catalog.getTables(schema1), hasSize(4)); final Schema schema2 = new SchemaReference("PUBLIC", "BOOKS");
@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 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)); } }