• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SchemaCrawlerUtility类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中schemacrawler.utility.SchemaCrawlerUtility的典型用法代码示例。如果您正苦于以下问题:Java SchemaCrawlerUtility类的具体用法?Java SchemaCrawlerUtility怎么用?Java SchemaCrawlerUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SchemaCrawlerUtility类属于schemacrawler.utility包,在下文中一共展示了SchemaCrawlerUtility类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: importSchemas

import schemacrawler.utility.SchemaCrawlerUtility; //导入依赖的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: crawlDatabase

import schemacrawler.utility.SchemaCrawlerUtility; //导入依赖的package包/类
/**
 * Starts the schema crawler and lets it crawl the given JDBC connection.
 *
 * @param connection The JDBC connection
 * @param schemaRule The {@link InclusionRule} to be passed to SchemaCrawler that specifies which schemas should be analyzed
 * @param tableRule  The {@link InclusionRule} to be passed to SchemaCrawler that specifies which tables should be analyzed. If a table is included by the
 *                   {@code tableRule} but excluded by the {@code schemaRule} it will not be analyzed.
 * @return The populated {@link Catalog} object containing the metadata for the extractor
 * @throws SchemaCrawlerException Gets thrown when the database could not be crawled successfully
 */
public static Catalog crawlDatabase(final Connection connection, final InclusionRule schemaRule, final InclusionRule tableRule) throws SchemaCrawlerException {
    final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
    final SchemaInfoLevel level = SchemaInfoLevelBuilder.standard();
    level.setRetrieveIndexes(false);
    options.setSchemaInfoLevel(level);
    options.setRoutineTypes(Arrays.asList(RoutineType.procedure, RoutineType.unknown)); // RoutineType.function not supported by h2
    options.setSchemaInclusionRule(schemaRule == null ? new IncludeAll() : schemaRule);
    options.setTableInclusionRule(tableRule == null ? new IncludeAll() : tableRule);

    try {
        return SchemaCrawlerUtility.getCatalog(connection, options);
    } catch (SchemaCrawlerException e) {
        LOG.error("Schema crawling failed with exception", e);
        throw e;
    }
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:27,代码来源:DatabaseManager.java


示例3: generateSpecification

import schemacrawler.utility.SchemaCrawlerUtility; //导入依赖的package包/类
public SpecRegistry generateSpecification(DataSource dataSource) throws Exception {
    SchemaCrawlerOptions options = new SchemaCrawlerOptions();
    // Set what details are required in the schema - this affects the
    // time taken to crawl the schema
    options.setSchemaInfoLevel(SchemaInfoLevelBuilder.detailed());

    Catalog catalog = SchemaCrawlerUtility.getCatalog( dataSource.getConnection(),
                                                      options);

    firstPass(catalog);
    secondPass(catalog);
    postProcess(catalog);
    return registry;
}
 
开发者ID:scottysinclair,项目名称:barleydb,代码行数:15,代码来源:FromDatabaseSchemaToSpecification.java


示例4: main

import schemacrawler.utility.SchemaCrawlerUtility; //导入依赖的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


示例5: extractTables

import schemacrawler.utility.SchemaCrawlerUtility; //导入依赖的package包/类
static TableInfo[] extractTables(Connection conn, final String schemaName, Rules rules) throws SchemaCrawlerException, SQLException {
        ArrayList<TableInfo> tableList = new ArrayList<TableInfo>(100);

        final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
        options.setSchemaInfoLevel(SchemaInfoLevel.standard());
        System.out.println("my catalog =" + conn.getCatalog());
        options.setSchemaInclusionRule(new InclusionRule() {
            @Override public boolean test(String anObject) {
                return schemaName.equals(anObject);
            }
        });

        final Catalog catalog = SchemaCrawlerUtility.getCatalog(conn, options);
        System.out.println("schem ! ");


        final Schema schema = catalog.getSchema(schemaName);
        System.out.println("Schema: " + schema);

        for (final Table table : catalog.getTables(schema)) {
            String tableName = table.getName();

            System.out.println(table + " pk " + table.getPrimaryKey() + " fks " + table.getForeignKeys() + " type " + table.getTableType());
            if (rules.skipTable(tableName) || table.getTableType().isView()) {
                System.out.println("SKIPPED");
                continue;
            }
            List<Column> columns = table.getColumns();
            List<String> fields = new ArrayList<>(columns.size());
            for (final Column column : columns) {
//                    System.out.println("     o--> " + column + " pk: "+ column.isPartOfPrimaryKey() + " fk: " + column.isPartOfForeignKey());
                String columnName = column.getName();
                if (column.isPartOfPrimaryKey() && rules.skipPrimaryKey(tableName, columnName)) {
                    // skip, todo strategy
                } else if (column.isPartOfForeignKey()) {
                    // skip, todo strategy
                } else {
                    fields.add(columnName);
                }
            }
            Map<List<String>, String> fks = extractForeignKeys(table);
            tableList.add(TableInfo.add(tableName, extractPrimaryKeys(table, fks), fields, fks));
        }

        return tableList.toArray(new TableInfo[tableList.size()]);
    }
 
开发者ID:jexp,项目名称:neo4j-rdbms-import,代码行数:47,代码来源:MetaDataReader.java



注:本文中的schemacrawler.utility.SchemaCrawlerUtility类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AbstractBuffer类代码示例发布时间:2022-05-22
下一篇:
Java RendererException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap