From 6c7f64d6f37916cd71b3498e5a44e04c4dd920a1 Mon Sep 17 00:00:00 2001 From: Mattias Arthursson Date: Thu, 18 Jan 2007 19:47:10 +0000 Subject: [PATCH] Fixed compensation for proxy being injected as contextSource to ContextSourceTransactionManager. --- .../ContextSourceTransactionManager.java | 14 +++++++++++--- .../TransactionAwareContextSourceProxy.java | 9 +++++++++ .../ContextSourceTransactionManagerTest.java | 12 ++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sandbox/src/main/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManager.java b/sandbox/src/main/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManager.java index 6514ffc4..f60f0371 100644 --- a/sandbox/src/main/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManager.java +++ b/sandbox/src/main/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManager.java @@ -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() { diff --git a/sandbox/src/main/java/org/springframework/ldap/support/transaction/TransactionAwareContextSourceProxy.java b/sandbox/src/main/java/org/springframework/ldap/support/transaction/TransactionAwareContextSourceProxy.java index cd9059d0..de998934 100644 --- a/sandbox/src/main/java/org/springframework/ldap/support/transaction/TransactionAwareContextSourceProxy.java +++ b/sandbox/src/main/java/org/springframework/ldap/support/transaction/TransactionAwareContextSourceProxy.java @@ -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) * diff --git a/sandbox/src/test/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManagerTest.java b/sandbox/src/test/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManagerTest.java index dfaeedc8..15ce737e 100644 --- a/sandbox/src/test/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManagerTest.java +++ b/sandbox/src/test/java/org/springframework/ldap/support/transaction/ContextSourceTransactionManagerTest.java @@ -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); + } }