connection tunnelling: configuration and logging v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 09:40:22 +0200
branchv_0
changeset 203504c4ba56d1c
parent 202 01078e09b85b
child 204 2805fea90278
connection tunnelling: configuration and logging
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
java/sql-dk/src/info/globalcode/sql/dk/configuration/CommandArgument.java
java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java
java/sql-dk/src/info/globalcode/sql/dk/configuration/TunnelDefinition.java
xml/config.rnc
xml/config.xsd
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sun Jun 21 16:21:51 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 09:40:22 2015 +0200
     1.3 @@ -17,6 +17,7 @@
     1.4   */
     1.5  package info.globalcode.sql.dk;
     1.6  
     1.7 +import info.globalcode.sql.dk.configuration.CommandArgument;
     1.8  import info.globalcode.sql.dk.configuration.Configuration;
     1.9  import info.globalcode.sql.dk.configuration.ConfigurationException;
    1.10  import info.globalcode.sql.dk.configuration.ConfigurationProvider;
    1.11 @@ -24,6 +25,7 @@
    1.12  import info.globalcode.sql.dk.configuration.FormatterDefinition;
    1.13  import info.globalcode.sql.dk.configuration.Properties;
    1.14  import info.globalcode.sql.dk.configuration.Property;
    1.15 +import info.globalcode.sql.dk.configuration.TunnelDefinition;
    1.16  import info.globalcode.sql.dk.formatting.ColumnsHeader;
    1.17  import info.globalcode.sql.dk.formatting.FakeSqlArray;
    1.18  import info.globalcode.sql.dk.formatting.Formatter;
    1.19 @@ -197,6 +199,15 @@
    1.20  		} else {
    1.21  			for (DatabaseDefinition dd : configuredDatabases) {
    1.22  				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
    1.23 +
    1.24 +				final TunnelDefinition tunnel = dd.getTunnel();
    1.25 +				if (tunnel != null) {
    1.26 +					log.log(Level.INFO, "Tunnel command: {0}", tunnel.getCommand());
    1.27 +					for (CommandArgument ca : Functions.notNull(tunnel.getArguments())) {
    1.28 +						log.log(Level.INFO, "\targument: {0}/{1}", new Object[]{ca.getType(), ca.getValue()});
    1.29 +					}
    1.30 +				}
    1.31 +
    1.32  			}
    1.33  		}
    1.34  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/CommandArgument.java	Sat Aug 15 09:40:22 2015 +0200
     2.3 @@ -0,0 +1,82 @@
     2.4 +/**
     2.5 + * SQL-DK
     2.6 + * Copyright © 2015 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package info.globalcode.sql.dk.configuration;
    2.22 +
    2.23 +import javax.xml.bind.annotation.XmlAttribute;
    2.24 +import javax.xml.bind.annotation.XmlEnum;
    2.25 +import javax.xml.bind.annotation.XmlEnumValue;
    2.26 +import javax.xml.bind.annotation.XmlValue;
    2.27 +
    2.28 +/**
    2.29 + *
    2.30 + * @author Ing. František Kučera (frantovo.cz)
    2.31 + */
    2.32 +public class CommandArgument {
    2.33 +
    2.34 +	private String value;
    2.35 +	private TYPE type;
    2.36 +
    2.37 +	@XmlEnum
    2.38 +	public static enum TYPE {
    2.39 +
    2.40 +		/**
    2.41 +		 * value = literal (text) argument
    2.42 +		 */
    2.43 +		@XmlEnumValue("literal")
    2.44 +		LITERAL,
    2.45 +		/**
    2.46 +		 * value will be substituted by hostname or IP address of the DB server
    2.47 +		 */
    2.48 +		@XmlEnumValue("host")
    2.49 +		HOST,
    2.50 +		/**
    2.51 +		 * value will be substituted by the port of the DB server
    2.52 +		 */
    2.53 +		@XmlEnumValue("port")
    2.54 +		PORT,
    2.55 +		/**
    2.56 +		 * value will be substituted by environmental variable of given name
    2.57 +		 */
    2.58 +		@XmlEnumValue("env")
    2.59 +		ENVIRONMENT_VARIABLE,
    2.60 +		/**
    2.61 +		 * value will be substituted by database property of given name
    2.62 +		 */
    2.63 +		@XmlEnumValue("dbProperty")
    2.64 +		DB_PROPERTY;
    2.65 +	}
    2.66 +
    2.67 +	@XmlValue
    2.68 +	public String getValue() {
    2.69 +		return value;
    2.70 +	}
    2.71 +
    2.72 +	public void setValue(String value) {
    2.73 +		this.value = value;
    2.74 +	}
    2.75 +
    2.76 +	@XmlAttribute(name = "type")
    2.77 +	public TYPE getType() {
    2.78 +		return type;
    2.79 +	}
    2.80 +
    2.81 +	public void setType(TYPE type) {
    2.82 +		this.type = type;
    2.83 +	}
    2.84 +
    2.85 +}
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java	Sun Jun 21 16:21:51 2015 +0200
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java	Sat Aug 15 09:40:22 2015 +0200
     3.3 @@ -57,6 +57,10 @@
     3.4  	 * JDBC properties
     3.5  	 */
     3.6  	private Properties properties = new Properties();
     3.7 +	/**
     3.8 +	 * optional definition of tunnel to the remote database
     3.9 +	 */
    3.10 +	private TunnelDefinition tunnel;
    3.11  
    3.12  	@XmlElement(name = "name", namespace = CONFIGURATION)
    3.13  	@Override
    3.14 @@ -112,6 +116,14 @@
    3.15  		this.properties = properties;
    3.16  	}
    3.17  
    3.18 +	public TunnelDefinition getTunnel() {
    3.19 +		return tunnel;
    3.20 +	}
    3.21 +
    3.22 +	public void setTunnel(TunnelDefinition tunnel) {
    3.23 +		this.tunnel = tunnel;
    3.24 +	}
    3.25 +
    3.26  	/**
    3.27  	 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
    3.28  	 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/TunnelDefinition.java	Sat Aug 15 09:40:22 2015 +0200
     4.3 @@ -0,0 +1,51 @@
     4.4 +/**
     4.5 + * SQL-DK
     4.6 + * Copyright © 2015 František Kučera (frantovo.cz)
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, either version 3 of the License, or
    4.11 + * (at your option) any later version.
    4.12 + *
    4.13 + * This program is distributed in the hope that it will be useful,
    4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    4.16 + * GNU General Public License for more details.
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License
    4.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    4.20 + */
    4.21 +package info.globalcode.sql.dk.configuration;
    4.22 +
    4.23 +import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
    4.24 +import java.util.List;
    4.25 +import javax.xml.bind.annotation.XmlElement;
    4.26 +
    4.27 +/**
    4.28 + *
    4.29 + * @author Ing. František Kučera (frantovo.cz)
    4.30 + */
    4.31 +public class TunnelDefinition {
    4.32 +
    4.33 +	private String command;
    4.34 +	private List<CommandArgument> arguments;
    4.35 +
    4.36 +	@XmlElement(name = "command", namespace = CONFIGURATION)
    4.37 +	public String getCommand() {
    4.38 +		return command;
    4.39 +	}
    4.40 +
    4.41 +	public void setCommand(String command) {
    4.42 +		this.command = command;
    4.43 +	}
    4.44 +
    4.45 +	@XmlElement(name = "argument", namespace = CONFIGURATION)
    4.46 +	public List<CommandArgument> getArguments() {
    4.47 +		return arguments;
    4.48 +	}
    4.49 +
    4.50 +	public void setArguments(List<CommandArgument> arguments) {
    4.51 +		this.arguments = arguments;
    4.52 +	}
    4.53 +
    4.54 +}
     5.1 --- a/xml/config.rnc	Sun Jun 21 16:21:51 2015 +0200
     5.2 +++ b/xml/config.rnc	Sat Aug 15 09:40:22 2015 +0200
     5.3 @@ -28,7 +28,14 @@
     5.4  			element property {
     5.5  				attribute name { text },
     5.6  				text
     5.7 -			}*
     5.8 +			}*,
     5.9 +			element tunnel {
    5.10 +				element command { text },
    5.11 +				element argument {
    5.12 +					attribute type { "literal" | "host" | "port" | "env" | "dbProperty" }?,
    5.13 +					text
    5.14 +				}*
    5.15 +			}?
    5.16  		}*,
    5.17  		
    5.18  		element defaultFormatter { text }?,
     6.1 --- a/xml/config.xsd	Sun Jun 21 16:21:51 2015 +0200
     6.2 +++ b/xml/config.xsd	Sat Aug 15 09:40:22 2015 +0200
     6.3 @@ -41,6 +41,7 @@
     6.4  				<xs:element minOccurs="0" ref="c:password"/>
     6.5  				<xs:element minOccurs="0" ref="c:driver"/>
     6.6  				<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:property"/>
     6.7 +				<xs:element minOccurs="0" ref="c:tunnel"/>
     6.8  			</xs:sequence>
     6.9  		</xs:complexType>
    6.10  	</xs:element>
    6.11 @@ -57,6 +58,33 @@
    6.12  		</xs:complexType>
    6.13  	</xs:element>
    6.14  	
    6.15 +	<xs:element name="tunnel">
    6.16 +		<xs:complexType>
    6.17 +			<xs:sequence>
    6.18 +				<xs:element ref="c:command"/>
    6.19 +				<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:argument"/>
    6.20 +			</xs:sequence>
    6.21 +		</xs:complexType>
    6.22 +	</xs:element>
    6.23 +	
    6.24 +	<xs:element name="command" type="xs:string"/>
    6.25 +	
    6.26 +	<xs:element name="argument">
    6.27 +		<xs:complexType mixed="true">
    6.28 +			<xs:attribute name="type">
    6.29 +				<xs:simpleType>
    6.30 +					<xs:restriction base="xs:token">
    6.31 +						<xs:enumeration value="literal"/>
    6.32 +						<xs:enumeration value="host"/>
    6.33 +						<xs:enumeration value="port"/>
    6.34 +						<xs:enumeration value="env"/>
    6.35 +						<xs:enumeration value="dbProperty"/>
    6.36 +					</xs:restriction>
    6.37 +				</xs:simpleType>
    6.38 +			</xs:attribute>
    6.39 +		</xs:complexType>
    6.40 +	</xs:element>
    6.41 +	
    6.42  	<xs:element name="defaultFormatter" type="xs:string"/>
    6.43  	
    6.44  	<xs:element name="formatter">