Fixed compensation for proxy being injected as contextSource to ContextSourceTransactionManager.
This commit is contained in:
@@ -62,14 +62,22 @@ public class ContextSourceTransactionManager extends
|
||||
private ContextSource contextSource;
|
||||
|
||||
/**
|
||||
* Set the ContextSource to work on. The supplied ContextSource must be of
|
||||
* the type abstract
|
||||
* Set the ContextSource to work on. Even though the actual ContextSource
|
||||
* sent to the LdapTemplate instance should be a
|
||||
* {@link TransactionAwareContextSourceProxy}, the one sent to this method
|
||||
* should be the target of that proxy. If it is not, the target will be
|
||||
* extracted and used instead.
|
||||
*
|
||||
* @param contextSource
|
||||
* the ContextSource to work on.
|
||||
*/
|
||||
public void setContextSource(ContextSource contextSource) {
|
||||
this.contextSource = contextSource;
|
||||
if (contextSource instanceof TransactionAwareContextSourceProxy) {
|
||||
TransactionAwareContextSourceProxy proxy = (TransactionAwareContextSourceProxy) contextSource;
|
||||
this.contextSource = proxy.getTarget();
|
||||
} else {
|
||||
this.contextSource = contextSource;
|
||||
}
|
||||
}
|
||||
|
||||
public ContextSource getContextSource() {
|
||||
|
||||
@@ -47,6 +47,15 @@ public class TransactionAwareContextSourceProxy implements ContextSource {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target ContextSource.
|
||||
*
|
||||
* @return the target ContextSource.
|
||||
*/
|
||||
public ContextSource getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -153,4 +153,16 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
.getResource(contextSourceMock));
|
||||
assertNull(expectedContextHolder.getTransactionDataManager());
|
||||
}
|
||||
|
||||
public void testSetContextSource_Proxy() {
|
||||
TransactionAwareContextSourceProxy proxy = new TransactionAwareContextSourceProxy(
|
||||
contextSourceMock);
|
||||
|
||||
// Perform test
|
||||
tested.setContextSource(proxy);
|
||||
ContextSource result = tested.getContextSource();
|
||||
|
||||
// Verify result
|
||||
assertSame(contextSourceMock, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user