01: /*
02: * Copyright 2002-2007 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.springframework.jdbc.datasource;
18:
19: import java.io.PrintWriter;
20: import java.sql.SQLException;
21:
22: import javax.sql.DataSource;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26:
27: import org.springframework.util.Assert;
28:
29: /**
30: * Abstract base class for Spring's {@link javax.sql.DataSource}
31: * implementations, taking care of the padding.
32: *
33: * <p>'Padding' in the context of this class means default implementations
34: * for certain methods from the <code>DataSource</code> interface, such as
35: * {@link #getLoginTimeout()}, {@link #setLoginTimeout(int)}, and so forth.
36: *
37: * @author Juergen Hoeller
38: * @since 07.05.2003
39: * @see DriverManagerDataSource
40: */
41: public abstract class AbstractDataSource implements DataSource {
42:
43: /** Logger available to subclasses */
44: protected final Log logger = LogFactory.getLog(getClass());
45:
46: /**
47: * Returns 0, indicating the default system timeout is to be used.
48: */
49: public int getLoginTimeout() throws SQLException {
50: return 0;
51: }
52:
53: /**
54: * Setting a login timeout is not supported.
55: */
56: public void setLoginTimeout(int timeout) throws SQLException {
57: throw new UnsupportedOperationException("setLoginTimeout");
58: }
59:
60: /**
61: * LogWriter methods are not supported.
62: */
63: public PrintWriter getLogWriter() {
64: throw new UnsupportedOperationException("getLogWriter");
65: }
66:
67: /**
68: * LogWriter methods are not supported.
69: */
70: public void setLogWriter(PrintWriter pw) throws SQLException {
71: throw new UnsupportedOperationException("setLogWriter");
72: }
73:
74: //---------------------------------------------------------------------
75: // Implementation of JDBC 4.0's Wrapper interface
76: //---------------------------------------------------------------------
77:
78: public Object unwrap(Class iface) throws SQLException {
79: Assert.notNull(iface, "Interface argument must not be null");
80: if (!DataSource.class.equals(iface)) {
81: throw new SQLException(
82: "DataSource of type ["
83: + getClass().getName()
84: + "] can only be unwrapped as [javax.sql.DataSource], not as ["
85: + iface.getName());
86: }
87: return this ;
88: }
89:
90: public boolean isWrapperFor(Class iface) throws SQLException {
91: return DataSource.class.equals(iface);
92: }
93:
94: }
|