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 203 504c4ba56d1c
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
--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sun Jun 21 16:21:51 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 09:40:22 2015 +0200
@@ -17,6 +17,7 @@
  */
 package info.globalcode.sql.dk;
 
+import info.globalcode.sql.dk.configuration.CommandArgument;
 import info.globalcode.sql.dk.configuration.Configuration;
 import info.globalcode.sql.dk.configuration.ConfigurationException;
 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
@@ -24,6 +25,7 @@
 import info.globalcode.sql.dk.configuration.FormatterDefinition;
 import info.globalcode.sql.dk.configuration.Properties;
 import info.globalcode.sql.dk.configuration.Property;
+import info.globalcode.sql.dk.configuration.TunnelDefinition;
 import info.globalcode.sql.dk.formatting.ColumnsHeader;
 import info.globalcode.sql.dk.formatting.FakeSqlArray;
 import info.globalcode.sql.dk.formatting.Formatter;
@@ -197,6 +199,15 @@
 		} else {
 			for (DatabaseDefinition dd : configuredDatabases) {
 				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
+
+				final TunnelDefinition tunnel = dd.getTunnel();
+				if (tunnel != null) {
+					log.log(Level.INFO, "Tunnel command: {0}", tunnel.getCommand());
+					for (CommandArgument ca : Functions.notNull(tunnel.getArguments())) {
+						log.log(Level.INFO, "\targument: {0}/{1}", new Object[]{ca.getType(), ca.getValue()});
+					}
+				}
+
 			}
 		}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/CommandArgument.java	Sat Aug 15 09:40:22 2015 +0200
@@ -0,0 +1,82 @@
+/**
+ * SQL-DK
+ * Copyright © 2015 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class CommandArgument {
+
+	private String value;
+	private TYPE type;
+
+	@XmlEnum
+	public static enum TYPE {
+
+		/**
+		 * value = literal (text) argument
+		 */
+		@XmlEnumValue("literal")
+		LITERAL,
+		/**
+		 * value will be substituted by hostname or IP address of the DB server
+		 */
+		@XmlEnumValue("host")
+		HOST,
+		/**
+		 * value will be substituted by the port of the DB server
+		 */
+		@XmlEnumValue("port")
+		PORT,
+		/**
+		 * value will be substituted by environmental variable of given name
+		 */
+		@XmlEnumValue("env")
+		ENVIRONMENT_VARIABLE,
+		/**
+		 * value will be substituted by database property of given name
+		 */
+		@XmlEnumValue("dbProperty")
+		DB_PROPERTY;
+	}
+
+	@XmlValue
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+
+	@XmlAttribute(name = "type")
+	public TYPE getType() {
+		return type;
+	}
+
+	public void setType(TYPE type) {
+		this.type = type;
+	}
+
+}
--- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java	Sun Jun 21 16:21:51 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java	Sat Aug 15 09:40:22 2015 +0200
@@ -57,6 +57,10 @@
 	 * JDBC properties
 	 */
 	private Properties properties = new Properties();
+	/**
+	 * optional definition of tunnel to the remote database
+	 */
+	private TunnelDefinition tunnel;
 
 	@XmlElement(name = "name", namespace = CONFIGURATION)
 	@Override
@@ -112,6 +116,14 @@
 		this.properties = properties;
 	}
 
+	public TunnelDefinition getTunnel() {
+		return tunnel;
+	}
+
+	public void setTunnel(TunnelDefinition tunnel) {
+		this.tunnel = tunnel;
+	}
+
 	/**
 	 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
 	 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/TunnelDefinition.java	Sat Aug 15 09:40:22 2015 +0200
@@ -0,0 +1,51 @@
+/**
+ * SQL-DK
+ * Copyright © 2015 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
+import java.util.List;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class TunnelDefinition {
+
+	private String command;
+	private List<CommandArgument> arguments;
+
+	@XmlElement(name = "command", namespace = CONFIGURATION)
+	public String getCommand() {
+		return command;
+	}
+
+	public void setCommand(String command) {
+		this.command = command;
+	}
+
+	@XmlElement(name = "argument", namespace = CONFIGURATION)
+	public List<CommandArgument> getArguments() {
+		return arguments;
+	}
+
+	public void setArguments(List<CommandArgument> arguments) {
+		this.arguments = arguments;
+	}
+
+}
--- a/xml/config.rnc	Sun Jun 21 16:21:51 2015 +0200
+++ b/xml/config.rnc	Sat Aug 15 09:40:22 2015 +0200
@@ -28,7 +28,14 @@
 			element property {
 				attribute name { text },
 				text
-			}*
+			}*,
+			element tunnel {
+				element command { text },
+				element argument {
+					attribute type { "literal" | "host" | "port" | "env" | "dbProperty" }?,
+					text
+				}*
+			}?
 		}*,
 		
 		element defaultFormatter { text }?,
--- a/xml/config.xsd	Sun Jun 21 16:21:51 2015 +0200
+++ b/xml/config.xsd	Sat Aug 15 09:40:22 2015 +0200
@@ -41,6 +41,7 @@
 				<xs:element minOccurs="0" ref="c:password"/>
 				<xs:element minOccurs="0" ref="c:driver"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:property"/>
+				<xs:element minOccurs="0" ref="c:tunnel"/>
 			</xs:sequence>
 		</xs:complexType>
 	</xs:element>
@@ -57,6 +58,33 @@
 		</xs:complexType>
 	</xs:element>
 	
+	<xs:element name="tunnel">
+		<xs:complexType>
+			<xs:sequence>
+				<xs:element ref="c:command"/>
+				<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:argument"/>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+	
+	<xs:element name="command" type="xs:string"/>
+	
+	<xs:element name="argument">
+		<xs:complexType mixed="true">
+			<xs:attribute name="type">
+				<xs:simpleType>
+					<xs:restriction base="xs:token">
+						<xs:enumeration value="literal"/>
+						<xs:enumeration value="host"/>
+						<xs:enumeration value="port"/>
+						<xs:enumeration value="env"/>
+						<xs:enumeration value="dbProperty"/>
+					</xs:restriction>
+				</xs:simpleType>
+			</xs:attribute>
+		</xs:complexType>
+	</xs:element>
+	
 	<xs:element name="defaultFormatter" type="xs:string"/>
 	
 	<xs:element name="formatter">