java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 25 Sep 2014 17:50:40 +0200
branchv_0
changeset 179 236332caeb29
parent 155 eb3676c6929b
child 184 53fb05ce504c
permissions -rw-r--r--
Basic JMX management/reporting – counters for commands and records
franta-hg@26
     1
/**
franta-hg@26
     2
 * SQL-DK
franta-hg@26
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@26
     4
 *
franta-hg@26
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@26
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@26
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@26
     8
 * (at your option) any later version.
franta-hg@26
     9
 *
franta-hg@26
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@26
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@26
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@26
    13
 * GNU General Public License for more details.
franta-hg@26
    14
 *
franta-hg@26
    15
 * You should have received a copy of the GNU General Public License
franta-hg@26
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@26
    17
 */
franta-hg@26
    18
package info.globalcode.sql.dk.configuration;
franta-hg@26
    19
franta-hg@30
    20
import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
franta-hg@27
    21
import info.globalcode.sql.dk.DatabaseConnection;
franta-hg@179
    22
import info.globalcode.sql.dk.jmx.ConnectionManagement;
franta-hg@179
    23
import java.lang.management.ManagementFactory;
franta-hg@29
    24
import java.sql.SQLException;
franta-hg@179
    25
import java.util.Hashtable;
franta-hg@179
    26
import java.util.logging.Level;
franta-hg@179
    27
import java.util.logging.Logger;
franta-hg@179
    28
import javax.management.MBeanServer;
franta-hg@179
    29
import javax.management.ObjectName;
franta-hg@26
    30
import javax.xml.bind.annotation.XmlElement;
franta-hg@26
    31
franta-hg@26
    32
/**
franta-hg@155
    33
 * Configured (but not yet connected) database connection.
franta-hg@26
    34
 *
franta-hg@26
    35
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@26
    36
 */
franta-hg@26
    37
public class DatabaseDefinition implements NameIdentified {
franta-hg@26
    38
franta-hg@179
    39
	private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName());
franta-hg@26
    40
	private String name;
franta-hg@26
    41
	private String url;
franta-hg@26
    42
	private String userName;
franta-hg@26
    43
	private String password;
franta-hg@104
    44
	private Properties properties = new Properties();
franta-hg@26
    45
franta-hg@30
    46
	@XmlElement(name = "name", namespace = CONFIGURATION)
franta-hg@26
    47
	@Override
franta-hg@26
    48
	public String getName() {
franta-hg@26
    49
		return name;
franta-hg@26
    50
	}
franta-hg@26
    51
franta-hg@26
    52
	public void setName(String name) {
franta-hg@26
    53
		this.name = name;
franta-hg@26
    54
	}
franta-hg@26
    55
franta-hg@30
    56
	@XmlElement(name = "url", namespace = CONFIGURATION)
franta-hg@26
    57
	public String getUrl() {
franta-hg@26
    58
		return url;
franta-hg@26
    59
	}
franta-hg@26
    60
franta-hg@26
    61
	public void setUrl(String url) {
franta-hg@26
    62
		this.url = url;
franta-hg@26
    63
	}
franta-hg@26
    64
franta-hg@30
    65
	@XmlElement(name = "userName", namespace = CONFIGURATION)
franta-hg@26
    66
	public String getUserName() {
franta-hg@26
    67
		return userName;
franta-hg@26
    68
	}
franta-hg@26
    69
franta-hg@26
    70
	public void setUserName(String userName) {
franta-hg@26
    71
		this.userName = userName;
franta-hg@26
    72
	}
franta-hg@26
    73
franta-hg@30
    74
	@XmlElement(name = "password", namespace = CONFIGURATION)
franta-hg@26
    75
	public String getPassword() {
franta-hg@26
    76
		return password;
franta-hg@26
    77
	}
franta-hg@26
    78
franta-hg@26
    79
	public void setPassword(String password) {
franta-hg@26
    80
		this.password = password;
franta-hg@26
    81
	}
franta-hg@26
    82
franta-hg@104
    83
	@XmlElement(name = "property", namespace = CONFIGURATION)
franta-hg@104
    84
	public Properties getProperties() {
franta-hg@104
    85
		return properties;
franta-hg@104
    86
	}
franta-hg@104
    87
franta-hg@104
    88
	public void setProperties(Properties properties) {
franta-hg@104
    89
		this.properties = properties;
franta-hg@104
    90
	}
franta-hg@104
    91
franta-hg@106
    92
	/**
franta-hg@155
    93
	 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
franta-hg@179
    94
	 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
franta-hg@179
    95
	 */
franta-hg@179
    96
	public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException {
franta-hg@179
    97
		return new DatabaseConnection(this, properties, jmxBean);
franta-hg@179
    98
	}
franta-hg@179
    99
franta-hg@179
   100
	/**
franta-hg@179
   101
	 * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String)
franta-hg@179
   102
	 * With disabled JMX reporting.
franta-hg@106
   103
	 */
franta-hg@106
   104
	public DatabaseConnection connect(Properties properties) throws SQLException {
franta-hg@179
   105
		return new DatabaseConnection(this, properties, null);
franta-hg@26
   106
	}
franta-hg@26
   107
}