Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: LDAP Transactions

  1. #11
    Join Date
    Jul 2007
    Posts
    22

    Default

    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>
    Last edited by sacara; Jul 5th, 2007 at 10:36 AM.

  2. #12
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is it possible to see the test code you are running as well?
    Last edited by karldmoore; Aug 29th, 2007 at 10:25 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #13
    Join Date
    Jul 2007
    Posts
    22

    Default

    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);
    }

  4. #14
    Join Date
    Jul 2007
    Posts
    22

    Default

    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.

  5. #15
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    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.
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  6. #16
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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
    Last edited by karldmoore; Aug 29th, 2007 at 10:25 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  7. #17
    Join Date
    Jul 2007
    Posts
    22

    Default

    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>

  8. #18
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    How about this?
    Code:
    ApplicationContext context = new ClassPathXmlApplicationContext("testContext.xml");
    PerfilDao ldapContact = (PerfilDao) context.getBean("myDataAccessObject");
    Last edited by karldmoore; Aug 29th, 2007 at 10:24 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  9. #19
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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
    Last edited by karldmoore; Aug 29th, 2007 at 10:24 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  10. #20
    Join Date
    Jul 2007
    Posts
    22

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •