001
014
015 package com.liferay.portal.dao.jdbc.util;
016
017 import java.io.PrintWriter;
018
019 import java.sql.Connection;
020 import java.sql.SQLException;
021
022 import java.util.logging.Logger;
023
024 import javax.sql.DataSource;
025
026
029 public class DataSourceWrapper implements DataSource {
030
031 public DataSourceWrapper(DataSource dataSource) {
032 _dataSource = dataSource;
033 }
034
035 public Connection getConnection() throws SQLException {
036 return _dataSource.getConnection();
037 }
038
039 public Connection getConnection(String username, String password)
040 throws SQLException {
041
042 return _dataSource.getConnection(username, password);
043 }
044
045 public int getLoginTimeout() throws SQLException {
046 return _dataSource.getLoginTimeout();
047 }
048
049 public PrintWriter getLogWriter() throws SQLException {
050 return _dataSource.getLogWriter();
051 }
052
053 public Logger getParentLogger() {
054
055
056
057 throw new UnsupportedOperationException();
058 }
059
060 public DataSource getWrappedDataSource() {
061 return _dataSource;
062 }
063
064 public boolean isWrapperFor(Class<?> clazz) {
065
066
067
068 return DataSource.class.equals(clazz);
069 }
070
071 public void setLoginTimeout(int seconds) throws SQLException {
072 _dataSource.setLoginTimeout(seconds);
073 }
074
075 public void setLogWriter(PrintWriter out) throws SQLException {
076 _dataSource.setLogWriter(out);
077 }
078
079 public void setWrappedDataSource(DataSource wrappedDataSource) {
080 _dataSource = wrappedDataSource;
081 }
082
083 public <T> T unwrap(Class<T> clazz) throws SQLException {
084
085
086
087 if (!DataSource.class.equals(clazz)) {
088 throw new SQLException("Invalid class " + clazz);
089 }
090
091 return (T)this;
092 }
093
094 private volatile DataSource _dataSource;
095
096 }