如何在 Java 代码中使用 SchemaCrawler 的离线快照
How to use SchemaCrawler's Offline Snapshots in Java code
我认为 header 解释了一切:有没有一种很好的方法可以在不使用命令行的情况下使用 SchemaCrawler 创建和加载数据库架构的离线快照?如果是,您能否提供一些示例代码/link?如果没有,一些示例 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
到 "connect" 到您的数据库快照。
请看下面的代码:
OfflineSnapshotTest.offlineSnapshotExecutable()
@ZidaneT,要加载离线快照,请使用 LoadSnapshotTest.java
中的代码
Sualeh Fatehi,SchemaCrawler
我认为 header 解释了一切:有没有一种很好的方法可以在不使用命令行的情况下使用 SchemaCrawler 创建和加载数据库架构的离线快照?如果是,您能否提供一些示例代码/link?如果没有,一些示例 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
到 "connect" 到您的数据库快照。
请看下面的代码: OfflineSnapshotTest.offlineSnapshotExecutable()
@ZidaneT,要加载离线快照,请使用 LoadSnapshotTest.java
中的代码Sualeh Fatehi,SchemaCrawler