01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * DriverConnectionProvider.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.modules.misc.datafactory.sql;
30:
31: import java.sql.Connection;
32: import java.sql.DriverManager;
33: import java.sql.SQLException;
34: import java.util.Properties;
35:
36: /**
37: * Creation-Date: 07.04.2006, 15:04:26
38: *
39: * @author Thomas Morgner
40: */
41: public class DriverConnectionProvider implements ConnectionProvider {
42: private Properties properties;
43: private String url;
44: private String driver;
45:
46: public DriverConnectionProvider() {
47: this .properties = new Properties();
48: }
49:
50: public String getProperty(final String key) {
51: return properties.getProperty(key);
52: }
53:
54: public Object setProperty(final String key, final String value) {
55: return properties.setProperty(key, value);
56: }
57:
58: public String getUrl() {
59: return url;
60: }
61:
62: public void setUrl(final String url) {
63: this .url = url;
64: }
65:
66: public String getDriver() {
67: return driver;
68: }
69:
70: public void setDriver(final String driver) {
71: this .driver = driver;
72: }
73:
74: public Connection getConnection() throws SQLException {
75: if (url == null) {
76: throw new NullPointerException(
77: "URL must not be null when connecting"); //$NON-NLS-1$
78: }
79:
80: try {
81: if (driver != null) {
82: Class.forName(driver);
83: }
84: } catch (Exception e) {
85: throw new SQLException(
86: "Unable to load the driver", e.getMessage()); //$NON-NLS-1$
87: }
88:
89: return DriverManager.getConnection(url, properties);
90: }
91:
92: public String[] getPropertyNames() {
93: return (String[]) properties.keySet().toArray(
94: new String[properties.size()]);
95: }
96: }
|