diff -r 7e08730da258 -r 4a1864c3e867 java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/DatabaseDefinition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/DatabaseDefinition.java Mon Mar 04 20:15:24 2019 +0100 @@ -0,0 +1,147 @@ +/** + * SQL-DK + * Copyright © 2013 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 info.globalcode.sql.dk.DatabaseConnection; +import info.globalcode.sql.dk.jmx.ConnectionManagement; +import java.sql.SQLException; +import java.util.logging.Logger; +import javax.xml.bind.annotation.XmlElement; + +/** + * Configured (but not yet connected) database connection. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class DatabaseDefinition implements NameIdentified { + + private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName()); + /** + * database name in SQL-DK configuration + */ + private String name; + /** + * JDBC URL + */ + private String url; + /** + * JDBC user name + */ + private String userName; + /** + * JDBC password + */ + private String password; + /** + * optional JDBC driver – if empty, the DriverManager is used to lookup specific Driver for + * given URL + */ + private String driver; + /** + * JDBC properties + */ + private Properties properties = new Properties(); + /** + * optional definition of tunnel to the remote database + */ + private TunnelDefinition tunnel; + + @XmlElement(name = "name", namespace = CONFIGURATION) + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement(name = "url", namespace = CONFIGURATION) + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @XmlElement(name = "userName", namespace = CONFIGURATION) + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @XmlElement(name = "password", namespace = CONFIGURATION) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getDriver() { + return driver; + } + + public void setDriver(String driver) { + this.driver = driver; + } + + @XmlElement(name = "property", namespace = CONFIGURATION) + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + 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 + * @return + * @throws java.sql.SQLException + */ + public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException { + return new DatabaseConnection(this, properties, jmxBean); + } + + /** + * @param properties + * @return + * @throws java.sql.SQLException + * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String) + * With disabled JMX reporting. + */ + public DatabaseConnection connect(Properties properties) throws SQLException { + return new DatabaseConnection(this, properties, null); + } +}