【问题标题】:How to use SchemaCrawler's Offline Snapshots in Java code如何在 Java 代码中使用 SchemaCrawler 的离线快照
【发布时间】:2016-10-26 08:45:19
【问题描述】:

我认为标题说明了一切:有没有一种很好的方法可以使用 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());

不知道如何连接它。

【问题讨论】:

    标签: java schemacrawler


    【解决方案1】:

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

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

    还有@ZidaneT,要加载离线快照,请使用LoadSnapshotTest.java中的代码

    Sualeh Fatehi,SchemaCrawler

    【讨论】:

    • 感谢您的回答!实际上我遇到了这个测试,所以这是我的尝试之一(可以立即编写它吗?),但后来我看到 OfflineSnapshotExecutable 构造函数实际上是受保护的,所以我无法访问它(至少不在任何包中) .出于某种原因需要这种可见性还是只是一个错误?
    • 您可能是第一个尝试以这种方式以编程方式使用它的人。我会将其公开,并发布新版本的 SchemaCrawler。请输入 GitHub 问题以跟踪它。谢谢。
    • @ZidaneT - 请使用 SchemaCrawler 14.10.06,它有一个 OfflineSnapshotExecutable 的公共构造函数
    • 谢谢!我还想问一件事:我错过了在sualeh.github.io/SchemaCrawler 上获取与您的示例代码相同的目录对象的选项(如果是离线快照)。我在 OfflineSnapshotExecutable -> loadCatalog() 中找到了一个可以执行此操作的方法,但它只是私有的。是否有一些提供相同功能的公共方法?如果没有,你能认为它是公开的还是做一个带参数的静态方法?
    • @ZidaneT - 请将此类请求作为 GitHub 问题发送 - github.com/sualeh/SchemaCrawler
    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    相关资源
    最近更新 更多