01: /*
02: * Copyright 2004-2006 the original author or authors.
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: package org.compass.gps.device.jdbc.datasource;
18:
19: import java.io.PrintWriter;
20: import java.sql.SQLException;
21: import javax.sql.DataSource;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25:
26: /**
27: * Abstract base class for Spring's DataSource implementations, taking care of
28: * the "uninteresting" glue.
29: *
30: * <p>
31: * Taken from Spring.
32: *
33: * @author kimchy
34: * @see DriverManagerDataSource
35: */
36: public abstract class AbstractDataSource implements DataSource {
37:
38: protected final Log log = LogFactory.getLog(getClass());
39:
40: /**
41: * Returns 0: means use default system timeout.
42: */
43: public int getLoginTimeout() throws SQLException {
44: return 0;
45: }
46:
47: public void setLoginTimeout(int timeout) throws SQLException {
48: throw new UnsupportedOperationException("setLoginTimeout");
49: }
50:
51: /**
52: * LogWriter methods are unsupported.
53: */
54: public PrintWriter getLogWriter() {
55: throw new UnsupportedOperationException("getLogWriter");
56: }
57:
58: /**
59: * LogWriter methods are unsupported.
60: */
61: public void setLogWriter(PrintWriter pw) throws SQLException {
62: throw new UnsupportedOperationException("setLogWriter");
63: }
64:
65: //---------------------------------------------------------------------
66: // Implementation of JDBC 4.0's Wrapper interface
67: //---------------------------------------------------------------------
68:
69: public Object unwrap(Class iface) throws SQLException {
70: if (!DataSource.class.equals(iface)) {
71: throw new SQLException(
72: "DataSource of type ["
73: + getClass().getName()
74: + "] can only be unwrapped as [javax.sql.DataSource], not as ["
75: + iface.getName());
76: }
77: return this ;
78: }
79:
80: public boolean isWrapperFor(Class iface) throws SQLException {
81: return DataSource.class.equals(iface);
82: }
83:
84: }
|