diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java index 02071e9fcfd..4401a64e6f8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java @@ -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}. + *

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. *

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 unwrap(Class 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}. - *

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.