LDAP-321: ContextSourceTransactionManager overrides isExistingTransaction
PreviouslyIllegalStateException: No value for key PoolingContextSource would be thrown. This is now fixed since isExistingTransaction is now provided.
This commit is contained in:
@@ -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.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -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<String,String> roleMap=roleRepo.queryRoleMap();
|
||||
assertNotNull(roleMap);
|
||||
|
||||
for(String roleName:roleMap.keySet()){
|
||||
System.out.println(roleName+":"+ roleMap.get(roleName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String,String> queryRoleMap() {
|
||||
return new HashMap<String,String>();
|
||||
}
|
||||
|
||||
}
|
||||
26
test/integration-tests/src/test/resources/ldap321.xml
Normal file
26
test/integration-tests/src/test/resources/ldap321.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:ldap="http://www.springframework.org/schema/ldap"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
|
||||
|
||||
<ldap:transaction-manager id="txManager">
|
||||
<ldap:default-renaming-strategy />
|
||||
</ldap:transaction-manager>
|
||||
|
||||
<tx:annotation-driven transaction-manager="txManager"/>
|
||||
<bean class="org.springframework.ldap.itest.ldap321.RoleRepo"/>
|
||||
|
||||
<ldap:context-source password="secret" url="ldap://localhost:9321" username="uid=admin,ou=system" />
|
||||
|
||||
<beans profile="default">
|
||||
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
|
||||
<property name="partitionName" value="example"/>
|
||||
<property name="partitionSuffix" value="dc=261consulting,dc=com" />
|
||||
<property name="port" value="9321" />
|
||||
</bean>
|
||||
</beans>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user