本文整理汇总了Java中schemacrawler.schema.Schema类的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Schema类属于schemacrawler.schema包,在下文中一共展示了Schema类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: importSchemas
import schemacrawler.schema.Schema; //导入依赖的package包/类
public static List<String> importSchemas(Datasource datasource) throws ServiceException {
List<String> schemaNames = new ArrayList<>();
try (Connection connection = ConnUtils.getSchemaCrawlerConnection(datasource)) {
final SchemaCrawlerOptions options = getSchemaCrawlerOptions(datasource);
options.getSchemaInfoLevel().setRetrieveDatabaseInfo(false);
options.getSchemaInfoLevel().setRetrieveTables(false);
Catalog database = SchemaCrawlerUtility.getCatalog(connection, options);
// MySQL only has catalog name, no schema name
if (datasource.getDatabaseType() == DBType.MYSQL) {
schemaNames.addAll(
database.getSchemas().stream().map(Schema::getCatalogName).collect(Collectors.toList()));
}
else {
schemaNames.addAll(database.getSchemas().stream().map(Schema::getName).collect(Collectors.toList()));
}
}
catch (Exception e) {
logger.error(e.getMessage(), e);
throw new ServiceException(e);
}
return schemaNames;
}
开发者ID:ajoabraham,项目名称:hue,代码行数:24,代码来源:SchemaImportService.java
示例2: testExtractWithExcludedReferencedTable
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Test
public void testExtractWithExcludedReferencedTable() throws Exception {
thrown.expect(RedGGenerationException.class);
thrown.expectMessage("foreign key is in an excluded table");
Connection connection = DatabaseManager.connectToDatabase("org.h2.Driver", "jdbc:h2:mem:rt-te-f", "", "");
assertNotNull(connection);
File tempFile = Helpers.getResourceAsFile("codegenerator/test.sql");
assertNotNull(tempFile);
DatabaseManager.executePreparationScripts(connection, new File[]{tempFile});
Catalog db = DatabaseManager.crawlDatabase(connection, new IncludeAll(), new RegularExpressionInclusionRule(".*USER.*"));
assertNotNull(db);
Schema s = db.lookupSchema("\"RT-TE-F\".PUBLIC").orElse(null);
assertNotNull(s);
Table t = db.lookupTable(s, "DEMO_USER").orElse(null);
assertNotNull(t);
MetadataExtractor.extract(db);
}
开发者ID:btc-ag,项目名称:redg,代码行数:20,代码来源:TableExtractorTest.java
示例3: putFKs
import schemacrawler.schema.Schema; //导入依赖的package包/类
public void putFKs(final Catalog catalog) {
try (Transaction tx = getDbService().beginTx()) {
for (final Schema schema : catalog.getSchemas()) {
for (final Table table : catalog.getTables(schema)) {
int i = 0;
for (final ForeignKey fk : table.getForeignKeys()) {
// get the fkNode from the (existing) graph
//Node fkNode = getDbService().findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName());
Node fkNode;
if (getDbService().findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName()) == null) {
fkNode = dbService.createNode(DatabaseNodeType.FOREIGN_KEY);
fkNode.setProperty("fullName", fk.getFullName());
}
}
}
}
tx.success();
}
}
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:20,代码来源:AdditionalExecutable.java
示例4: putSynonyms
import schemacrawler.schema.Schema; //导入依赖的package包/类
public void putSynonyms(final Catalog catalog) {
try (Transaction tx = getDbService().beginTx()) {
for (final Schema schema : catalog.getSchemas()) {
for (final Synonym synonym : catalog.getSynonyms(schema)) {
// add synonym to nodes
// feed node with datas
// attach synonym to schema
// attach synonym to database object (?)
//synonym.getReferencedObject().getClass();
}
}
tx.success();
}
}
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:17,代码来源:AdditionalExecutable.java
示例5: putSequences
import schemacrawler.schema.Schema; //导入依赖的package包/类
public void putSequences(final Catalog catalog) {
try (Transaction tx = getDbService().beginTx()) {
for (final Schema schema : catalog.getSchemas()) {
for (final Sequence sequence : catalog.getSequences(schema)) {
Node seqNode = dbService.createNode(DatabaseNodeType.SEQUENCE);
seqNode.setProperty("fullName", sequence.getFullName());
seqNode.setProperty("increment", sequence.getIncrement());
seqNode.setProperty("lookupKey", sequence.getLookupKey());
seqNode.setProperty("maximumValue", sequence.getMaximumValue() + "");
seqNode.setProperty("minimumValue", sequence.getMinimumValue() + "");
seqNode.setProperty("name", sequence.getName());
if (sequence.getRemarks() != null) {
seqNode.setProperty("remarks", sequence.getRemarks());
}
seqNode.setProperty("isCycle", sequence.isCycle());
// Attach sequence to schema
//dbService.findNode(DatabaseNodeType.SCHEMA, "fullName", schema.getFullName());
Relationship belongsToSchema = seqNode.createRelationshipTo(dbService.findNode(DatabaseNodeType.SCHEMA, "fullName", schema.getFullName()), SchemaRelationShips.BELONGS_TO_SCHEMA);
// attach the sequence to a column (if applicable)
}
}
tx.success();
}
}
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:27,代码来源:AdditionalExecutable.java
示例6: testForeignKeyExtraction
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Test
public void testForeignKeyExtraction() throws Exception {
Connection connection = DatabaseManager.connectToDatabase("org.h2.Driver", "jdbc:h2:mem:rt-fe", "", "");
assertNotNull(connection);
File tempFile = Helpers.getResourceAsFile("codegenerator/test.sql");
assertNotNull(tempFile);
DatabaseManager.executePreparationScripts(connection, new File[]{tempFile});
Catalog db = DatabaseManager.crawlDatabase(connection, new IncludeAll(), new IncludeAll());
assertNotNull(db);
Schema s = db.lookupSchema("\"RT-FE\".PUBLIC").orElse(null);
assertNotNull(s);
Table t = db.lookupTable(s, "DEMO_USER").orElse(null);
assertNotNull(t);
assertEquals(1, t.getImportedForeignKeys().size());
ForeignKey fk = (ForeignKey) t.getImportedForeignKeys().toArray()[0];
assertNotNull(fk);
ForeignKeyExtractor extractor = new ForeignKeyExtractor(new DefaultDataTypeProvider(), new DefaultNameProvider(),
new DefaultExplicitAttributeDecider(),"My");
ForeignKeyModel model = extractor.extractForeignKeyModel(fk);
assertEquals("MyDemoCompany", model.getJavaTypeName());
assertEquals("worksAtDemoCompany", model.getName());
assertEquals(1, model.getReferences().size());
assertTrue(model.getReferences().containsKey("WORKS_AT"));
ForeignKeyColumnModel columnModel = model.getReferences().get("WORKS_AT");
assertEquals("id", columnModel.getPrimaryKeyAttributeName());
assertEquals("worksAt", columnModel.getLocalName());
assertEquals("java.math.BigDecimal", columnModel.getLocalType());
assertEquals("WORKS_AT", columnModel.getDbName());
assertEquals("DEMO_USER", columnModel.getDbTableName());
}
开发者ID:btc-ag,项目名称:redg,代码行数:33,代码来源:ForeignKeyExtractorTest.java
示例7: testExtractTable
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Test
public void testExtractTable() throws Exception {
Connection connection = DatabaseManager.connectToDatabase("org.h2.Driver", "jdbc:h2:mem:rt-te", "", "");
assertNotNull(connection);
File tempFile = Helpers.getResourceAsFile("codegenerator/test.sql");
assertNotNull(tempFile);
DatabaseManager.executePreparationScripts(connection, new File[]{tempFile});
Catalog db = DatabaseManager.crawlDatabase(connection, new IncludeAll(), new IncludeAll());
assertNotNull(db);
Schema s = db.lookupSchema("\"RT-TE\".PUBLIC").orElse(null);
assertNotNull(s);
Table t = db.lookupTable(s, "DEMO_USER").orElse(null);
assertNotNull(t);
TableExtractor extractor = new TableExtractor("My", "com.demo.pkg", null, null, null, null);
TableModel model = extractor.extractTableModel(t);
assertNotNull(model);
assertEquals("MyDemoUser", model.getClassName());
assertEquals("DemoUser", model.getName());
assertEquals("com.demo.pkg", model.getPackageName());
assertEquals("DEMO_USER", model.getSqlName());
assertEquals(1, model.getForeignKeys().size());
assertEquals(7, model.getColumns().size()); // Due to #12 the FK-column gets counted as well
assertEquals(6, model.getNonForeignKeyColumns().size()); // Test for #12 without FK-column
assertTrue(model.hasColumnsAndForeignKeys());
}
开发者ID:btc-ag,项目名称:redg,代码行数:28,代码来源:TableExtractorTest.java
示例8: validateDatabase
import schemacrawler.schema.Schema; //导入依赖的package包/类
@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);
}
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:14,代码来源:MsSqlMetadataDialect.java
示例9: firstPass
import schemacrawler.schema.Schema; //导入依赖的package包/类
/**
* 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)) {
LOG.debug("Processing table {}", table.getName());
EntitySpec espec = toEntitySpec(table);
entitySpecs.put(table, espec);
spec.add( espec );
}
}
}
开发者ID:scottysinclair,项目名称:barleydb,代码行数:18,代码来源:FromDatabaseSchemaToSpecification.java
示例10: attachColumnsToFk
import schemacrawler.schema.Schema; //导入依赖的package包/类
public void attachColumnsToFk(final Catalog catalog) {
try (Transaction tx = getDbService().beginTx()) {
// get all columns
for (final Schema schema : catalog.getSchemas()) {
for (final Table table : catalog.getTables(schema)) {
for (final ForeignKey fk : table.getImportedForeignKeys()) {
//fk.
//get the node of the fk
dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName());
// get the node of the table
dbService.findNode(DatabaseNodeType.TABLE, "fullName", table.getFullName());
// attach FK to table
Relationship fkBelongsToTable = dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName()).createRelationshipTo(dbService.findNode(DatabaseNodeType.TABLE, "fullName", table.getFullName()), SchemaRelationShips.BELONGS_TO_TABLE);
// fetch the columns of the fk
for (final ForeignKeyColumnReference fkColRef : fk.getColumnReferences()) {
// get the node of the column
dbService.findNode(DatabaseNodeType.TABLE_COLUMN, "fullName", fkColRef.getForeignKeyColumn().getFullName());
// attach column to fk
Relationship rel = dbService.findNode(DatabaseNodeType.TABLE_COLUMN, "fullName", fkColRef.getForeignKeyColumn().getFullName()).createRelationshipTo(dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName()), SchemaRelationShips.IS_COLUMN_OF_FK);
}
//dbService.findNodes(DatabaseNodeType.TABLE_COLUMN, "fullName", fk.)
}
}
}
tx.success();
}
}
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:29,代码来源:AdditionalExecutable.java
示例11: putNbRowsOfTables
import schemacrawler.schema.Schema; //导入依赖的package包/类
public void putNbRowsOfTables(final Catalog catalog, final Connection connection) throws SQLException {
try (Transaction tx = getDbService().beginTx()) {
for (final Schema schema : catalog.getSchemas()) {
for (final Table table : catalog.getTables(schema)) {
// for each table, count the number of rows
String sql = "select count(1) from " + schema.getName() + ".\"" + table.getName() + "\"";
Statement stmt = null;
try {
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
int nbRows = rs.getInt(1);
//get the table node and set the number of rows in it
dbService.findNode(DatabaseNodeType.TABLE, "fullName", table.getFullName()).setProperty("nbRows", nbRows);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
}
tx.success();
}
}
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:30,代码来源:AdditionalExecutable.java
示例12: main
import schemacrawler.schema.Schema; //导入依赖的package包/类
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());
}
}
}
}
开发者ID:jexp,项目名称:neo4j-rdbms-import,代码行数:28,代码来源:SchemaCrawlerTest.java
示例13: getSchemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSchemaName(Schema schema) {
return schema.getName();
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:SchemaByNameStrategy.java
示例14: getSubschemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSubschemaName(Schema schema) {
return null;
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:SchemaByNameStrategy.java
示例15: DaSchemaImpl
import schemacrawler.schema.Schema; //导入依赖的package包/类
public DaSchemaImpl(Schema schema, SchemaStrategy schemaStrategy) {
this.schema = Validate.notNull(schema);
this.schemaStrategy = schemaStrategy;
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:DaSchemaImpl.java
示例16: getSchemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSchemaName(Schema schema) {
return schema.getCatalogName();
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:SchemaByCatalogStrategy.java
示例17: getSubschemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSubschemaName(Schema schema) {
return schema.getName();
}
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:SchemaByCatalogStrategy.java
示例18: secondPass
import schemacrawler.schema.Schema; //导入依赖的package包/类
/**
* process the foreign key relations and constraints.
*/
private void secondPass(Catalog catalog) {
for (Schema schema: catalog.getSchemas()) {
System.out.println(schema);
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 (!processedFks.add(new ProcessedFk(fkNSpec, pkEspec))) {
continue;
}
/*
* Do the N:1 natual foreign key relation *
*/
fkNSpec.setName( genRealtionNodeName(pkEspec) );
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);
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);
}
}
}
}
}
开发者ID:scottysinclair,项目名称:barleydb,代码行数:61,代码来源:FromDatabaseSchemaToSpecification.java
示例19: getSchemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
String getSchemaName(Schema schema);
开发者ID:goldmansachs,项目名称:obevo,代码行数:2,代码来源:SchemaStrategy.java
示例20: getSubschemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
String getSubschemaName(Schema schema);
开发者ID:goldmansachs,项目名称:obevo,代码行数:2,代码来源:SchemaStrategy.java
注:本文中的schemacrawler.schema.Schema类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论