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 @Override
036 public Connection getConnection() throws SQLException {
037 return _dataSource.getConnection();
038 }
039
040 @Override
041 public Connection getConnection(String username, String password)
042 throws SQLException {
043
044 return _dataSource.getConnection(username, password);
045 }
046
047 @Override
048 public int getLoginTimeout() throws SQLException {
049 return _dataSource.getLoginTimeout();
050 }
051
052 @Override
053 public PrintWriter getLogWriter() throws SQLException {
054 return _dataSource.getLogWriter();
055 }
056
057 @Override
058 public Logger getParentLogger() {
059 throw new UnsupportedOperationException();
060 }
061
062 public DataSource getWrappedDataSource() {
063 return _dataSource;
064 }
065
066 @Override
067 public boolean isWrapperFor(Class<?> clazz) {
068
069
070
071 return DataSource.class.equals(clazz);
072 }
073
074 @Override
075 public void setLoginTimeout(int seconds) throws SQLException {
076 _dataSource.setLoginTimeout(seconds);
077 }
078
079 @Override
080 public void setLogWriter(PrintWriter out) throws SQLException {
081 _dataSource.setLogWriter(out);
082 }
083
084 public void setWrappedDataSource(DataSource wrappedDataSource) {
085 _dataSource = wrappedDataSource;
086 }
087
088 @Override
089 public <T> T unwrap(Class<T> clazz) throws SQLException {
090
091
092
093 if (!DataSource.class.equals(clazz)) {
094 throw new SQLException("Invalid class " + clazz);
095 }
096
097 return (T)this;
098 }
099
100 private volatile DataSource _dataSource;
101
102 }