Tweak PoolingDataSourceBean.getParentLogger()
Update PoolingDataSourceBean.getParentLogger() to directly call the method rather than use reflection. Also removed the logic from `DirectXADataSource` since any fix there should really be applied in the DataSource being wrapped (and not the wrapper). See gh-1518
This commit is contained in:
parent
565e449d89
commit
96dceb39a4
|
@ -17,19 +17,17 @@
|
|||
package org.springframework.boot.jta.bitronix;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.sql.XAConnection;
|
||||
import javax.sql.XADataSource;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.datasource.DelegatingDataSource;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import bitronix.tm.resource.common.ResourceBean;
|
||||
|
@ -86,7 +84,6 @@ public class PoolingDataSourceBean extends PoolingDataSource implements BeanName
|
|||
/**
|
||||
* Set the {@link XADataSource} directly, instead of calling
|
||||
* {@link #setClassName(String)}.
|
||||
*
|
||||
* @param dataSource the data source to use
|
||||
*/
|
||||
public void setDataSource(XADataSource dataSource) {
|
||||
|
@ -110,7 +107,13 @@ public class PoolingDataSourceBean extends PoolingDataSource implements BeanName
|
|||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return getParentLoggerForDataSource(this.dataSource);
|
||||
try {
|
||||
return ((DataSource) this).getParentLogger();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Work around https://jira.codehaus.org/browse/BTM-134
|
||||
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,33 +162,14 @@ public class PoolingDataSourceBean extends PoolingDataSource implements BeanName
|
|||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() {
|
||||
return getParentLoggerForDataSource(this.dataSource);
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return this.dataSource.getParentLogger();
|
||||
}
|
||||
|
||||
public XADataSource getDataSource() {
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* When running on Java 7 or later, delegates reflectively to the underlying
|
||||
* {@link javax.sql.DataSource} or, when running on Java 6, does what
|
||||
* {@link DelegatingDataSource} does
|
||||
*/
|
||||
private static Logger getParentLoggerForDataSource(XADataSource dataSource) {
|
||||
|
||||
Method getParentLoggerMethod = ReflectionUtils.findMethod(XADataSource.class,
|
||||
"getParentLogger");
|
||||
|
||||
if (getParentLoggerMethod != null) {
|
||||
try {
|
||||
return (Logger) getParentLoggerMethod.invoke(dataSource);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Swallow and continue
|
||||
}
|
||||
}
|
||||
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue