Avoid reusing/rewriting the DB connection properties.
There was weird random errors while testing connection to multiple DB in parallel when one of them was meta connection to same DB connection.
Two kinds of exception: 1) missing password 2) „Passing DB password as CLI parameter is insecure!“
3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk.configuration;
20 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
21 import info.globalcode.sql.dk.DatabaseConnection;
22 import info.globalcode.sql.dk.jmx.ConnectionManagement;
23 import java.sql.SQLException;
24 import java.util.logging.Logger;
25 import javax.xml.bind.annotation.XmlElement;
28 * Configured (but not yet connected) database connection.
30 * @author Ing. František Kučera (frantovo.cz)
32 public class DatabaseDefinition implements NameIdentified {
34 private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName());
36 * database name in SQL-DK configuration
46 private String userName;
50 private String password;
52 * optional JDBC driver – if empty, the DriverManager is used to lookup specific Driver for
55 private String driver;
59 private Properties properties = new Properties();
61 * optional definition of tunnel to the remote database
63 private TunnelDefinition tunnel;
65 @XmlElement(name = "name", namespace = CONFIGURATION)
67 public String getName() {
71 public void setName(String name) {
75 @XmlElement(name = "url", namespace = CONFIGURATION)
76 public String getUrl() {
80 public void setUrl(String url) {
84 @XmlElement(name = "userName", namespace = CONFIGURATION)
85 public String getUserName() {
89 public void setUserName(String userName) {
90 this.userName = userName;
93 @XmlElement(name = "password", namespace = CONFIGURATION)
94 public String getPassword() {
98 public void setPassword(String password) {
99 this.password = password;
102 public String getDriver() {
106 public void setDriver(String driver) {
107 this.driver = driver;
110 @XmlElement(name = "property", namespace = CONFIGURATION)
111 public Properties getProperties() {
115 public void setProperties(Properties properties) {
116 this.properties = properties;
119 public TunnelDefinition getTunnel() {
123 public void setTunnel(TunnelDefinition tunnel) {
124 this.tunnel = tunnel;
128 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
129 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
131 * @throws java.sql.SQLException
133 public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException {
134 return new DatabaseConnection(this, properties, jmxBean);
140 * @throws java.sql.SQLException
141 * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String)
142 * With disabled JMX reporting.
144 public DatabaseConnection connect(Properties properties) throws SQLException {
145 return new DatabaseConnection(this, properties, null);