01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: DriverManagerDataSource.java,v 1.4 2003/05/24 03:28:35 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo;
12:
13: import java.io.PrintWriter;
14: import java.sql.Connection;
15: import java.sql.DriverManager;
16: import java.sql.SQLException;
17: import javax.jdo.JDOFatalUserException;
18: import javax.sql.DataSource;
19:
20: public class DriverManagerDataSource implements DataSource {
21: private final String driverName;
22: private final String URL;
23:
24: public DriverManagerDataSource(String driverName, String URL) {
25: this .driverName = driverName;
26: this .URL = URL;
27:
28: if (driverName != null) {
29: try {
30: Class.forName(driverName).newInstance();
31: } catch (Exception e) {
32: throw new JDOFatalUserException("Invalid driver class "
33: + driverName, e);
34: }
35: }
36: }
37:
38: public Connection getConnection() throws SQLException {
39: return DriverManager.getConnection(URL);
40: }
41:
42: public Connection getConnection(String userName, String password)
43: throws SQLException {
44: return DriverManager.getConnection(URL, userName, password);
45: }
46:
47: public PrintWriter getLogWriter() throws SQLException {
48: return DriverManager.getLogWriter();
49: }
50:
51: public void setLogWriter(PrintWriter out) throws SQLException {
52: DriverManager.setLogWriter(out);
53: }
54:
55: public int getLoginTimeout() throws SQLException {
56: return DriverManager.getLoginTimeout();
57: }
58:
59: public void setLoginTimeout(int seconds) throws SQLException {
60: DriverManager.setLoginTimeout(seconds);
61: }
62:
63: public boolean equals(Object obj) {
64: if (obj == this )
65: return true;
66:
67: if (!(obj instanceof DriverManagerDataSource))
68: return false;
69:
70: DriverManagerDataSource dmds = (DriverManagerDataSource) obj;
71:
72: if (driverName == null) {
73: if (dmds.driverName != null)
74: return false;
75: } else if (!driverName.equals(dmds.driverName))
76: return false;
77:
78: if (URL == null) {
79: if (dmds.URL != null)
80: return false;
81: } else if (!URL.equals(dmds.URL))
82: return false;
83:
84: return true;
85: }
86:
87: public int hashCode() {
88: return (driverName == null ? 0 : driverName.hashCode())
89: ^ (URL == null ? 0 : URL.hashCode());
90: }
91: }
|