From 340a88da4c58ce828e3cb0e5ec0b210ed1fad3b3 Mon Sep 17 00:00:00 2001
From: Rob Winch
Date: Tue, 28 Apr 2015 13:07:03 -0500
Subject: [PATCH] LDAP-321: ContextSourceTransactionManager overrides
isExistingTransaction
PreviouslyIllegalStateException: No value for key PoolingContextSource
would be thrown.
This is now fixed since isExistingTransaction is now provided.
---
.../ContextSourceTransactionManager.java | 21 +++++---
.../ldap/itest/ldap321/Ldap321Test.java | 50 +++++++++++++++++++
.../ldap/itest/ldap321/RoleRepo.java | 33 ++++++++++++
.../src/test/resources/ldap321.xml | 26 ++++++++++
4 files changed, 124 insertions(+), 6 deletions(-)
create mode 100644 test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java
create mode 100644 test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java
create mode 100644 test/integration-tests/src/test/resources/ldap321.xml
diff --git a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManager.java b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManager.java
index a10578b7..6934cff8 100644
--- a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManager.java
+++ b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManager.java
@@ -22,8 +22,10 @@ import org.springframework.ldap.transaction.compensating.TempEntryRenamingStrate
import org.springframework.ldap.transaction.compensating.UnbindOperationExecutor;
import org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy;
import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder;
+import org.springframework.transaction.compensating.support.CompensatingTransactionObject;
import org.springframework.transaction.compensating.support.DefaultCompensatingTransactionOperationManager;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
@@ -101,9 +103,9 @@ import org.springframework.transaction.support.DefaultTransactionStatus;
* same logic needs to be used if we want to wrap a JDBC and LDAP transaction in
* the same logical transaction.
*
- *
+ *
* @author Mattias Hellborg Arthursson
- *
+ *
* @see ContextSourceAndDataSourceTransactionManager
* @see ContextSourceTransactionManagerDelegate
* @see DefaultCompensatingTransactionOperationManager
@@ -156,7 +158,7 @@ public class ContextSourceTransactionManager extends
/**
* Get the ContextSource.
- *
+ *
* @return the contextSource.
* @see ContextSourceTransactionManagerDelegate#getContextSource()
*/
@@ -166,7 +168,7 @@ public class ContextSourceTransactionManager extends
/**
* Set the ContextSource.
- *
+ *
* @param contextSource
* the ContextSource.
* @see ContextSourceTransactionManagerDelegate#setContextSource(ContextSource)
@@ -177,7 +179,7 @@ public class ContextSourceTransactionManager extends
/**
* Set the {@link TempEntryRenamingStrategy}.
- *
+ *
* @param renamingStrategy
* the Renaming Strategy.
* @see ContextSourceTransactionManagerDelegate#setRenamingStrategy(TempEntryRenamingStrategy)
@@ -189,4 +191,11 @@ public class ContextSourceTransactionManager extends
public void afterPropertiesSet() throws Exception {
delegate.checkRenamingStrategy();
}
-}
+
+ @Override
+ protected boolean isExistingTransaction(Object transaction)
+ throws TransactionException {
+ CompensatingTransactionObject txObject = (CompensatingTransactionObject) transaction;
+ return (txObject.getHolder() != null);
+ }
+}
\ No newline at end of file
diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java
new file mode 100644
index 00000000..a3abd76b
--- /dev/null
+++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2002-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ldap.itest.ldap321;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author Rob Winch
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:ldap321.xml")
+@TransactionConfiguration(transactionManager = "txManager",defaultRollback = true)
+@Transactional
+public class Ldap321Test{
+ @Autowired
+ private RoleRepo roleRepo;
+
+ @Test
+ public void testQueryRoleMap() throws Exception {
+ Map roleMap=roleRepo.queryRoleMap();
+ assertNotNull(roleMap);
+
+ for(String roleName:roleMap.keySet()){
+ System.out.println(roleName+":"+ roleMap.get(roleName));
+ }
+ }
+}
diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java
new file mode 100644
index 00000000..71a05865
--- /dev/null
+++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ldap.itest.ldap321;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author Rob Winch
+ */
+public class RoleRepo {
+
+ @Transactional
+ public Map queryRoleMap() {
+ return new HashMap();
+ }
+
+}
diff --git a/test/integration-tests/src/test/resources/ldap321.xml b/test/integration-tests/src/test/resources/ldap321.xml
new file mode 100644
index 00000000..dccfd81e
--- /dev/null
+++ b/test/integration-tests/src/test/resources/ldap321.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file