
org.jsimpledb.cli.cmd.ShowAllSchemasCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-cli Show documentation
Show all versions of jsimpledb-cli Show documentation
JSimpleDB classes supporting command line interfaces.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb.cli.cmd;
import java.util.Map;
import org.jsimpledb.cli.CliSession;
import org.jsimpledb.core.Schema;
import org.jsimpledb.schema.SchemaModel;
import org.jsimpledb.util.ParseContext;
@Command
public class ShowAllSchemasCommand extends AbstractCommand {
public ShowAllSchemasCommand() {
super("show-all-schemas -x:xml");
}
@Override
public String getHelpSummary() {
return "Shows all schema versions recorded in the database";
}
@Override
public String getHelpDetail() {
return "If the `-x' flag is provided, the XML representation of each schema version is included.";
}
@Override
public CliSession.Action getAction(CliSession session, ParseContext ctx, boolean complete, Map params) {
final boolean xml = params.containsKey("xml");
return new CliSession.TransactionalAction() {
@Override
public void run(CliSession session) throws Exception {
for (Map.Entry entry : session.getTransaction().getSchemas().getVersions().entrySet()) {
final int number = entry.getKey();
final SchemaModel model = entry.getValue().getSchemaModel();
if (xml) {
session.getWriter().println("=== Schema version " + number + " ===\n"
+ model.toString().replaceAll("^<.xml[^>]+>\\n", ""));
} else
session.getWriter().println(number);
}
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy