本文整理汇总了Java中schemacrawler.schema.Schema类的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Schema类属于schemacrawler.schema包,在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例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());
}
示例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);
}
}
示例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 );
}
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
}
}
}
示例13: getSchemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSchemaName(Schema schema) {
return schema.getName();
}
示例14: getSubschemaName
import schemacrawler.schema.Schema; //导入依赖的package包/类
@Override
public String getSubschemaName(Schema schema) {
return null;
}
示例15: DaSchemaImpl
import schemacrawler.schema.Schema; //导入依赖的package包/类
public DaSchemaImpl(Schema schema, SchemaStrategy schemaStrategy) {
this.schema = Validate.notNull(schema);
this.schemaStrategy = schemaStrategy;
}