|
|
|
@ -21,9 +21,10 @@ import java.util.List; |
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
import org.springframework.aop.scope.ScopedObject; |
|
|
|
|
import org.springframework.core.InfrastructureProxy; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
import org.springframework.aop.scope.ScopedObject; |
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 boolean aopAvailable = ClassUtils.isPresent( |
|
|
|
|
"org.springframework.aop.scope.ScopedObject", TransactionSynchronizationUtils.class.getClassLoader()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Check whether the given resource transaction managers refers to the given |
|
|
|
@ -57,12 +61,15 @@ public abstract class TransactionSynchronizationUtils { |
|
|
|
|
static Object unwrapResourceIfNecessary(Object resource) { |
|
|
|
|
Assert.notNull(resource, "Resource must not be null"); |
|
|
|
|
Object resourceRef = resource; |
|
|
|
|
if (resource instanceof ScopedObject) { |
|
|
|
|
// First unwrap a scoped proxy.
|
|
|
|
|
resourceRef = ((ScopedObject) resource).getTargetObject(); |
|
|
|
|
// unwrap infrastructure proxy
|
|
|
|
|
if (resourceRef instanceof InfrastructureProxy) { |
|
|
|
|
resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject(); |
|
|
|
|
} |
|
|
|
|
if (aopAvailable) { |
|
|
|
|
// now unwrap scoped proxy
|
|
|
|
|
resourceRef = ScopedProxyUnwrapper.unwrapIfNecessary(resource); |
|
|
|
|
} |
|
|
|
|
// Now unwrap infrastructure proxy
|
|
|
|
|
return (resourceRef instanceof InfrastructureProxy ? ((InfrastructureProxy) resourceRef).getWrappedObject() : resourceRef); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|