franta-hg@26: /** franta-hg@26: * SQL-DK franta-hg@26: * Copyright © 2013 František Kučera (frantovo.cz) franta-hg@26: * franta-hg@26: * This program is free software: you can redistribute it and/or modify franta-hg@26: * it under the terms of the GNU General Public License as published by franta-hg@26: * the Free Software Foundation, either version 3 of the License, or franta-hg@26: * (at your option) any later version. franta-hg@26: * franta-hg@26: * This program is distributed in the hope that it will be useful, franta-hg@26: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@26: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@26: * GNU General Public License for more details. franta-hg@26: * franta-hg@26: * You should have received a copy of the GNU General Public License franta-hg@26: * along with this program. If not, see . franta-hg@26: */ franta-hg@26: package info.globalcode.sql.dk.configuration; franta-hg@26: franta-hg@30: import static info.globalcode.sql.dk.Xmlns.CONFIGURATION; franta-hg@27: import info.globalcode.sql.dk.DatabaseConnection; franta-hg@179: import info.globalcode.sql.dk.jmx.ConnectionManagement; franta-hg@29: import java.sql.SQLException; franta-hg@179: import java.util.logging.Logger; franta-hg@26: import javax.xml.bind.annotation.XmlElement; franta-hg@26: franta-hg@26: /** franta-hg@155: * Configured (but not yet connected) database connection. franta-hg@26: * franta-hg@26: * @author Ing. František Kučera (frantovo.cz) franta-hg@26: */ franta-hg@26: public class DatabaseDefinition implements NameIdentified { franta-hg@26: franta-hg@179: private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName()); franta-hg@194: /** franta-hg@194: * database name in SQL-DK configuration franta-hg@194: */ franta-hg@26: private String name; franta-hg@194: /** franta-hg@194: * JDBC URL franta-hg@194: */ franta-hg@26: private String url; franta-hg@194: /** franta-hg@194: * JDBC user name franta-hg@194: */ franta-hg@26: private String userName; franta-hg@194: /** franta-hg@194: * JDBC password franta-hg@194: */ franta-hg@26: private String password; franta-hg@194: /** franta-hg@194: * optional JDBC driver – if empty, the DriverManager is used to lookup specific Driver for franta-hg@194: * given URL franta-hg@194: */ franta-hg@194: private String driver; franta-hg@194: /** franta-hg@194: * JDBC properties franta-hg@194: */ franta-hg@104: private Properties properties = new Properties(); franta-hg@203: /** franta-hg@203: * optional definition of tunnel to the remote database franta-hg@203: */ franta-hg@203: private TunnelDefinition tunnel; franta-hg@26: franta-hg@30: @XmlElement(name = "name", namespace = CONFIGURATION) franta-hg@26: @Override franta-hg@26: public String getName() { franta-hg@26: return name; franta-hg@26: } franta-hg@26: franta-hg@26: public void setName(String name) { franta-hg@26: this.name = name; franta-hg@26: } franta-hg@26: franta-hg@30: @XmlElement(name = "url", namespace = CONFIGURATION) franta-hg@26: public String getUrl() { franta-hg@26: return url; franta-hg@26: } franta-hg@26: franta-hg@26: public void setUrl(String url) { franta-hg@26: this.url = url; franta-hg@26: } franta-hg@26: franta-hg@30: @XmlElement(name = "userName", namespace = CONFIGURATION) franta-hg@26: public String getUserName() { franta-hg@26: return userName; franta-hg@26: } franta-hg@26: franta-hg@26: public void setUserName(String userName) { franta-hg@26: this.userName = userName; franta-hg@26: } franta-hg@26: franta-hg@30: @XmlElement(name = "password", namespace = CONFIGURATION) franta-hg@26: public String getPassword() { franta-hg@26: return password; franta-hg@26: } franta-hg@26: franta-hg@26: public void setPassword(String password) { franta-hg@26: this.password = password; franta-hg@26: } franta-hg@26: franta-hg@194: public String getDriver() { franta-hg@194: return driver; franta-hg@194: } franta-hg@194: franta-hg@194: public void setDriver(String driver) { franta-hg@194: this.driver = driver; franta-hg@194: } franta-hg@194: franta-hg@104: @XmlElement(name = "property", namespace = CONFIGURATION) franta-hg@104: public Properties getProperties() { franta-hg@104: return properties; franta-hg@104: } franta-hg@104: franta-hg@104: public void setProperties(Properties properties) { franta-hg@104: this.properties = properties; franta-hg@104: } franta-hg@104: franta-hg@203: public TunnelDefinition getTunnel() { franta-hg@203: return tunnel; franta-hg@203: } franta-hg@203: franta-hg@203: public void setTunnel(TunnelDefinition tunnel) { franta-hg@203: this.tunnel = tunnel; franta-hg@203: } franta-hg@203: franta-hg@106: /** franta-hg@155: * @param properties ad-hoc properties from CLI options (for the JDBC driver) franta-hg@179: * @param jmxBean JMX management bean for progress reporting | null = disable JMX franta-hg@194: * @return franta-hg@188: * @throws java.sql.SQLException franta-hg@179: */ franta-hg@179: public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException { franta-hg@179: return new DatabaseConnection(this, properties, jmxBean); franta-hg@179: } franta-hg@179: franta-hg@179: /** franta-hg@188: * @param properties franta-hg@194: * @return franta-hg@188: * @throws java.sql.SQLException franta-hg@179: * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String) franta-hg@179: * With disabled JMX reporting. franta-hg@106: */ franta-hg@106: public DatabaseConnection connect(Properties properties) throws SQLException { franta-hg@179: return new DatabaseConnection(this, properties, null); franta-hg@26: } franta-hg@26: }