01: /*
02: * Copyright 2006 Davide Deidda
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: /*
18: * TestDataSource.java
19: *
20: * Created on 9 aprile 2005, 13.10
21: */
22:
23: package it.biobytes.ammentos.test;
24:
25: import javax.sql.*;
26: import java.sql.*;
27: import java.io.*;
28:
29: /**
30: *
31: * @author davide
32: */
33: public class TestDataSource implements DataSource {
34: private int m_loginTimeout;
35: private PrintWriter m_out;
36: private String m_dbUrl;
37:
38: public TestDataSource() {
39: this ("jdbc:hsqldb:data/db/ammentos");
40: }
41:
42: public TestDataSource(String uri) {
43: m_dbUrl = uri;
44: try {
45: Class.forName("org.hsqldb.jdbcDriver");
46: } catch (Exception e) {
47: System.out.println("Database Driver not found");
48: System.exit(1);
49: }
50: }
51:
52: public void setLoginTimeout(int seconds) throws SQLException {
53: m_loginTimeout = seconds;
54: }
55:
56: public void setLogWriter(java.io.PrintWriter out)
57: throws SQLException {
58: m_out = out;
59: }
60:
61: public int getLoginTimeout() throws SQLException {
62: return m_loginTimeout;
63: }
64:
65: public java.io.PrintWriter getLogWriter() throws SQLException {
66: return m_out;
67: }
68:
69: public Connection getConnection(String username, String password)
70: throws SQLException {
71: return DriverManager.getConnection(m_dbUrl, username, password);
72: }
73:
74: public Connection getConnection() throws SQLException {
75: Connection res;
76: res = DriverManager.getConnection(m_dbUrl, "sa", "");
77: //System.out.println( "Connection: " + res );
78: return res;
79: }
80:
81: public Object unwrap(Class iface) throws SQLException {
82: throw new UnsupportedOperationException("Not supported yet.");
83: }
84:
85: public boolean isWrapperFor(Class iface) throws SQLException {
86: throw new UnsupportedOperationException("Not supported yet.");
87: }
88:
89: }
|