1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Mon Dec 16 15:15:32 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Mon Dec 16 15:29:02 2013 +0100
1.3 @@ -1,6 +1,7 @@
1.4 package info.globalcode.sql.dk;
1.5
1.6 import static info.globalcode.sql.dk.Functions.isNotEmpty;
1.7 +import static info.globalcode.sql.dk.Functions.isEmpty;
1.8 import static info.globalcode.sql.dk.Functions.equalz;
1.9 import java.util.ArrayList;
1.10 import java.util.Collection;
1.11 @@ -16,6 +17,7 @@
1.12 public static final String DEFAULT_NAME_PREFIX = ":";
1.13 private String sql;
1.14 private String databaseName;
1.15 + private String databaseNameToTest;
1.16 private String namePrefix = DEFAULT_NAME_PREFIX;
1.17 private String formatterName;
1.18 private boolean batch;
1.19 @@ -34,7 +36,9 @@
1.20 VERSION,
1.21 LICENSE,
1.22 FORMATTERS,
1.23 - TYPES
1.24 + TYPES,
1.25 + DATABASES,
1.26 + CONNECTION
1.27 }
1.28
1.29 public enum COMMAND_TYPE {
1.30 @@ -77,6 +81,9 @@
1.31 if (!equalz(namePrefix, DEFAULT_NAME_PREFIX)) {
1.32 e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name prefix if just showing info."));
1.33 }
1.34 + if (showInfo.contains(INFO_TYPE.CONNECTION) && isEmpty(databaseNameToTest, false)) {
1.35 + e.addProblem(new InvalidOptionsException.OptionProblem("Please specify which database should be tested."));
1.36 + }
1.37 }
1.38
1.39 if (!namedParameters.isEmpty() && !numberedParameters.isEmpty()) {
1.40 @@ -182,4 +189,12 @@
1.41 public EnumSet<INFO_TYPE> getShowInfo() {
1.42 return showInfo;
1.43 }
1.44 +
1.45 + public String getDatabaseNameToTest() {
1.46 + return databaseNameToTest;
1.47 + }
1.48 +
1.49 + public void setDatabaseNameToTest(String databaseNameToTest) {
1.50 + this.databaseNameToTest = databaseNameToTest;
1.51 + }
1.52 }
2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Mon Dec 16 15:15:32 2013 +0100
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Mon Dec 16 15:29:02 2013 +0100
2.3 @@ -114,6 +114,13 @@
2.4 case Tokens.INFO_VERSION:
2.5 options.addShowInfo(CLIOptions.INFO_TYPE.VERSION);
2.6 break;
2.7 + case Tokens.INFO_DATABASES:
2.8 + options.addShowInfo(CLIOptions.INFO_TYPE.DATABASES);
2.9 + break;
2.10 + case Tokens.INFO_CONNECTION:
2.11 + options.addShowInfo(CLIOptions.INFO_TYPE.CONNECTION);
2.12 + options.setDatabaseNameToTest(fetchNext(args, ++i));
2.13 + break;
2.14 default:
2.15 throw new CLIParserException("Unknown option: " + arg);
2.16 }
2.17 @@ -145,6 +152,8 @@
2.18 public static final String INFO_LICENSE = "--license";
2.19 public static final String INFO_FORMATTERS = "--list-formatters";
2.20 public static final String INFO_TYPES = "--list-types";
2.21 + public static final String INFO_DATABASES = "--list-databases";
2.22 + public static final String INFO_CONNECTION = "--test-connection";
2.23
2.24 private Tokens() {
2.25 }
3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 15:15:32 2013 +0100
3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 15:29:02 2013 +0100
3.3 @@ -23,7 +23,7 @@
3.4 /** Show info */
3.5 if (!options.getShowInfo().isEmpty()) {
3.6 InfoLister infoLister = new InfoLister();
3.7 - infoLister.showInfo(options.getShowInfo(), System.err);
3.8 + infoLister.showInfo(options, System.err);
3.9 }
3.10
3.11 } catch (CLIParserException e) {
4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 15:15:32 2013 +0100
4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 15:29:02 2013 +0100
4.3 @@ -10,7 +10,8 @@
4.4 */
4.5 public class InfoLister {
4.6
4.7 - public void showInfo(EnumSet<CLIOptions.INFO_TYPE> infoTypes, PrintStream out) {
4.8 + public void showInfo(CLIOptions options, PrintStream out) {
4.9 + EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
4.10 for (CLIOptions.INFO_TYPE infoType : infoTypes) {
4.11 switch (infoType) {
4.12 /**
4.13 @@ -31,6 +32,12 @@
4.14 case VERSION:
4.15 out.println("TODO: show version");
4.16 break;
4.17 + case DATABASES:
4.18 + out.println("TODO: list databases");
4.19 + break;
4.20 + case CONNECTION:
4.21 + out.println("TODO: test database connection: " + options.getDatabaseNameToTest());
4.22 + break;
4.23 default:
4.24 throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
4.25 }