繁体   English   中英

如何在Java代码中使用SchemaCrawler的脱机快照

[英]How to use SchemaCrawler's Offline Snapshots in Java code

我认为标题说明了一切:有没有一种使用SchemaCrawler而不使用命令行来创建和加载数据库架构的脱机快照的好方法? 如果是,您能否提供一些示例代码/链接? 如果没有,那么一些使用命令行选项的示例Java代码也会有所帮助(我对此没有太多经验)!

感谢您的任何帮助!

PS:我设法使用以下代码创建脱机快照:

    final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
    // Set what details are required in the schema - this affects the
    // time taken to crawl the schema
    options.setSchemaInfoLevel(SchemaInfoLevelBuilder.standard());
    options.setRoutineInclusionRule(new ExcludeAll());
    options.setSchemaInclusionRule(new RegularExpressionInclusionRule(/* some regex here*/));
    options.setTableInclusionRule(new RegularExpressionExclusionRule(/*some regex here*/));

    outputOptions.setCompressedOutputFile(Paths.get("./test_db_snapshot.xml"));
    final String command = "serialize";

    final Executable executable = new SchemaCrawlerExecutable(command);
    executable.setSchemaCrawlerOptions(options);
    executable.setOutputOptions(outputOptions);
    executable.execute(getConnection());

虽然不确定如何连接。

您需要使用schemacrawler.tools.offline.OfflineSnapshotExecutable以及schemacrawler.tools.offline.jdbc.OfflineConnection来“连接”到数据库快照。

请看下面的代码: OfflineSnapshotTest.offlineSnapshotExecutable()

@ZidaneT,要加载脱机快照,请使用类似LoadSnapshotTest.java中的代码

Sualeh Fatehi, SchemaCrawler

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM