allow multiple databases connection test in --test-connection v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 26 Dec 2013 22:39:38 +0100
branchv_0
changeset 74a8444f6a54f3
parent 73 d32fd50d3c2c
child 75 43aa4625ab7e
allow multiple databases connection test in --test-connection
java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Thu Dec 26 22:32:06 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Thu Dec 26 22:39:38 2013 +0100
     1.3 @@ -18,14 +18,15 @@
     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 info.globalcode.sql.dk.InfoLister.InfoType;
    1.10  import java.io.OutputStream;
    1.11  import java.util.ArrayList;
    1.12  import java.util.Collection;
    1.13  import java.util.EnumSet;
    1.14 +import java.util.HashSet;
    1.15  import java.util.List;
    1.16 +import java.util.Set;
    1.17  import java.util.regex.Pattern;
    1.18  import java.util.regex.PatternSyntaxException;
    1.19  
    1.20 @@ -39,7 +40,7 @@
    1.21  	public static final String DEFAULT_NAME_SUFFIX = "(?=([^\\w]|$))";
    1.22  	private String sql;
    1.23  	private String databaseName;
    1.24 -	private String databaseNameToTest;
    1.25 +	private Set<String> databaseNameToTest = new HashSet<>();
    1.26  	private String namePrefix = DEFAULT_NAME_PREFIX;
    1.27  	private String nameSuffix = DEFAULT_NAME_SUFFIX;
    1.28  	private String formatterName;
    1.29 @@ -84,7 +85,7 @@
    1.30  			if (!equalz(nameSuffix, DEFAULT_NAME_SUFFIX)) {
    1.31  				e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name suffix if just showing info."));
    1.32  			}
    1.33 -			if (showInfo.contains(InfoType.CONNECTION) && isEmpty(databaseNameToTest, false)) {
    1.34 +			if (showInfo.contains(InfoType.CONNECTION) && databaseNameToTest.isEmpty()) {
    1.35  				e.addProblem(new InvalidOptionsException.OptionProblem("Please specify which database should be tested."));
    1.36  			}
    1.37  		}
    1.38 @@ -210,12 +211,12 @@
    1.39  		return showInfo;
    1.40  	}
    1.41  
    1.42 -	public String getDatabaseNameToTest() {
    1.43 +	public Set<String> getDatabaseNameToTest() {
    1.44  		return databaseNameToTest;
    1.45  	}
    1.46  
    1.47 -	public void setDatabaseNameToTest(String databaseNameToTest) {
    1.48 -		this.databaseNameToTest = databaseNameToTest;
    1.49 +	public void addDatabaseNameToTest(String databaseNameToTest) {
    1.50 +		this.databaseNameToTest.add(databaseNameToTest);
    1.51  	}
    1.52  
    1.53  	public SQLCommand getSQLCommand() {
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Thu Dec 26 22:32:06 2013 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Thu Dec 26 22:39:38 2013 +0100
     2.3 @@ -120,7 +120,7 @@
     2.4  					break;
     2.5  				case Tokens.INFO_CONNECTION:
     2.6  					options.addShowInfo(InfoType.CONNECTION);
     2.7 -					options.setDatabaseNameToTest(fetchNext(args, ++i));
     2.8 +					options.addDatabaseNameToTest(fetchNext(args, ++i));
     2.9  					break;
    2.10  				default:
    2.11  					throw new CLIParserException("Unknown option: " + arg);
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Thu Dec 26 22:32:06 2013 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Thu Dec 26 22:39:38 2013 +0100
     3.3 @@ -61,7 +61,7 @@
     3.4  
     3.5  		for (InfoType infoType : commands) {
     3.6  			switch (infoType) {
     3.7 -				// only these needs formatted output
     3.8 +				// only these need formatted output
     3.9  				case CONNECTION:
    3.10  				case DATABASES:
    3.11  				case FORMATTERS:
    3.12 @@ -135,14 +135,13 @@
    3.13  	public void testConnection() throws FormatterException, ConfigurationException {
    3.14  		ColumnsHeader header = constructHeader(
    3.15  				new HeaderField("database_name", SQLType.VARCHAR),
    3.16 -				new HeaderField("configured", SQLType.VARCHAR),
    3.17 -				new HeaderField("connected", SQLType.VARCHAR));
    3.18 +				new HeaderField("configured", SQLType.BOOLEAN),
    3.19 +				new HeaderField("connected", SQLType.BOOLEAN));
    3.20  		List<Object[]> data = new ArrayList<>();
    3.21  
    3.22 -		/** TODO: support multiple DB to test */
    3.23 -		String dbName = options.getDatabaseNameToTest();
    3.24 -
    3.25 -		data.add(testConnection(dbName));
    3.26 +		for (String dbName : options.getDatabaseNameToTest()) {
    3.27 +			data.add(testConnection(dbName));
    3.28 +		}
    3.29  
    3.30  		printTable(formatter, header, data);
    3.31  	}