LDAP-256: Now requiring TempEntryRenamingStrategy to be explicitly configured. Updated transaction documentation to reflect this and use tx:annotation-config syntax.
This commit is contained in:
@@ -162,7 +162,7 @@ public class ContextSourceAndDataSourceTransactionManager extends
|
||||
ldapManagerDelegate.setContextSource(contextSource);
|
||||
}
|
||||
|
||||
protected void setRenamingStrategy(
|
||||
public void setRenamingStrategy(
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
ldapManagerDelegate.setRenamingStrategy(renamingStrategy);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
ldapManagerDelegate.setContextSource(contextSource);
|
||||
}
|
||||
|
||||
protected void setRenamingStrategy(
|
||||
public void setRenamingStrategy(
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
ldapManagerDelegate.setRenamingStrategy(renamingStrategy);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.ldap.transaction.compensating.support.DefaultTempEntr
|
||||
import org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate;
|
||||
import org.springframework.transaction.compensating.support.CompensatingTransactionHolderSupport;
|
||||
import org.springframework.transaction.compensating.support.DefaultCompensatingTransactionOperationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
@@ -48,7 +49,7 @@ public class ContextSourceTransactionManagerDelegate extends
|
||||
|
||||
private ContextSource contextSource;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy = new DefaultTempEntryRenamingStrategy();
|
||||
private TempEntryRenamingStrategy renamingStrategy;
|
||||
|
||||
/**
|
||||
* Set the ContextSource to work on. Even though the actual ContextSource
|
||||
@@ -120,9 +121,6 @@ public class ContextSourceTransactionManagerDelegate extends
|
||||
}
|
||||
|
||||
void checkRenamingStrategy() {
|
||||
if(renamingStrategy instanceof DefaultTempEntryRenamingStrategy) {
|
||||
log.warn("Using DefaultTempEntryRenamingStrategy. This is not advised for more complex use; " +
|
||||
"see reference documentation for additional information on how to configure TempEntryRenamingStrategy.");
|
||||
}
|
||||
Assert.notNull(renamingStrategy, "RenamingStrategy must be specified");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
transaction (e.g. a <literal>modifyAttributes</literal> followed by a <literal>rebind</literal>), or
|
||||
if transaction synchronization with a JDBC data source is not required (see below) there will be nothing to gain
|
||||
by using the LDAP transaction support.</note>
|
||||
<note>While the default setup will work fine for most simple use cases, some more complex scenarios will
|
||||
require additional configuration; more specifically if you will be creating or deleting subtrees within
|
||||
transactions, you will need to use an alternative <literal>TempEntryRenamingStrategy</literal>, as described
|
||||
in <xref linkend="renaming-strategies"/> below</note>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
@@ -45,9 +41,10 @@
|
||||
<title>Configuration</title>
|
||||
<para>
|
||||
Configuring Spring LDAP transactions should look very familiar if you're used to configuring Spring transactions.
|
||||
You will create a <literal>TransactionManager</literal> instance and wrap your target object using a
|
||||
<literal>TransactionProxyFactoryBean</literal>. In addition to this, you will also need to wrap your
|
||||
<literal>ContextSource</literal> in a <literal>TransactionAwareContextSourceProxy</literal>.
|
||||
You will annotate your transacted classes with <literal>@Transactional</literal>, create a
|
||||
<literal>TransactionManager</literal> instance and include a <literal><tx:annotation-driven></literal>
|
||||
tag in your bean configuraion. In addition to this, you will also need to wrap your <literal>ContextSource</literal>
|
||||
in a <literal>TransactionAwareContextSourceProxy</literal>.
|
||||
<informalexample>
|
||||
<programlisting><beans>
|
||||
...
|
||||
@@ -70,29 +67,32 @@
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
|
||||
<property name="contextSource" ref="contextSource" />
|
||||
<property name="renamingStrategy">
|
||||
<!--
|
||||
Note this default configuration will not work for more complex scenarios, see below for more information on RenamingStrategies.
|
||||
-->
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
|
||||
</bean>
|
||||
|
||||
<bean id="myDataAccessObjectTarget" class="com.example.MyDataAccessObject">
|
||||
<bean id="myDataAccessObject" class="com.example.MyDataAccessObject">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="myDataAccessObject"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="target" ref="myDataAccessObjectTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven>
|
||||
|
||||
...</programlisting>
|
||||
<note>While the this setup will work fine for most simple use cases, some more complex scenarios will
|
||||
require additional configuration; more specifically if you will be creating or deleting subtrees within
|
||||
transactions, you will need to use an alternative <literal>TempEntryRenamingStrategy</literal>, as described
|
||||
in <xref linkend="renaming-strategies"/> below</note>
|
||||
</informalexample>
|
||||
In a real world example you would probably apply the transactions on the service object level
|
||||
rather than the DAO level; the above serves as an example to demonstrate the general idea.
|
||||
<note>You'll notice that the actual <literal>ContextSource</literal> and DAO instances get ids with a
|
||||
"Target" suffix. The beans you will actually refer to are the Proxies that are created
|
||||
around the targets; <literal>contextSource</literal> and <literal>myDataAccessObject</literal></note>
|
||||
<note>You'll notice that the actual <literal>ContextSource</literal> instance gets an id with a
|
||||
"Target" suffix. The bean you will actually refer to is the Proxy that are created
|
||||
around the target; <literal>contextSource</literal>.</note>
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="jdbc-transaction-integration">
|
||||
|
||||
@@ -20,7 +20,9 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapDummyDaoImpl implements DummyDao {
|
||||
private static final boolean RECURSIVE = true;
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@@ -5,9 +5,12 @@ import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@Transactional
|
||||
public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements OrgPersonDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@@ -45,7 +45,7 @@ import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
@@ -57,24 +57,17 @@
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
</bean>
|
||||
<property name="renamingStrategy">
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.ldap.itest.transaction.compensating.manager.hibernate.DummyDaoLdapAndHibernateImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<tx:annotation-driven />
|
||||
</beans>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
@@ -43,24 +43,17 @@
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
<property name="renamingStrategy">
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.ldap.itest.transaction.compensating.manager.LdapAndJdbcDummyDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<tx:annotation-driven />
|
||||
</beans>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
@@ -30,23 +30,15 @@
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
<property name="renamingStrategy">
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.ldap.itest.transaction.compensating.manager.LdapDummyDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<tx:annotation-driven />
|
||||
</beans>
|
||||
|
||||
@@ -54,6 +54,9 @@
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
<property name="renamingStrategy">
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
<property name="renamingStrategy">
|
||||
<bean class="org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user