database/formatter properties also as CLI options v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 01 Jan 2014 02:44:29 +0100
branchv_0
changeset 1078189a4a28cd8
parent 106 e9c3583580c8
child 108 d06d90b28217
database/formatter properties also as CLI options
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Wed Jan 01 01:06:38 2014 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Wed Jan 01 02:44:29 2014 +0100
     1.3 @@ -18,6 +18,7 @@
     1.4  package info.globalcode.sql.dk;
     1.5  
     1.6  import info.globalcode.sql.dk.InfoLister.InfoType;
     1.7 +import info.globalcode.sql.dk.configuration.Property;
     1.8  import java.util.ArrayList;
     1.9  import java.util.HashMap;
    1.10  import java.util.List;
    1.11 @@ -100,6 +101,12 @@
    1.12  				case Tokens.FORMATTER:
    1.13  					options.setFormatterName(fetchNext(args, ++i));
    1.14  					break;
    1.15 +				case Tokens.DB_PROPERTY:
    1.16 +					options.addDatabaseProperty(new Property(fetchNext(args, ++i), fetchNext(args, ++i)));
    1.17 +					break;
    1.18 +				case Tokens.FORMATTER_PROPERTY:
    1.19 +					options.addFormatterProperty(new Property(fetchNext(args, ++i), fetchNext(args, ++i)));
    1.20 +					break;
    1.21  				case Tokens.INFO_HELP:
    1.22  					options.addShowInfo(InfoType.HELP);
    1.23  					break;
    1.24 @@ -141,6 +148,7 @@
    1.25  
    1.26  		// bash-completion:options:
    1.27  		public static final String DB = "--db"; // bash-completion:option // help: database name
    1.28 +		public static final String DB_PROPERTY = "--db-property"; // bash-completion:option // help: name and value
    1.29  		public static final String SQL = "--sql"; // bash-completion:option // help: SQL query/command
    1.30  		public static final String BATCH = "--batch"; // bash-completion:option // help: batch mode (no argument)
    1.31  		public static final String DATA = "--data"; // bash-completion:option // help: list of ordinal parameters
    1.32 @@ -149,6 +157,7 @@
    1.33  		public static final String NAME_SUFFIX = "--name-suffix"; // bash-completion:option // help: parameter name suffix – regular expression
    1.34  		public static final String TYPES = "--types"; // bash-completion:option // help: comma separated list of parameter types
    1.35  		public static final String FORMATTER = "--formatter"; // bash-completion:option // help: name of the output formatter
    1.36 +		public static final String FORMATTER_PROPERTY = "--formatter-property"; // bash-completion:option // help: name and value
    1.37  		public static final String INFO_HELP = "--help"; // bash-completion:option // help: print this help
    1.38  		public static final String INFO_VERSION = "--version"; // bash-completion:option // help: print version info
    1.39  		public static final String INFO_LICENSE = "--license"; // bash-completion:option // help: print license
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Wed Jan 01 01:06:38 2014 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Wed Jan 01 02:44:29 2014 +0100
     2.3 @@ -20,6 +20,7 @@
     2.4  import info.globalcode.sql.dk.batch.Batch;
     2.5  import info.globalcode.sql.dk.configuration.DatabaseDefinition;
     2.6  import info.globalcode.sql.dk.configuration.Properties;
     2.7 +import info.globalcode.sql.dk.configuration.Property;
     2.8  import info.globalcode.sql.dk.formatting.ColumnsHeader;
     2.9  import info.globalcode.sql.dk.formatting.Formatter;
    2.10  import java.sql.Connection;
    2.11 @@ -46,10 +47,12 @@
    2.12  		this.databaseDefinition = databaseDefinition;
    2.13  		this.properties = properties;
    2.14  
    2.15 -		properties.setDefaults(databaseDefinition.getProperties());
    2.16 +		Properties credentials = new Properties();
    2.17 +		credentials.add(new Property("user", databaseDefinition.getUserName()));
    2.18 +		credentials.add(new Property("password", databaseDefinition.getPassword()));
    2.19 +		credentials.setDefaults(databaseDefinition.getProperties());
    2.20 +		properties.setDefaults(credentials);
    2.21  		java.util.Properties javaProperties = properties.getJavaProperties();
    2.22 -		javaProperties.setProperty("user", databaseDefinition.getUserName());
    2.23 -		javaProperties.setProperty("password", databaseDefinition.getPassword());
    2.24  
    2.25  		connection = DriverManager.getConnection(databaseDefinition.getUrl(), javaProperties);
    2.26  	}
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java	Wed Jan 01 01:06:38 2014 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java	Wed Jan 01 02:44:29 2014 +0100
     3.3 @@ -94,14 +94,14 @@
     3.4  	 */
     3.5  	public java.util.Properties getJavaProperties() {
     3.6  		java.util.Properties javaProperties = new java.util.Properties();
     3.7 -		if (defaults != null) {
     3.8 -			duplicateTo(javaProperties);
     3.9 -		}
    3.10  		duplicateTo(javaProperties);
    3.11  		return javaProperties;
    3.12  	}
    3.13  
    3.14  	private void duplicateTo(java.util.Properties javaProperties) {
    3.15 +		if (defaults != null) {
    3.16 +			defaults.duplicateTo(javaProperties);
    3.17 +		}
    3.18  		for (Property p : this) {
    3.19  			javaProperties.setProperty(p.getName(), p.getValue());
    3.20  		}