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: * BaseDataSource.java
19: *
20: * Created on 6 maggio 2005, 20.38
21: */
22:
23: package it.biobytes.ammentos;
24:
25: import javax.sql.*;
26: import java.sql.*;
27: import java.io.*;
28:
29: /**
30: *
31: * @author davide
32: */
33: public class BaseDataSource implements DataSource {
34: private int m_loginTimeout;
35: private PrintWriter m_out;
36: private String m_dbUrl;
37: private String m_user;
38: private String m_password;
39:
40: public BaseDataSource(String driver, String dbUrl, String user,
41: String password) {
42: m_dbUrl = dbUrl;
43: m_user = user;
44: m_password = password;
45: try {
46: Class.forName(driver);
47: } catch (Exception e) {
48: System.out.println("Database Driver not found: " + driver);
49: System.exit(1);
50: }
51: }
52:
53: public void setLoginTimeout(int seconds) throws SQLException {
54: m_loginTimeout = seconds;
55: }
56:
57: public void setLogWriter(java.io.PrintWriter out)
58: throws SQLException {
59: m_out = out;
60: }
61:
62: public int getLoginTimeout() throws SQLException {
63: return m_loginTimeout;
64: }
65:
66: public java.io.PrintWriter getLogWriter() throws SQLException {
67: return m_out;
68: }
69:
70: public Connection getConnection(String user, String password)
71: throws SQLException {
72: return DriverManager.getConnection(m_dbUrl, user, password);
73: }
74:
75: public Connection getConnection() throws SQLException {
76: return DriverManager.getConnection(m_dbUrl, m_user, m_password);
77: }
78:
79: public Object unwrap(Class iface) throws SQLException {
80: throw new UnsupportedOperationException("Not supported yet.");
81: }
82:
83: public boolean isWrapperFor(Class iface) throws SQLException {
84: throw new UnsupportedOperationException("Not supported yet.");
85: }
86:
87: }
|