-
Hi! Here is my configuration:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="contextSourceTarget"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://x.x.x:389" />
<property name="base" value="o=sigmatao,c=MX" />
<property name="userName" value="cn=xxxxx" />
<property name="password" value="xxxxx" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSourceTarget" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="transactionManager"
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
<constructor-arg ref="contextSource" />
</bean>
<bean id="myDataAccessObjectTarget" class="sigmatao.com.PerfilDaoImpl">
<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="create">PROPAGATION_SUPPORTS</prop>
<prop key="delete">PROPAGATION_SUPPORTS</prop>
<prop key="update">PROPAGATION_SUPPORTS</prop>
<prop key="getAllPerfilCuentas">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
</beans>
-
Is it possible to see the test code you are running as well?
-
Yes, here is my code:
Code:
resource = new ClassPathResource("testContext.xml");
factory = new XmlBeanFactory(resource);
ldapContact = (ProfileDaoImpl)factory.getBean("myDataAccessObjectTarget");
Profile p1 = new Profile();
p1.setCn("Alexis Moreno");
p1.setCt("1116");
p1.setMail("alexis@mail.com");
p1.setSn("Alexis");
p1.setTelephoneNumber("22666666");
ldapContact.create(p1, "tablename");
In ProfileDaoImpl:
public void create(Profile p, String clase){
private LdapTemplate ldapTemplate;
ldapTemplate.bind(construyeDn(p), null, profileAttributes);
}
-
I've been thinking about that the best manner of control my transactions is the programmatically manner, isn't it? well, I've been reading information about it and some examples aren't clear. I've been reading the Transaction Management Spring framework, and http://forum.springframework.org/arc...p/t-34112.html forum and I have not seen an concrete sample about the use of ContextSourceAndDataSourceTransactionManager class. I need to do transactions with LDAP and JDBC. Help me!
Thanks.
-
There is an integration test for transactions involving LDAP and JDBC. Perhaps that might be of some help to you. The context file is here and the test code is here.
You'll find the same code in the buildable distribution.
-
I would presume your problem was because you were using BeanFactory instead of ApplicationContext. It's quite a common problem people have with AOP and is discussed at the beginning of the reference manual.
http://www.springframework.org/docs/...nce/beans.html
-
Thanks a lot for all of you, I modify my code, and I had an org.springframework.beans.factory.BeanCreationExce ption:
Code:
Resource resource = new ClassPathResource("testContext.xml");
//BeanFactory factory = new XmlBeanFactory(resource);
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"testContext.xml"});
BeanFactory factory = (BeanFactory) context;
PerfilDao ldapContact = (PerfilDaoImpl)factory.getBean("myDataAccessObjectTarget");
and my configuration:
Code:
<bean id="transactionManager"
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
<constructor-arg ref="contextSource" />
</bean>
<bean id="myDataAccessObjectTarget" class="PerfilDaoImpl">
<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="create">PROPAGATION_SUPPORTS</prop>
<prop key="delete">PROPAGATION_SUPPORTS</prop>
<prop key="update">PROPAGATION_SUPPORTS</prop>
<prop key="getAllPerfilCuentas">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
-
How about this?
Code:
ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
PerfilDao ldapContact = (PerfilDao) context.getBean("myDataAccessObject");
-
A couple of other things I've noticed. Your transaction propagation setting means if an existing transaction doesn't exist it's going to execute non-transactionally. It would also be really useful to see the code you are running to test this.
http://www.springframework.org/docs/...ATION_SUPPORTS
-
Hi Karldmoore, I'm going to try it.
But I changed to programatically manner using the ContextSourceTransactionManager class to perform a transaction LDAP, I saw the forum http://forum.springframework.org/arc...3C/t-9730.html and and others forums, tutoriales and I see that almost samples are the same, but I have some problems to do the transaction programmatic, here some code:
Code:
LdapContextSource ldapContextSource = new LdapContextSource();
TransactionAwareContextSourceProxy tacsp = null;
final Perfil p1 = new Perfil();
//construct an appropriate transaction manager
ContextSourceTransactionManager txManager = new ContextSourceTransactionManager();
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//explicitly setting the transaction name is something that can only be done programmatically
def.setName("SomeTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
Assert.notNull(txManager, "The 'transactionManager' argument must not be null.");
ldapContextSource.setUrl("ldap://X.X.X:389");
ldapContextSource.setBase("o=xxxxxx,c=MX");
ldapContextSource.setUserName("cn=xxxx");
ldapContextSource.setPassword("xxxxxx");
tacsp = new TransactionAwareContextSourceProxy(ldapContextSource);
final ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
final PerfilDao ldapContact = (PerfilDao)context.getBean("myDataAccessObject");
txManager.setContextSource(ldapContextSource);
TransactionTemplate(txManager);
//Asignación de los valores de un perfil
p1.setCn("Alexis Moreno");
p1.setCt("1013");
p1.setMail("alexis@mail.com");
p1.setSn("Alexis");
p1.setTelephoneNumber("4422666666");
// execute your business logic here
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try{
ldapContact.create(p1, "perfilTelmex");
}
catch(Exception e){
e.printStackTrace();
status.setRollbackOnly();
}
}
});
Where is/are my error(s)?
Thanks