UnlockUpgradeCommand implements Command { @Override public void execute(String... args) throws Exception { OptionParser parser = new OptionParser(); OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo(""); OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo(""); OptionSpec<String> nonOption = parser.nonOptions("unlockUpgrade {<jdbc-uri> | <mongodb-uri>}"); OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp(); OptionSet options = parser.parse(args); List<String> nonOptions = nonOption.values(options); if (options.has(help)) { parser.printHelpOn(System.out); return; } if (nonOptions.isEmpty()) { parser.printHelpOn(System.err); return; } DocumentStore store = null; try { String uri = nonOptions.get(0); if (uri.startsWith(MONGODB_PREFIX)) { MongoClientURI clientURI = new MongoClientURI(uri); if (clientURI.getDatabase() == null) { System.err.println("Database missing in MongoDB URI: " + clientURI.getURI()); } else { MongoConnection mongo = new MongoConnection(clientURI.getURI()); store = new MongoDocumentStore( mongo.getMongoClient(), mongo.getDatabase(), new MongoDocumentNodeStoreBuilder()); } } else if (uri.startsWith("jdbc")) { DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri, rdbjdbcuser.value(options), rdbjdbcpasswd.value(options)); store = new RDBDocumentStore(ds, new DocumentNodeStoreBuilder()); } else { System.err.println("Unrecognized URI: " + uri); } if (store != null && VERSION.writeTo(store)) { System.out.println("Format version set to " + VERSION); } } catch (DocumentStoreException e) { System.err.println(e.getMessage()); } finally { if (store != null) { store.dispose(); } } }  @Override void execute(String... args);  }
@Test public void unlockUpgrade() throws Exception { ns.dispose(); resetFormatVersion(FormatVersion.valueOf("0.0.1")); UnlockUpgradeCommand cmd = new UnlockUpgradeCommand(); cmd.execute(MongoUtils.URL); FormatVersion v = versionOf(createDocumentNodeStore().getDocumentStore()); assertEquals(DocumentNodeStore.VERSION, v); }