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