schemacrawler.schema.Schema Java Examples
The following examples show how to use
schemacrawler.schema.Schema.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FromDatabaseSchemaToSpecification.java From barleydb with GNU Lesser General Public License v3.0 | 6 votes |
/** * create the entityspecs and nodespecs. * @param catalog */ private void firstPass(Catalog catalog) { LOG.debug("First pass..."); for (Schema schema: catalog.getSchemas()) { LOG.debug("Processing schema..."); for (Table table: catalog.getTables(schema)) { if (exclusionRules.excludeTable(table)) { continue; } LOG.debug("Processing table {}", table.getName()); EntitySpec espec = toEntitySpec(table); entitySpecs.put(table, espec); spec.add( espec ); } } }
Example #2
Source File: MsSqlMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public void validateDatabase(Catalog database, final PhysicalSchema physicalSchema) { MutableCollection<Schema> schemasWithIncorrectCatalog = CollectionAdapter.adapt(database.getSchemas()).reject(each -> each.getCatalogName().equals(physicalSchema.getPhysicalName())); if (schemasWithIncorrectCatalog.notEmpty()) { throw new IllegalArgumentException("Returned ASE schemas should be in " + physicalSchema.getPhysicalName() + " catalog; however, these were not: " + schemasWithIncorrectCatalog); } }
Example #3
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public void validateDatabase(Catalog database, final PhysicalSchema physicalSchema) { MutableCollection<Schema> schemasWithIncorrectCatalog = CollectionAdapter.adapt(database.getSchemas()).reject(new Predicate<Schema>() { @Override public boolean accept(Schema each) { return each.getCatalogName().equals(physicalSchema.getPhysicalName()); } }); if (schemasWithIncorrectCatalog.notEmpty()) { throw new IllegalArgumentException("Returned ASE schemas should be in " + physicalSchema.getPhysicalName() + " catalog; however, these were not: " + schemasWithIncorrectCatalog); } }
Example #4
Source File: SchemaCrawlerTest.java From neo4j-rdbms-import with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws SQLException, SchemaCrawlerException, ClassNotFoundException { Driver driver = DriverManager.getDriver("jdbc:derby:memory:test;create=true"); Connection connection = DriverManager.getConnection("jdbc:derby:memory:test;create=true", new Properties()); Statement statement = connection.createStatement(); // id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1) statement.execute("CREATE TABLE USERS (id INT NOT NULL, name varchar(20), constraint users_pk_id primary key(id))"); statement.execute("CREATE TABLE FRIENDS (id1 INT, id2 INT, " + " constraint fk_users_id1 foreign key(id1) references users(id)," + " constraint fk_users_id2 foreign key(id2) references users(id)" + ")"); final SchemaCrawlerOptions options = new SchemaCrawlerOptions(); options.setSchemaInfoLevel(SchemaInfoLevel.standard()); final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, options); for (final Schema schema : catalog.getSchemas()) { System.out.println(schema); for (final Table table : catalog.getTables(schema)) { System.out.println("o--> " + table + " pk " + table.getPrimaryKey() + " fks " + table.getForeignKeys() + " type " + table.getTableType()); for (final Column column : table.getColumns()) { System.out.println(" o--> " + column + " pk: " + column.isPartOfPrimaryKey() + " fk: " + column.isPartOfForeignKey()); } } } }
Example #5
Source File: SchemaByNameStrategy.java From obevo with Apache License 2.0 | 4 votes |
@Override public String getSchemaName(Schema schema) { return schema.getName(); }
Example #6
Source File: SchemaByNameStrategy.java From obevo with Apache License 2.0 | 4 votes |
@Override public String getSubschemaName(Schema schema) { return null; }
Example #7
Source File: DaSchemaImpl.java From obevo with Apache License 2.0 | 4 votes |
public DaSchemaImpl(Schema schema, SchemaStrategy schemaStrategy) { this.schema = Validate.notNull(schema); this.schemaStrategy = schemaStrategy; }
Example #8
Source File: SchemaByCatalogStrategy.java From obevo with Apache License 2.0 | 4 votes |
@Override public String getSchemaName(Schema schema) { return schema.getCatalogName(); }
Example #9
Source File: SchemaByCatalogStrategy.java From obevo with Apache License 2.0 | 4 votes |
@Override public String getSubschemaName(Schema schema) { return schema.getName(); }
Example #10
Source File: FromDatabaseSchemaToSpecification.java From barleydb with GNU Lesser General Public License v3.0 | 4 votes |
/** * process the foreign key relations and constraints. */ private void secondPass(Catalog catalog) { for (Schema schema: catalog.getSchemas()) { LOG.debug(schema.toString()); for (Table table: catalog.getTables(schema)) { for (ForeignKey fk: table.getForeignKeys()) { for (ForeignKeyColumnReference fkRef: fk.getColumnReferences()) { Column fkCol = fkRef.getForeignKeyColumn(); Column pkCol = fkRef.getPrimaryKeyColumn(); Table pkTable = pkCol.getParent(); EntitySpec pkEspec = entitySpecs.get(pkTable); EntitySpec fkEspec = entitySpecs.get(fkCol.getParent()); NodeSpec fkNSpec = nodeSpecs.get(fkCol); if (pkEspec == null || fkEspec == null || fkNSpec == null) { continue; } if (!processedFks.add(new ProcessedFk(fkNSpec, pkEspec))) { continue; } /* * Do the N:1 natuarl foreign key relation * */ fkNSpec.setName( genRealtionNodeName(fkNSpec) ); //java type is null, as the relation defines the type. fkNSpec.setJavaType(null); RelationSpec rspec = new RelationSpec(); rspec.setEntitySpec(pkEspec); rspec.setJoinType(JoinTypeSpec.LEFT_OUTER_JOIN); rspec.setType(RelationType.REFERS); fkNSpec.setRelation(rspec); LOG.debug("Added FK relation from {}.{} to {}", fkEspec.getClassName(), fkNSpec.getName(), pkEspec.getClassName()); createForeignKeyConstraint(fkEspec, fkNSpec, rspec); /* * do the opposite 1:N relation */ //create the nodespec as there is no dbcolumn whch created a node for us LOG.debug("Creating tomany node for N relation from {} to {}", pkEspec.getClassName(), fkEspec.getClassName()); NodeSpec toManyNodeSpec = new NodeSpec(); String nodeName = genRealtionNodeName(fkEspec, true); while (pkEspec.getNodeSpec(nodeName) != null) { nodeName = incrementNodeName(nodeName); } toManyNodeSpec.setName( nodeName ); toManyNodeSpec.setEntity(pkEspec); rspec = new RelationSpec(); rspec.setBackReference(fkNSpec); rspec.setEntitySpec(fkEspec); rspec.setJoinType(JoinTypeSpec.LEFT_OUTER_JOIN); rspec.setType(RelationType.REFERS); toManyNodeSpec.setRelation(rspec); pkEspec.add(toManyNodeSpec); } } } } }
Example #11
Source File: SchemaStrategy.java From obevo with Apache License 2.0 | votes |
String getSchemaName(Schema schema);
Example #12
Source File: SchemaStrategy.java From obevo with Apache License 2.0 | votes |
String getSubschemaName(Schema schema);