avoid hard-coded AOP dependency for ScopedObject check
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2687 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
53a71fe962
commit
5b59b9a0dc
|
|
@ -21,9 +21,10 @@ import java.util.List;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.aop.scope.ScopedObject;
|
||||||
import org.springframework.core.InfrastructureProxy;
|
import org.springframework.core.InfrastructureProxy;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.aop.scope.ScopedObject;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for triggering specific {@link TransactionSynchronization}
|
* Utility methods for triggering specific {@link TransactionSynchronization}
|
||||||
|
|
@ -38,6 +39,9 @@ public abstract class TransactionSynchronizationUtils {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(TransactionSynchronizationUtils.class);
|
private static final Log logger = LogFactory.getLog(TransactionSynchronizationUtils.class);
|
||||||
|
|
||||||
|
private static final boolean aopAvailable = ClassUtils.isPresent(
|
||||||
|
"org.springframework.aop.scope.ScopedObject", TransactionSynchronizationUtils.class.getClassLoader());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given resource transaction managers refers to the given
|
* Check whether the given resource transaction managers refers to the given
|
||||||
|
|
@ -57,12 +61,15 @@ public abstract class TransactionSynchronizationUtils {
|
||||||
static Object unwrapResourceIfNecessary(Object resource) {
|
static Object unwrapResourceIfNecessary(Object resource) {
|
||||||
Assert.notNull(resource, "Resource must not be null");
|
Assert.notNull(resource, "Resource must not be null");
|
||||||
Object resourceRef = resource;
|
Object resourceRef = resource;
|
||||||
if (resource instanceof ScopedObject) {
|
// unwrap infrastructure proxy
|
||||||
// First unwrap a scoped proxy.
|
if (resourceRef instanceof InfrastructureProxy) {
|
||||||
resourceRef = ((ScopedObject) resource).getTargetObject();
|
resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject();
|
||||||
}
|
}
|
||||||
// Now unwrap infrastructure proxy
|
if (aopAvailable) {
|
||||||
return (resourceRef instanceof InfrastructureProxy ? ((InfrastructureProxy) resourceRef).getWrappedObject() : resourceRef);
|
// now unwrap scoped proxy
|
||||||
|
resourceRef = ScopedProxyUnwrapper.unwrapIfNecessary(resource);
|
||||||
|
}
|
||||||
|
return resourceRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -167,4 +174,20 @@ public abstract class TransactionSynchronizationUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inner class to avoid hard-coded dependency on AOP module.
|
||||||
|
*/
|
||||||
|
private static class ScopedProxyUnwrapper {
|
||||||
|
|
||||||
|
public static Object unwrapIfNecessary(Object resource) {
|
||||||
|
if (resource instanceof ScopedObject) {
|
||||||
|
return ((ScopedObject) resource).getTargetObject();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue