01: package com.jat.integration.db;
02:
03: import java.sql.Connection;
04: import java.sql.DriverManager;
05: import java.sql.SQLException;
06: import java.util.Hashtable;
07:
08: import com.jat.core.config.Config;
09: import com.jat.core.log.LogManager;
10: import com.jat.integration.DataSource;
11: import com.jat.integration.IntegrationException;
12:
13: /**
14: * <p>Title: JAT</p>
15: * <p>Description: This class implements a database access through JDBC.
16: * </p>
17: * <p><b>Configuration:</b><br/>
18: * In the data source name section put the following parameters:
19: * <ul>
20: * <li><b>driver</b> the JDBC driver class</li>
21: * <li><b>URL</b> the JDBC URL to access to your database</li>
22: * <li>query definition (see query configuration in {@link com.jat.integration.db.GenericDatabaseDataSource} for details)</li>
23: * </ul>
24: * <i>Example:</i>
25: * <blockquote>
26: * [<i>myDataSourceName</i>]<br/>
27: * driver = <i>sun.jdbc.odbc.JdbcOdbcDriver</i><br/>
28: * url = <i>jdbc:odbc:MyDatabase</i><br/>
29: * query1.name = <i>myQueryName</i><br/>
30: * query1.value = <i>select * from dual</i>
31: * </blockquote>
32: * </p>
33: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
34: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
35: * @author stf
36: * @version 1.2
37: * @since 1.2
38: * @see com.jat.integration.DataSource
39: * @see com.jat.integration.db.GenericDatabaseDataSource
40: */
41:
42: public class JdbcDataSource extends GenericDatabaseDataSource implements
43: DataSource {
44:
45: public final static String CONFIG_DRIVER = "driver";
46: public final static String CONFIG_URL = "url";
47:
48: protected void initDataSource() throws IntegrationException {
49: LogManager.sendDebug(this .getClass().getName()
50: + "::initDataSource: start");
51: try {
52: this .driver = Config.getCurrent().getValue(this .getName(),
53: CONFIG_DRIVER);
54: LogManager.sendDebug(this .getClass().getName()
55: + "::initDataSource: driver: " + this .driver);
56: this .url = Config.getCurrent().getValue(this .getName(),
57: CONFIG_URL);
58: LogManager.sendDebug(this .getClass().getName()
59: + "::initDataSource: url: " + this .url);
60: Class.forName(new String(this .driver));
61: } catch (ClassNotFoundException cnfex) {
62: LogManager.sendError(this .getClass().getName()
63: + "::initDataSource: Data source '"
64: + this .getName() + "': Cannot load driver '"
65: + driver + "': " + cnfex);
66: throw new IntegrationException(this .getClass().getName()
67: + "::initDataSource: Data source '"
68: + this .getName() + "': Cannot load driver '"
69: + driver + "': " + cnfex);
70: } catch (Exception ex) {
71: LogManager.sendError(this .getClass().getName()
72: + "::initDataSource: Data source '"
73: + this .getName() + "': exception: " + ex);
74: throw new IntegrationException(this .getClass().getName()
75: + "::initDataSource: Data source '"
76: + this .getName() + "':exception: " + ex);
77: }
78: LogManager.sendDebug(this .getClass().getName()
79: + "::initDataSource: end");
80: }
81:
82: protected Hashtable putInitProperties(Hashtable hash)
83: throws Exception {
84: hash.put(CONFIG_DRIVER, this .driver);
85: hash.put(CONFIG_URL, this .url);
86: return hash;
87: }
88:
89: protected Connection getConnection() throws SQLException {
90: Connection con = DriverManager.getConnection(this .url);
91: return con;
92: }
93:
94: protected String url;
95: protected String driver;
96: }
|