0

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.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());

Not sure how to connect to it though.

ZidaneT
  • 3
  • 2

1 Answers1

0

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

Sualeh Fatehi
  • 4,700
  • 2
  • 24
  • 28
  • Thank you for your answer! Actually I came across this test so this was one of my attempts (could have written it right away right?), but then I saw that OfflineSnapshotExecutable constructor is actually protected, so I can't access it (at least not in any package). Is this visibility desired for some reason or is it just a bug? – ZidaneT Oct 27 '16 at 07:10
  • You just may be the first person to try to use this programmatically in this way. I will make it public, and release a new version of SchemaCrawler. Please enter in a GitHub issue to track it. Thanks. – Sualeh Fatehi Oct 27 '16 at 16:16
  • @ZidaneT - please use SchemaCrawler 14.10.06, which has a public constructor for `OfflineSnapshotExecutable` – Sualeh Fatehi Oct 30 '16 at 01:57
  • Thank you ! There is one more thing I wanted to ask: I miss an option to get Catalog object same as in your sample code on http://sualeh.github.io/SchemaCrawler/ (in case of offline snapshot). I found a method in OfflineSnapshotExecutable -> loadCatalog() which does this, but it is only private. Is there some public method providing the same functionality? If not, could you consider it to be public or make a static method with parameters? – ZidaneT Nov 01 '16 at 12:29
  • @ZidaneT - please send requests like this as GitHub issues - https://github.com/sualeh/SchemaCrawler – Sualeh Fatehi Nov 01 '16 at 17:22
  • @ZidaneT To load an offline snapshot, use code like that in [LoadSnapshotTest\.java](https://github.com/sualeh/SchemaCrawler/blob/48275a508c9f1624e0870dea1b4707e01094f1d7/schemacrawler-offline/src/test/java/schemacrawler/integration/test/LoadSnapshotTest.java#L68-L78) – Sualeh Fatehi Nov 02 '16 at 01:19