ZidaneT ZidaneT - 6 months ago 47
Java Question

How to use SchemaCrawler's Offline Snapshots in Java code

I think the header explains it all: Is there a nice way to create and load offline snapshots of database schema using SchemaCrawler without using command line? If yes, can you provide some example code / link please? If not, some example java code to use command line options would be helpful too (I don't have much experience with that)!

Thanks for any kind of help!

PS: I managed to create offline snapshot with this code:

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

final String command = "serialize";

final Executable executable = new SchemaCrawlerExecutable(command);

Not sure how to connect to it though.


You need to use the schemacrawler.tools.offline.OfflineSnapshotExecutable along with an schemacrawler.tools.offline.jdbc.OfflineConnection to "connect" to your database snapshoot.

Please take a look at the following code: OfflineSnapshotTest.offlineSnapshotExecutable()

And @ZidaneT, to load an offline snapshot, use code like that in LoadSnapshotTest.java

Sualeh Fatehi, SchemaCrawler