author | František Kučera <franta-hg@frantovo.cz> |
Sun, 30 Aug 2015 02:28:15 +0200 | |
branch | v_0 |
changeset 224 | 36db9fd27436 |
parent 203 | 504c4ba56d1c |
permissions | -rw-r--r-- |
26 | 1 |
/** |
2 |
* SQL-DK |
|
3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
|
4 |
* |
|
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. |
|
9 |
* |
|
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. |
|
14 |
* |
|
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/>. |
|
17 |
*/ |
|
18 |
package info.globalcode.sql.dk.configuration; |
|
19 |
||
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
20 |
import static info.globalcode.sql.dk.Xmlns.CONFIGURATION; |
27
24aa5199bfd6
DatabaseConnection: just change package
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
21 |
import info.globalcode.sql.dk.DatabaseConnection; |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
22 |
import info.globalcode.sql.dk.jmx.ConnectionManagement; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
23 |
import java.sql.SQLException; |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
24 |
import java.util.logging.Logger; |
26 | 25 |
import javax.xml.bind.annotation.XmlElement; |
26 |
||
27 |
/** |
|
155 | 28 |
* Configured (but not yet connected) database connection. |
26 | 29 |
* |
30 |
* @author Ing. František Kučera (frantovo.cz) |
|
31 |
*/ |
|
32 |
public class DatabaseDefinition implements NameIdentified { |
|
33 |
||
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
34 |
private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName()); |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
35 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
36 |
* database name in SQL-DK configuration |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
37 |
*/ |
26 | 38 |
private String name; |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
39 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
40 |
* JDBC URL |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
41 |
*/ |
26 | 42 |
private String url; |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
43 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
44 |
* JDBC user name |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
45 |
*/ |
26 | 46 |
private String userName; |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
47 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
48 |
* JDBC password |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
49 |
*/ |
26 | 50 |
private String password; |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
51 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
52 |
* optional JDBC driver – if empty, the DriverManager is used to lookup specific Driver for |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
53 |
* given URL |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
54 |
*/ |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
55 |
private String driver; |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
56 |
/** |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
57 |
* JDBC properties |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
58 |
*/ |
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
59 |
private Properties properties = new Properties(); |
203
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
60 |
/** |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
61 |
* optional definition of tunnel to the remote database |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
62 |
*/ |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
63 |
private TunnelDefinition tunnel; |
26 | 64 |
|
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
65 |
@XmlElement(name = "name", namespace = CONFIGURATION) |
26 | 66 |
@Override |
67 |
public String getName() { |
|
68 |
return name; |
|
69 |
} |
|
70 |
||
71 |
public void setName(String name) { |
|
72 |
this.name = name; |
|
73 |
} |
|
74 |
||
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
75 |
@XmlElement(name = "url", namespace = CONFIGURATION) |
26 | 76 |
public String getUrl() { |
77 |
return url; |
|
78 |
} |
|
79 |
||
80 |
public void setUrl(String url) { |
|
81 |
this.url = url; |
|
82 |
} |
|
83 |
||
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
84 |
@XmlElement(name = "userName", namespace = CONFIGURATION) |
26 | 85 |
public String getUserName() { |
86 |
return userName; |
|
87 |
} |
|
88 |
||
89 |
public void setUserName(String userName) { |
|
90 |
this.userName = userName; |
|
91 |
} |
|
92 |
||
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
93 |
@XmlElement(name = "password", namespace = CONFIGURATION) |
26 | 94 |
public String getPassword() { |
95 |
return password; |
|
96 |
} |
|
97 |
||
98 |
public void setPassword(String password) { |
|
99 |
this.password = password; |
|
100 |
} |
|
101 |
||
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
102 |
public String getDriver() { |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
103 |
return driver; |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
104 |
} |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
105 |
|
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
106 |
public void setDriver(String driver) { |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
107 |
this.driver = driver; |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
108 |
} |
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
109 |
|
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
110 |
@XmlElement(name = "property", namespace = CONFIGURATION) |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
111 |
public Properties getProperties() { |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
112 |
return properties; |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
113 |
} |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
114 |
|
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
115 |
public void setProperties(Properties properties) { |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
116 |
this.properties = properties; |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
117 |
} |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
118 |
|
203
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
119 |
public TunnelDefinition getTunnel() { |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
120 |
return tunnel; |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
121 |
} |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
122 |
|
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
123 |
public void setTunnel(TunnelDefinition tunnel) { |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
124 |
this.tunnel = tunnel; |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
125 |
} |
504c4ba56d1c
connection tunnelling: configuration and logging
František Kučera <franta-hg@frantovo.cz>
parents:
194
diff
changeset
|
126 |
|
106
e9c3583580c8
use database properties
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
127 |
/** |
155 | 128 |
* @param properties ad-hoc properties from CLI options (for the JDBC driver) |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
129 |
* @param jmxBean JMX management bean for progress reporting | null = disable JMX |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
130 |
* @return |
188
54bacc7ed42b
jdbc-dk-driver: include main project sources
František Kučera <franta-hg@frantovo.cz>
parents:
184
diff
changeset
|
131 |
* @throws java.sql.SQLException |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
132 |
*/ |
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
133 |
public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException { |
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
134 |
return new DatabaseConnection(this, properties, jmxBean); |
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
135 |
} |
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
136 |
|
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
137 |
/** |
188
54bacc7ed42b
jdbc-dk-driver: include main project sources
František Kučera <franta-hg@frantovo.cz>
parents:
184
diff
changeset
|
138 |
* @param properties |
194
629c9c7eab01
JDBC driver class can be specified in the database configuration as an optional parameter (useful especially while embedding jdbc-dk-driver into other application that does not support automatic driver discovery)
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
139 |
* @return |
188
54bacc7ed42b
jdbc-dk-driver: include main project sources
František Kučera <franta-hg@frantovo.cz>
parents:
184
diff
changeset
|
140 |
* @throws java.sql.SQLException |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
141 |
* @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String) |
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
142 |
* With disabled JMX reporting. |
106
e9c3583580c8
use database properties
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
143 |
*/ |
e9c3583580c8
use database properties
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
144 |
public DatabaseConnection connect(Properties properties) throws SQLException { |
179
236332caeb29
Basic JMX management/reporting – counters for commands and records
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
145 |
return new DatabaseConnection(this, properties, null); |
26 | 146 |
} |
147 |
} |