# HG changeset patch # User František Kučera # Date 1439624422 -7200 # Node ID 504c4ba56d1cc46135ce7e05c79dd210055d0daf # Parent 01078e09b85b70e7de50f0ea5b9adf057f28b6a2 connection tunnelling: configuration and logging diff -r 01078e09b85b -r 504c4ba56d1c java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- 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()}); + } + } + } } diff -r 01078e09b85b -r 504c4ba56d1c java/sql-dk/src/info/globalcode/sql/dk/configuration/CommandArgument.java --- /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 . + */ +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; + } + +} diff -r 01078e09b85b -r 504c4ba56d1c java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java --- 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 diff -r 01078e09b85b -r 504c4ba56d1c java/sql-dk/src/info/globalcode/sql/dk/configuration/TunnelDefinition.java --- /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 . + */ +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 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 getArguments() { + return arguments; + } + + public void setArguments(List arguments) { + this.arguments = arguments; + } + +} diff -r 01078e09b85b -r 504c4ba56d1c xml/config.rnc --- 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 }?, diff -r 01078e09b85b -r 504c4ba56d1c xml/config.xsd --- 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 @@ + @@ -57,6 +58,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +