java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 16 May 2015 23:58:06 +0200
branchv_0
changeset 191 862d0a8747ac
parent 188 54bacc7ed42b
child 194 629c9c7eab01
permissions -rw-r--r--
avoid NullPointerException (value = null) while duplicating to java.util.Properties
     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 
    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;
    26 
    27 /**
    28  * Configured (but not yet connected) database connection.
    29  *
    30  * @author Ing. František Kučera (frantovo.cz)
    31  */
    32 public class DatabaseDefinition implements NameIdentified {
    33 
    34 	private static final Logger log = Logger.getLogger(DatabaseDefinition.class.getName());
    35 	private String name;
    36 	private String url;
    37 	private String userName;
    38 	private String password;
    39 	private Properties properties = new Properties();
    40 
    41 	@XmlElement(name = "name", namespace = CONFIGURATION)
    42 	@Override
    43 	public String getName() {
    44 		return name;
    45 	}
    46 
    47 	public void setName(String name) {
    48 		this.name = name;
    49 	}
    50 
    51 	@XmlElement(name = "url", namespace = CONFIGURATION)
    52 	public String getUrl() {
    53 		return url;
    54 	}
    55 
    56 	public void setUrl(String url) {
    57 		this.url = url;
    58 	}
    59 
    60 	@XmlElement(name = "userName", namespace = CONFIGURATION)
    61 	public String getUserName() {
    62 		return userName;
    63 	}
    64 
    65 	public void setUserName(String userName) {
    66 		this.userName = userName;
    67 	}
    68 
    69 	@XmlElement(name = "password", namespace = CONFIGURATION)
    70 	public String getPassword() {
    71 		return password;
    72 	}
    73 
    74 	public void setPassword(String password) {
    75 		this.password = password;
    76 	}
    77 
    78 	@XmlElement(name = "property", namespace = CONFIGURATION)
    79 	public Properties getProperties() {
    80 		return properties;
    81 	}
    82 
    83 	public void setProperties(Properties properties) {
    84 		this.properties = properties;
    85 	}
    86 
    87 	/**
    88 	 * @param properties ad-hoc properties from CLI options (for the JDBC driver)
    89 	 * @param jmxBean JMX management bean for progress reporting | null = disable JMX
    90 	 * @return 
    91 	 * @throws java.sql.SQLException
    92 	 */
    93 	public DatabaseConnection connect(Properties properties, ConnectionManagement jmxBean) throws SQLException {
    94 		return new DatabaseConnection(this, properties, jmxBean);
    95 	}
    96 
    97 	/**
    98 	 * @param properties
    99 	 * @return 
   100 	 * @throws java.sql.SQLException
   101 	 * @see #connect(info.globalcode.sql.dk.configuration.Properties, java.lang.String)
   102 	 * With disabled JMX reporting.
   103 	 */
   104 	public DatabaseConnection connect(Properties properties) throws SQLException {
   105 		return new DatabaseConnection(this, properties, null);
   106 	}
   107 }