Fixed compensation for proxy being injected as contextSource to ContextSourceTransactionManager.

This commit is contained in:
Mattias Arthursson
2007-01-18 19:47:10 +00:00
parent ac20372706
commit 6c7f64d6f3
3 changed files with 32 additions and 3 deletions

View File

@@ -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() {

View File

@@ -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)
*

View File

@@ -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);
}
}