AbstractRoutingDataSource consistently implements JDBC 4.0's Wrapper interface as well
Issue: SPR-9856
This commit is contained in:
parent
93aa411886
commit
9ff640a95d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -51,6 +51,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
|
||||
private DataSource resolvedDefaultDataSource;
|
||||
|
||||
|
||||
/**
|
||||
* Specify the map of target DataSources, with the lookup key as key.
|
||||
* The mapped value can either be a corresponding {@link javax.sql.DataSource}
|
||||
|
@ -121,6 +122,19 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the given lookup key object, as specified in the
|
||||
* {@link #setTargetDataSources targetDataSources} map, into
|
||||
* the actual lookup key to be used for matching with the
|
||||
* {@link #determineCurrentLookupKey() current lookup key}.
|
||||
* <p>The default implementation simply returns the given key as-is.
|
||||
* @param lookupKey the lookup key object as specified by the user
|
||||
* @return the lookup key as needed for matching
|
||||
*/
|
||||
protected Object resolveSpecifiedLookupKey(Object lookupKey) {
|
||||
return lookupKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified data source object into a DataSource instance.
|
||||
* <p>The default implementation handles DataSource instances and data source
|
||||
|
@ -152,6 +166,20 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
return determineTargetDataSource().getConnection(username, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface.isInstance(this)) {
|
||||
return (T) this;
|
||||
}
|
||||
return determineTargetDataSource().unwrap(iface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return (iface.isInstance(this) || determineTargetDataSource().isWrapperFor(iface));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current target DataSource. Determines the
|
||||
* {@link #determineCurrentLookupKey() current lookup key}, performs
|
||||
|
@ -173,20 +201,6 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the given lookup key object, as specified in the
|
||||
* {@link #setTargetDataSources targetDataSources} map, into
|
||||
* the actual lookup key to be used for matching with the
|
||||
* {@link #determineCurrentLookupKey() current lookup key}.
|
||||
* <p>The default implementation simply returns the given key as-is.
|
||||
* @param lookupKey the lookup key object as specified by the user
|
||||
* @return the lookup key as needed for matching
|
||||
*/
|
||||
protected Object resolveSpecifiedLookupKey(Object lookupKey) {
|
||||
return lookupKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current lookup key. This will typically be
|
||||
* implemented to check a thread-bound transaction context.
|
||||
|
|
Loading…
Reference in New Issue