001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package test.org.mandarax.zkb;
019:
020: import java.io.PrintWriter;
021: import java.sql.SQLException;
022:
023: /**
024: * "Simulation" of a data source, not functional but with some properties a real
025: * implementaton probably has.
026: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
027: * @version 3.4 <7 March 05>
028: * @since 2.2
029: */
030: public class DummyDataSource implements javax.sql.DataSource,
031: java.io.Serializable {
032:
033: private Class driver = null;
034: private String connectString = "";
035: private String userName = "";
036: private String password = "";
037: private int loginTimeout = 1000;
038: private PrintWriter logWriter = null;
039:
040: /**
041: * Constructor.
042: */
043: public DummyDataSource() {
044: super ();
045: try {
046: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
047: } catch (Exception x) {
048: x.printStackTrace();
049: }
050: }
051:
052: /**
053: * Get a database connection.
054: * @return a database connection
055: */
056: public java.sql.Connection getConnection()
057: throws java.sql.SQLException {
058: return java.sql.DriverManager.getConnection("jdbc:odbc:test");
059: }
060:
061: /**
062: * Get a database connection.
063: * @return a database connection
064: * @param userName a user name
065: * @param password a password
066: */
067: public java.sql.Connection getConnection(String userName,
068: String password) throws java.sql.SQLException {
069: return java.sql.DriverManager.getConnection("jdbc:odbc:test",
070: userName, password);
071: }
072:
073: /**
074: * Get a connect string.
075: * @return a string
076: */
077: public java.lang.String getConnectString() {
078: return connectString;
079: }
080:
081: /**
082: * Get tehn login toimeout.
083: */
084: public int getLoginTimeout() throws SQLException {
085: return loginTimeout;
086: }
087:
088: /**
089: * Get the log writer.
090: */
091: public PrintWriter getLogWriter() throws SQLException {
092: return logWriter;
093: }
094:
095: /**
096: * Get the password.
097: * @return the database password
098: */
099: public String getPassword() {
100: return password;
101: }
102:
103: /**
104: * Get the user name for the database
105: * @return the user name
106: */
107: public String getUserName() {
108: return userName;
109: }
110:
111: /**
112: * Set the connect string.
113: * @param newConnectString java.lang.String
114: */
115: public void setConnectString(java.lang.String newConnectString) {
116: connectString = newConnectString;
117: }
118:
119: /**
120: * Set the login timeout.
121: * @param millis the time in milli seconds
122: */
123: public void setLoginTimeout(int millis) throws SQLException {
124: loginTimeout = millis;
125: }
126:
127: /**
128: * Set the log writer.
129: * @param writer a writer
130: */
131: public void setLogWriter(PrintWriter writer) throws SQLException {
132: logWriter = writer;
133: }
134:
135: /**
136: * Set a new password.
137: * @param newPassword a password
138: */
139: public void setPassword(String newPassword) {
140: password = newPassword;
141: }
142:
143: /**
144: * Set a user name.
145: * @param newUserName the user name
146: */
147: public void setUserName(String newUserName) {
148: userName = newUserName;
149: }
150:
151: /**
152: * Get a database driver class.
153: * @return a database driver
154: */
155: public Class getDriver() {
156: return driver;
157: }
158:
159: /**
160: * Set a new driver class.
161: * @param newDriver a jdbc driver class
162: */
163: public void setDriver(Class newDriver) {
164: driver = newDriver;
165: }
166:
167: /**
168: * Convert the object to a string.
169: * @return a string representation of this object
170: */
171: public String toString() {
172: return "data source dummy implementation for XKB testing only";
173: }
174:
175: /**
176: * Compares objects.
177: * @return a boolean
178: * @param obj another object
179: */
180: public boolean equals(Object obj) {
181: if (obj instanceof DummyDataSource) {
182: DummyDataSource ds = (DummyDataSource) obj;
183: boolean result = true;
184:
185: result = result && (driver == ds.driver);
186: result = result && (loginTimeout == ds.loginTimeout);
187: result = result
188: && ((connectString == null) ? ds.connectString == null
189: : connectString.equals(ds.connectString));
190: result = result
191: && ((userName == null) ? ds.userName == null
192: : userName.equals(ds.userName));
193: result = result
194: && ((password == null) ? ds.password == null
195: : password.equals(ds.password));
196: result = result
197: && ((logWriter == null) ? ds.logWriter == null
198: : logWriter.equals(ds.logWriter));
199:
200: return result;
201: }
202:
203: return false;
204: }
205:
206: /**
207: * Get the hash code of the object.
208: * @return a hash code
209: */
210: public int hashCode() {
211: return (connectString == null) ? 0 : connectString.hashCode();
212: }
213: }
|