java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/DatabaseDefinition.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:43:08 +0200
branchv_0
changeset 250 aae5009bd0af
parent 238 4a1864c3e867
permissions -rw-r--r--
fix license version: GNU GPLv3
     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, version 3 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    17 package info.globalcode.sql.dk.configuration;
    18 
    19 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
    20 import info.globalcode.sql.dk.DatabaseConnection;
    21 import info.globalcode.sql.dk.jmx.ConnectionManagement;
    22 import java.sql.SQLException;
    23 import java.util.logging.Logger;
    24 import javax.xml.bind.annotation.XmlElement;
    25 
    26 /**
    27  * Configured (but not yet connected) database connection.
    28  *
    29  * @author Ing. František Kučera (frantovo.cz)
    30  */
    31 public class DatabaseDefinition implements NameIdentified {
    32 
    33 	private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName());
    34 	/**
    35 	 * database name in SQL-DK configuration
    36 	 */
    37 	private String name;
    38 	/**
    39 	 * JDBC URL
    40 	 */
    41 	private String url;
    42 	/**
    43 	 * JDBC user name
    44 	 */
    45 	private String userName;
    46 	/**
    47 	 * JDBC password
    48 	 */
    49 	private String password;
    50 	/**
    51 	 * optional JDBC driver – if empty, the DriverManager is used to lookup specific Driver for
    52 	 * given URL
    53 	 */
    54 	private String driver;
    55 	/**
    56 	 * JDBC properties
    57 	 */
    58 	private Properties properties = new Properties();
    59 	/**
    60 	 * optional definition of tunnel to the remote database
    61 	 */
    62 	private TunnelDefinition tunnel;
    63 
    64 	@XmlElement(name = "name", namespace = CONFIGURATION)
    65 	@Override
    66 	public String getName() {
    67 		return name;
    68 	}
    69 
    70 	public void setName(String name) {
    71 		this.name = name;
    72 	}
    73 
    74 	@XmlElement(name = "url", namespace = CONFIGURATION)
    75 	public String getUrl() {
    76 		return url;
    77 	}
    78 
    79 	public void setUrl(String url) {
    80 		this.url = url;
    81 	}
    82 
    83 	@XmlElement(name = "userName", namespace = CONFIGURATION)
    84 	public String getUserName() {
    85 		return userName;
    86 	}
    87 
    88 	public void setUserName(String userName) {
    89 		this.userName = userName;
    90 	}
    91 
    92 	@XmlElement(name = "password", namespace = CONFIGURATION)
    93 	public String getPassword() {
    94 		return password;
    95 	}
    96 
    97 	public void setPassword(String password) {
    98 		this.password = password;
    99 	}
   100 
   101 	public String getDriver() {
   102 		return driver;
   103 	}
   104 
   105 	public void setDriver(String driver) {
   106 		this.driver = driver;
   107 	}
   108 
   109 	@XmlElement(name = "property", namespace = CONFIGURATION)
   110 	public Properties getProperties() {
   111 		return properties;
   112 	}
   113 
   114 	public void setProperties(Properties properties) {
   115 		this.properties = properties;
   116 	}
   117 
   118 	public TunnelDefinition getTunnel() {
   119 		return tunnel;
   120 	}
   121 
   122 	public void setTunnel(TunnelDefinition tunnel) {
   123 		this.tunnel = tunnel;
   124 	}
   125 
   126 	/**
   127 	 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
   128 	 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
   129 	 * @return
   130 	 * @throws java.sql.SQLException
   131 	 */
   132 	public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException {
   133 		return new DatabaseConnection(this, properties, jmxBean);
   134 	}
   135 
   136 	/**
   137 	 * @param properties
   138 	 * @return
   139 	 * @throws java.sql.SQLException
   140 	 * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String)
   141 	 * With disabled JMX reporting.
   142 	 */
   143 	public DatabaseConnection connect(Properties properties) throws SQLException {
   144 		return new DatabaseConnection(this, properties, null);
   145 	}
   146 }