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.xkb;
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 1.6
029: */
030: public class DummyDataSource implements javax.sql.DataSource {
031:
032: private Class driver = null;
033: private String connectString = "";
034: private String userName = "";
035: private String password = "";
036: private int loginTimeout = 1000;
037: private PrintWriter logWriter = null;
038:
039: /**
040: * Constructor.
041: */
042: public DummyDataSource() {
043: super ();
044: }
045:
046: /**
047: * Get a database connection.
048: * @return a database connection
049: */
050: public java.sql.Connection getConnection()
051: throws java.sql.SQLException {
052: throw new UnsupportedOperationException("This is just a dummy!");
053: }
054:
055: /**
056: * Get a database connection.
057: * @return a database connection
058: * @param userName a user name
059: * @param password a password
060: */
061: public java.sql.Connection getConnection(String userName,
062: String password) throws java.sql.SQLException {
063: throw new UnsupportedOperationException("This is just a dummy!");
064: }
065:
066: /**
067: * Get a connect string.
068: * @return a string
069: */
070: public java.lang.String getConnectString() {
071: return connectString;
072: }
073:
074: /**
075: * Get tehn login toimeout.
076: */
077: public int getLoginTimeout() throws SQLException {
078: return loginTimeout;
079: }
080:
081: /**
082: * Get the log writer.
083: */
084: public PrintWriter getLogWriter() throws SQLException {
085: return logWriter;
086: }
087:
088: /**
089: * Get the password.
090: * @return the database password
091: */
092: public String getPassword() {
093: return password;
094: }
095:
096: /**
097: * Get the user name for the database
098: * @return the user name
099: */
100: public String getUserName() {
101: return userName;
102: }
103:
104: /**
105: * Set the connect string.
106: * @param newConnectString java.lang.String
107: */
108: public void setConnectString(java.lang.String newConnectString) {
109: connectString = newConnectString;
110: }
111:
112: /**
113: * Set the login timeout.
114: * @param millis the time in milli seconds
115: */
116: public void setLoginTimeout(int millis) throws SQLException {
117: loginTimeout = millis;
118: }
119:
120: /**
121: * Set the log writer.
122: * @param writer a writer
123: */
124: public void setLogWriter(PrintWriter writer) throws SQLException {
125: logWriter = writer;
126: }
127:
128: /**
129: * Set a new password.
130: * @param newPassword a password
131: */
132: public void setPassword(String newPassword) {
133: password = newPassword;
134: }
135:
136: /**
137: * Set a user name.
138: * @param newUserName the user name
139: */
140: public void setUserName(String newUserName) {
141: userName = newUserName;
142: }
143:
144: /**
145: * Get a database driver class.
146: * @return a database driver
147: */
148: public Class getDriver() {
149: return driver;
150: }
151:
152: /**
153: * Set a new driver class.
154: * @param newDriver a jdbc driver class
155: */
156: public void setDriver(Class newDriver) {
157: driver = newDriver;
158: }
159:
160: /**
161: * Convert the object to a string.
162: * @return a string representation of this object
163: */
164: public String toString() {
165: return "data source dummy implementation for XKB testing only";
166: }
167:
168: /**
169: * Compares objects.
170: * @return a boolean
171: * @param obj another object
172: */
173: public boolean equals(Object obj) {
174: if (obj instanceof DummyDataSource) {
175: DummyDataSource ds = (DummyDataSource) obj;
176: boolean result = true;
177:
178: result = result && (driver == ds.driver);
179: result = result && (loginTimeout == ds.loginTimeout);
180: result = result
181: && ((connectString == null) ? ds.connectString == null
182: : connectString.equals(ds.connectString));
183: result = result
184: && ((userName == null) ? ds.userName == null
185: : userName.equals(ds.userName));
186: result = result
187: && ((password == null) ? ds.password == null
188: : password.equals(ds.password));
189: result = result
190: && ((logWriter == null) ? ds.logWriter == null
191: : logWriter.equals(ds.logWriter));
192:
193: return result;
194: }
195:
196: return false;
197: }
198:
199: /**
200: * Get the hash code of the object.
201: * @return a hash code
202: */
203: public int hashCode() {
204: return (connectString == null) ? 0 : connectString.hashCode();
205: }
206: }
|