Announcement Announcement Module
Collapse
No announcement yet.
Transactions are not rolling back JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transactions are not rolling back JDBC

    Hi All,

    I am having problems getting the spring transaction manager to rollback one jdbc insert statement that is called from my mvc controller. After the insert statement I throw a runtime exception to try and test that the sql rollbacks. This simply does not happen and item is committed to the db.

    Can anyone give me some guidance as to where I have gone wrong as im really keen to master this.. ?




    Application Context Namespace Headings are:

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	   	
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    	http://www.springframework.org/schem...ng-mvc-3.0.xsd
    	http://www.springframework.org/schema/beans 
    http://www.springframework.org/schem...-beans-3.0.xsd							
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schem...ontext-3.0.xsd
    http://www.springframework.org/schema/task 
    http://www.springframework.org/schem...g-task-3.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    Application Context :

    Code:
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    
    <tx:annotation-driven />
    Mr service method has :

    Code:
    @Override
    @Transactional (isolation=Isolation.DEFAULT, propagation=Propagation.REQUIRED)
    public void testInsertCustomer() {		
      final String email = "[email protected]";
      final String firstName = "firstname";
      final String lastName = "lastname";
      final String customerDobStr = "01/01/2011";
    		
      getJdbcTemplate().update(SQL_REPLACE_INSERT_CUSTOMER, new Object[]
         {"123456", email, firstName, lastName, customerDobStr});
    
    throw new RuntimeException("exception");
    }
    The Service class is injected into the controller and the controller invokes testInsertCustomer().

    Finally my pom file has:

    Code:
    <dependency>
    	   <groupId>org.springframework</groupId>
    	   <artifactId>spring-tx</artifactId>
    	   <version>3.0.5.RELEASE</version>
    	</dependency>
    If anyone could point me in the right direction I would really appreciate it. I tried nearly everything I can think of, but the transaction will just not roll back.

    Kind Regards
    Darren.
    Last edited by DJC_Spring; Jun 23rd, 2011, 06:57 AM.

  • #2
    Hello

    use code tags when you post some code

    The Service class is injected into the controller and the controller invokes testInsertCustomer().
    Be totally sure that the business method which call your DAO method must be @Transactional too

    is testInsertCustomer() the business method or is the DAO method?, I am confused about that, if you could post the code about the controller would be better for us

    Comment


    • #3
      What SQL server vendor are you using? Have you confirmed autoCommit and exactly what the default isolatation is in use? For example MySQL with MyISAM tables does not support transactions, even though the server responds as-if all is fine in the world.

      Put a big wait Thead.getCurrentThread().sleep(10000); just before raising the exception and from another SQL connection try to select the row during that pause. Please report back if you an see it or the other connection is locked.

      Im not sure how the other repliers question is relevant. Regardless of where (Service or DAO) and how nested your @Transactional is, I presume your Exception is thrown all the way back up to your controller; and so you are reporting here that the rollback action is not happening.

      Comment


      • #4
        Dear Both,

        Thank you very much for the advise.. I really appreciate it when you find a forum whereas people share thier knowledge to help others.! Its a great quality of a person :-)..

        Im documenting everything I tried so hopefully this post will help others with similier issues:

        To try you ideas I thought I would start by checking the mySQL engine:
        Code:
        SELECT TABLE_NAME, ENGINE
        FROM information_schema.TABLES
        WHERE TABLE_SCHEMA = 'mySchemaName'
        Default Engine is InnoDB - So this is fine

        Check Auto commit from command line:

        Code:
        mysql> select @@autocommit;
        +--------------+
        | @@autocommit |
        +--------------+
        |            1 |
        +--------------+
        1 row in set (0.00 sec)
        So 1 = enabled!!

        I inserted a record from the command line and tried to rollback, The recored was of course still there.

        Can anyone tell me the best way to disable this? Is it better to do this in a mysql.ini file somewhere? Or is there a xml configuaration I can use?

        I search for this anyway..
        Last edited by DJC_Spring; Jun 23rd, 2011, 06:58 AM.

        Comment


        • #5
          To disable auto commit for my sql I added defaultAutocommit = false:

          Code:
          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
          		<property name="url" value="jdbc:mysql://localhost:3306/raf" />
          		<property name="username" value="root" />
          		<property name="password" value="root" />		
          		<property name="defaultAutoCommit" value="false" />		
          	</bean>
          Now Zero transactions are commiting if I throw an exception or not?

          Any ideas on what is going?
          Last edited by DJC_Spring; Jun 23rd, 2011, 06:59 AM.

          Comment


          • #6
            Your setup is wrong... You probably have 2 instances of your service (I suspect you use component scanning). Also tx:annotation-driven only works for the applicationcontext it is defined in! So it will not work on parent or child (DispatcherServlet) contexts. Which means if you have tx:annotation-driven in the root-context (ContextLoaderListener) your service needs to be in there also (and ONLY in there). If you have defined (or are scanning) your service in the DispatcherServlet (child context) you get no transactions.

            And please in the future use [ code][/code ] tags, that way it remains readable.

            Comment


            • #7
              Sorry I will update my prevoius posts..

              Comment


              • #8
                Transactions are not rolling back JDBC

                Hello Darren,

                There are two ways to handle this issue.

                The first is to explicitly set a flag for class if the transaction commits. Check the block should flag. If it has not been set, it means that the transaction could not be commited and must be rolled back.

                Another way is to catch 'Exception' after 'SQLException'. If a runtime exception is thrown that will handle it in the catch block by rolling back the transaction and rethrowing the RuntimeException.


                Regards
                Kevin Thomas
                Attune Infocom Inc
                Email : [email protected]
                Liferay Portlet

                Comment


                • #9
                  Hi Marten,

                  Thanks for the respone and I have updated previous post with the code tags. Appologies to everyone all.

                  Could you possibly provide me an with some more info of how I do this? I am learning the configuaration and really keen to fully understand your comment above.

                  My Web.xml is :



                  Code:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
                  	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                  
                  <!--	<context-param>-->
                  <!--		<param-name>contextConfigLocation</param-name>-->
                  <!--		<param-value>-->
                  <!--			/WEB-INF/applicationContext.xml-->
                  <!--		</param-value>-->
                  <!--	</context-param>-->
                  
                  	<context-param>
                  		<param-name>log4jConfigLocation</param-name>
                  		<param-value>/WEB-INF/log4j.xml</param-value>
                  	</context-param>
                  
                  	<listener>
                  		<listener-class>org.springframework.web.util.Log4jConfigListener
                  		</listener-class>
                  	</listener>
                  <!--	<listener>-->
                  <!--		<listener-class>org.springframework.web.context.ContextLoaderListener-->
                  <!--		</listener-class>-->
                  <!--	</listener>-->
                  <!--	<listener>-->
                  <!--		<listener-class>org.springframework.web.context.request.RequestContextListener-->
                  <!--		</listener-class>-->
                  <!--	</listener>-->
                  	
                  	<!-- Reads request input using UTF-8 encoding -->
                  	<filter>
                  		<filter-name>characterEncodingFilter</filter-name>
                  		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
                  		<init-param>
                  			<param-name>encoding</param-name>
                  			<param-value>UTF-8</param-value>
                  		</init-param>
                  		<init-param>
                  			<param-name>forceEncoding</param-name>
                  			<param-value>true</param-value>
                  		</init-param>
                  	</filter>
                  
                  	<filter-mapping>
                  		<filter-name>characterEncodingFilter</filter-name>
                  		<url-pattern>/*</url-pattern> 
                  	</filter-mapping>
                  	
                  	<!-- Handles all requests into the application -->
                  	<servlet>
                  		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                  		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                  		<init-param>
                  			<param-name>contextConfigLocation</param-name>
                  			<param-value>
                  				/WEB-INF/applicationContext.xml
                  			</param-value>
                  		</init-param>
                  		<load-on-startup>1</load-on-startup>
                  	</servlet>
                  
                  	<servlet-mapping>
                            <servlet-name>default</servlet-name>
                            <url-pattern>/static/*</url-pattern>
                            <url-pattern>*.png</url-pattern>
                            <url-pattern>*.jpg</url-pattern>
                            <url-pattern>*.js</url-pattern>
                            <url-pattern>*.gif</url-pattern>
                            <url-pattern>*.css</url-pattern>
                       </servlet-mapping>
                  
                  	<servlet-mapping>
                  		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                  		<url-pattern>/</url-pattern>
                  	</servlet-mapping>
                  
                  </web-app>
                  And my full application context is

                  Code:
                  <?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:aop="http://www.springframework.org/schema/aop" 
                  	   	xmlns:tx="http://www.springframework.org/schema/tx"
                  		xmlns:context="http://www.springframework.org/schema/context"
                  		xmlns:mvc="http://www.springframework.org/schema/mvc" 
                  		xmlns:task="http://www.springframework.org/schema/task"
                  		xsi:schemaLocation="http://www.springframework.org/schema/mvc 
                  							http://www.springframework.org/schem...ng-mvc-3.0.xsd
                  							http://www.springframework.org/schema/beans 
                  							http://www.springframework.org/schem...-beans-3.0.xsd
                  							http://www.springframework.org/schema/context 
                  							http://www.springframework.org/schem...ontext-3.0.xsd
                  							http://www.springframework.org/schema/task 
                  							http://www.springframework.org/schem...g-task-3.0.xsd
                  		 					http://www.springframework.org/schema/aop 
                  		 					http://www.springframework.org/schem...ng-aop-3.0.xsd
                  		 					http://www.springframework.org/schema/tx
                  		 					http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                  
                  	
                  	<!-- Scans the Classpath of this application for @Components to deploy as beans -->
                  	<context:component-scan base-package="com.mycompany.net.*" />
                  
                  	<!-- Configures the @Controller programming model -->
                  	<mvc:annotation-driven />
                  <!--	<task:annotation-driven />-->
                  	 
                  	
                  
                  	<!-- Forwards requests to the "/" resource to the "welcome" view -->
                  	<!-- mvc:view-controller should only be used for the static pages i.e. pages that doesn't contain any inputs. This tag essentially bypasses the controller -->
                  	<mvc:view-controller path="/" view-name="welcome" />	
                  
                  	
                  	<!-- Configures Handler Interceptors -->
                  	<mvc:interceptors>
                  		<!-- Changes the locale when a 'locale' request parameter is sent; e.g.	/?locale=de -->
                  		<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
                  	</mvc:interceptors>
                  
                  	
                  	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />	
                  	
                  	<bean id="recommendationController" class="com.mycompany.net.controller.RecommendationController">
                  		<constructor-arg ref="emailService" />
                  		<constructor-arg ref="rafService" />
                  	</bean>
                  	
                  	<!-- Handles HTTP GET requests for /resources/** by efficiently serving	up static resources in the ${webappRoot}/resources/ directory -->
                  	<mvc:resources mapping="/resources/**" location="/resources/" />
                  
                  	<!-- Saves a locale change using a cookie -->
                  	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
                  
                  	<!-- Application Message Bundle -->
                  	<bean id="messageSource"
                  		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                  		<property name="basename" value="/WEB-INF/messages/messages" />
                  		<property name="cacheSeconds" value="0" />
                  	</bean>
                  
                  	<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
                  		<property name="locations">
                  			<list>
                  				<value>WEB-INF/raf.properties</value>
                  			</list>
                  		</property>
                  	</bean>
                  	
                  	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  		<property name="locations">
                              <list>
                               	<value>/WEB-INF/raf.properties</value>
                              </list>
                          </property>
                  	</bean>
                  
                  	<bean id="springApplicationContext"	class="com.mycompany.spring.beans.SpringApplicationContextBean" />
                  
                  	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                  		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
                  		<property name="url" value="jdbc:mysql://localhost:3306/raf" />
                  		<property name="username" value="root" />
                  		<property name="password" value="root" />		
                  		<property name="defaultAutoCommit" value="false" />		
                  	</bean>
                  	
                  <!--	<import resource="classpath:/com/mycompany/net/download/customer-download-context.xml" />-->
                  <!--	<import resource="classpath:/com/mycompany/net/jobs/recommendationEmail/recommend-a-friend-context.xml" />-->
                  <!--	<import resource="classpath:/com/mycompany/net/jobs/recommendationExpired/recommendation-expiry-context.xml" /> -->
                  <!--	<import resource="classpath:/com/mycompany/net/jobs/recommendationApprovedEmail/voucher-approval-context.xml" />-->
                  <!--	<import resource="classpath:/com/mycompany/net/jobs/recommendationList/voucher-list-email-context.xml" />-->
                  	
                  	<import resource="services.xml" />
                  	<import resource="web-mvc-config.xml" />
                  	
                  	<!--  Include properties for SocialAuth -->	
                  	<import resource="properties.xml" />
                  	
                  	
                  	<bean id="socialAuthTemplate" class="org.brickred.socialauth.spring.bean.SocialAuthTemplate" scope="session">
                      	<aop:scoped-proxy/>
                      </bean>
                          
                      
                      <bean id="socialAuthWebController" class="org.brickred.socialauth.spring.controller.SocialAuthWebController">
                      	<constructor-arg value="http://universalstudios.mycompany.net/RAFWeb/" />
                          <constructor-arg value="authSuccess.do" />
                          <constructor-arg ref="socialAuthProperties" />
                      </bean>
                      
                      <bean id="rafService" class="com.mycompany.net.dao.RAFServiceImpl" />
                      
                     <!-- enable the configuration of transactional behavior based on annotations -->
                    <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
                  
                    <!-- a PlatformTransactionManager is still required -->
                    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                    <!-- (this dependency is defined somewhere else) -->
                    <property name="dataSource" ref="dataSource"/>
                    </bean>
                  
                  	
                  <!--	<bean id="myDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">-->
                  <!--    <property name="transactionManager" ref="transactionManager"/>-->
                  <!--    <property name="target" ref="rafService"/>-->
                  <!--    <property name="proxyTargetClass" value="true"/>-->
                  <!--    <property name="transactionAttributes">-->
                  <!--      <props>-->
                  <!--        <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>-->
                  <!--        <prop key="get*">PROPAGATION_SUPPORTS</prop>-->
                  <!--      </props>-->
                  <!--    </property>-->
                  <!--  </bean>-->
                  	
                  	 
                  		
                  
                  </beans>
                  So, yes I use componenet scanning on

                  Code:
                  <context:component-scan base-package="com.mycompany.net.*" />
                  and (if I understand this right) my tx:annotation-driven is held within a child of dispacther servlet (applicationContext.xml)

                  Could you please tell me how I put my tx:annotation-driven and service in the root-context? - I, slightly confused here, due to my basic understanding unfortunatly..

                  Best Regards
                  Darren.
                  Last edited by DJC_Spring; Jun 23rd, 2011, 07:35 AM.

                  Comment


                  • #10
                    The scenario I explained is the scenario used in most cases, however it doesn't apply to your situation.

                    Please post the stacktrace and also the service, dao and controller.

                    What I wonder is why do you specify everything in xml if you use component-scanning it seems duplication to me and is probably related to your issue.

                    Comment


                    • #11
                      Hi Marten,

                      I have made some changes to the configuration as per you last post regardign root-context.

                      Here is the code :

                      Web.xml

                      Code:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
                      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                      
                      	<context-param>
                              <param-name>contextConfigLocation</param-name>
                              <param-value>
                                  /WEB-INF/service-context.xml            
                              </param-value>
                          </context-param>
                          
                      	<listener>
                      		<listener-class>
                      			org.springframework.web.context.ContextLoaderListener
                      		</listener-class>
                      	</listener>
                      	
                      	
                      	<context-param>
                      		<param-name>log4jConfigLocation</param-name>
                      		<param-value>/WEB-INF/log4j.xml</param-value>
                      	</context-param>
                      
                      	<listener>
                      		<listener-class>org.springframework.web.util.Log4jConfigListener
                      		</listener-class>
                      	</listener>
                      	
                      		
                      	<filter>
                      		<filter-name>characterEncodingFilter</filter-name>
                      		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
                      		<init-param>
                      			<param-name>encoding</param-name>
                      			<param-value>UTF-8</param-value>
                      		</init-param>
                      		<init-param>
                      			<param-name>forceEncoding</param-name>
                      			<param-value>true</param-value>
                      		</init-param>
                      	</filter>
                      
                      	<filter-mapping>
                      		<filter-name>characterEncodingFilter</filter-name>
                      		<url-pattern>/*</url-pattern> 
                      	</filter-mapping>
                      	
                      	<servlet>
                      		<servlet-name>raf</servlet-name>
                      		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>		
                      		<load-on-startup>1</load-on-startup>
                      	</servlet>
                      
                      	<servlet-mapping>
                      		<servlet-name>raf</servlet-name>
                      		<url-pattern>/</url-pattern>
                      	</servlet-mapping>
                      
                      	<servlet-mapping>
                                <servlet-name>default</servlet-name>
                                <url-pattern>/static/*</url-pattern>
                                <url-pattern>*.png</url-pattern>
                                <url-pattern>*.jpg</url-pattern>
                                <url-pattern>*.js</url-pattern>
                                <url-pattern>*.gif</url-pattern>
                                <url-pattern>*.css</url-pattern>
                           </servlet-mapping>
                      	
                      
                      
                      </web-app>

                      Comment


                      • #12
                        Service-context.xml

                        Code:
                        <?xml version="1.0" encoding="UTF-8"?>
                        
                        <beans xmlns="http://www.springframework.org/schema/beans"
                            xmlns:context="http://www.springframework.org/schema/context"
                            xmlns:tx="http://www.springframework.org/schema/tx"
                            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
                              http://www.springframework.org/schema/context
                              http://www.springframework.org/schema/context/spring-context-2.5.xsd
                              http://www.springframework.org/schema/tx
                              http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
                        
                        	 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
                        			<property name="driverClassName" value="com.mysql.jdbc.Driver" />
                        			<property name="url" value="jdbc:mysql://localhost:3306/raf" />
                        			<property name="username" value="root" />
                        			<property name="password" value="root" />		
                        			<property name="defaultAutoCommit" value="false" />		
                        	</bean>
                         
                         
                        	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                        		<property name="dataSource" ref="dataSource"/>
                        	</bean>
                        		
                        	<context:component-scan base-package="com.myCompany.net.dao" />
                        	
                        	<tx:annotation-driven />
                        
                        </beans>

                        Comment


                        • #13
                          Application Content (raf-servlet.xml)
                          Code:
                          <?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:aop="http://www.springframework.org/schema/aop" 
                          	   	xmlns:tx="http://www.springframework.org/schema/tx"
                          		xmlns:context="http://www.springframework.org/schema/context"
                          		xmlns:mvc="http://www.springframework.org/schema/mvc" 
                          		xmlns:task="http://www.springframework.org/schema/task"
                          		xsi:schemaLocation="http://www.springframework.org/schema/mvc 
                          							http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                          							http://www.springframework.org/schema/beans 
                          							http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          							http://www.springframework.org/schema/context 
                          							http://www.springframework.org/schema/context/spring-context-3.0.xsd
                          							http://www.springframework.org/schema/task 
                          							http://www.springframework.org/schema/task/spring-task-3.0.xsd
                          		 					http://www.springframework.org/schema/aop 
                          		 					http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                          		 					http://www.springframework.org/schema/tx
                          		 					http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                          
                          	
                          	<!-- Scans the Classpath of this application for @Components to deploy as beans -->
                          	<context:component-scan base-package="com.myCompany.net" />
                          
                          	<!-- Configures the @Controller programming model -->
                          	<mvc:annotation-driven />	
                          	
                          	<task:annotation-driven />
                          	 
                          	<!-- Forwards requests to the "/" resource to the "welcome" view -->
                          	<!-- mvc:view-controller should only be used for the static pages i.e. pages that doesn't contain any inputs. This tag essentially bypasses the controller -->
                          	<mvc:view-controller path="/" view-name="welcome" />	
                          	
                          	<!-- Configures Handler Interceptors -->
                          	<mvc:interceptors>
                          		<!-- Changes the locale when a 'locale' request parameter is sent; e.g.	/?locale=de -->
                          		<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
                          	</mvc:interceptors>
                          
                          	<bean id="rafService" class="com.myCompany.net.dao.RAFServiceImpl" >
                          		<constructor-arg ref="rafDao" />
                          	</bean>
                          	
                          	<bean id="rafDao" class="com.myCompany.net.dao.RAFDAOImpl" >
                          	</bean>
                          	
                          	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />	
                          	
                          	<bean id="recommendationController" class="com.myCompany.net.controller.RecommendationController">
                          		<constructor-arg ref="emailService" />
                          		<constructor-arg ref="rafService" />
                          	</bean>
                          	
                          	<!-- Handles HTTP GET requests for /resources/** by efficiently serving	up static resources in the ${webappRoot}/resources/ directory -->
                          	<mvc:resources mapping="/resources/**" location="/resources/" />
                          
                          	<!-- Saves a locale change using a cookie -->
                          	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
                          
                          	<!-- Application Message Bundle -->
                          	<bean id="messageSource"
                          		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                          		<property name="basename" value="/WEB-INF/messages/messages" />
                          		<property name="cacheSeconds" value="0" />
                          	</bean>
                          
                          	<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
                          		<property name="locations">
                          			<list>
                          				<value>WEB-INF/raf.properties</value>
                          			</list>
                          		</property>
                          	</bean>
                          	
                          	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                          		<property name="locations">
                                      <list>
                                       	<value>/WEB-INF/raf.properties</value>
                                      </list>
                                  </property>
                          	</bean>
                          
                          	<bean id="springApplicationContext"	class="com.myCompany.spring.beans.SpringApplicationContextBean" />
                          	
                          <!--	<import resource="classpath:/com/myCompany/net/download/customer-download-context.xml" />-->
                          <!--	<import resource="classpath:/com/myCompany/net/jobs/recommendationEmail/recommend-a-friend-context.xml" />-->
                          <!--	<import resource="classpath:/com/myCompany/net/jobs/recommendationExpired/recommendation-expiry-context.xml" /> -->
                          <!--	<import resource="classpath:/com/myCompany/net/jobs/recommendationApprovedEmail/voucher-approval-context.xml" />-->
                          <!--	<import resource="classpath:/com/myCompany/net/jobs/recommendationList/voucher-list-email-context.xml" />-->
                          	
                          	<import resource="services.xml" />
                          	<import resource="web-mvc-config.xml" />
                          	
                          	<!--  Include properties for SocialAuth -->	
                          	<import resource="properties.xml" />
                          	
                          	
                          	<bean id="socialAuthTemplate" class="org.brickred.socialauth.spring.bean.SocialAuthTemplate" scope="session">
                              	<aop:scoped-proxy/>
                              </bean>
                                  
                              
                              <bean id="socialAuthWebController" class="org.brickred.socialauth.spring.controller.SocialAuthWebController">
                              	<constructor-arg value="http://universalstudios.myCompany.net/RAFWeb/" />
                                  <constructor-arg value="authSuccess.do" />
                                  <constructor-arg ref="socialAuthProperties" />
                              </bean>
                              
                             
                          
                             
                            
                          
                          	
                          	 
                          		
                          
                          </beans>

                          Comment


                          • #14
                            Service
                            Code:
                            package com.myCompany.net.dao;
                            
                            import java.sql.PreparedStatement;
                            import java.sql.ResultSet;
                            import java.sql.SQLException;
                            import java.text.SimpleDateFormat;
                            import java.util.Date;
                            import java.util.List;
                            
                            import javax.sql.DataSource;
                            
                            import org.apache.log4j.Logger;
                            import org.springframework.beans.factory.annotation.Autowired;
                            import org.springframework.jdbc.core.BatchPreparedStatementSetter;
                            import org.springframework.jdbc.core.JdbcTemplate;
                            import org.springframework.jdbc.core.RowMapper;
                            import org.springframework.jdbc.core.support.JdbcDaoSupport;
                            import org.springframework.stereotype.Repository;
                            import org.springframework.transaction.annotation.Isolation;
                            import org.springframework.transaction.annotation.Propagation;
                            import org.springframework.transaction.annotation.Transactional;
                            
                            import com.myCompany.net.commons.Util;
                            import com.myCompany.net.domain.Customer;
                            import com.myCompany.net.domain.Recommendation;
                            import com.myCompany.net.domain.Recommendee;
                            import com.myCompany.net.integration.DataFeed;
                            
                            @Repository
                            @Transactional
                            public class RAFServiceImpl implements IRAFService {
                            	
                            	private JdbcTemplate jdbcTemplate;
                            	private final IRAFDAO rafDao;
                            	
                            	public RAFServiceImpl(final IRAFDAO rafDao) {
                            		this.rafDao = rafDao;
                            	}
                            	
                            	@Autowired
                            	public void setDataSource(DataSource dataSource) {
                            		this.jdbcTemplate = new JdbcTemplate(dataSource);
                            	}
                            
                            	/**
                            	 * Checks in the latest feed to see if the customer exist and if yes, then update his/her reference number otherwise return 'Unconfirmed' 
                            	 */
                            	public String getCustomerRefNumber(final String customerFirstName, final String customerLastName, final String dobString) {
                            		return rafDao.getCustomerRefNumber(customerFirstName, customerLastName, dobString);
                            	}
                            	
                            	
                            	/**
                            	 * Same user can recommend multiple friends in different point in time. Now once the Customer is stored in the database, and later 
                            	 * confirmed/CRN updated, we don't want to delete it (or update it with 'Unconfirmed' status)
                            	 */
                            	@Override
                            	@Transactional (isolation=Isolation.DEFAULT, propagation=Propagation.REQUIRED, readOnly=false,rollbackFor=RuntimeException.class)
                            	public int saveOrUpdateCustomer(final Customer customer) {
                            		return rafDao.saveOrUpdateCustomer(customer);
                            	}
                            	
                            	
                            	@Override
                            	@Transactional (propagation=Propagation.REQUIRED)
                            	public void dummyInserCustomer() {		
                            		rafDao.dummyInserCustomer();
                            	}
                            
                            	@Override	
                            	public boolean friendAlreadyExist(final List<Recommendee> recomendations) {
                            		
                            		return rafDao.friendAlreadyExist(recomendations);
                            		
                            	}
                            	
                            
                            	@Override
                            	@Transactional (propagation=Propagation.NESTED, isolation=Isolation.DEFAULT, readOnly=false)
                            	public void addFriends(final Recommendation recomendations,Customer customer) {
                            		rafDao.addFriends(recomendations, customer);
                            		
                            
                            	}
                            	
                            	@Override	
                            	public int[] storeDataFeed(final List<DataFeed> dataFeed) {
                            		return rafDao.storeDataFeed(dataFeed);
                            		
                            
                            	}
                            	
                            	@Override
                            	public List<Recommendee> getAllRecommendee() {
                            		return rafDao.getAllRecommendee();
                            
                            	}
                            	
                            	@Override
                            	public Customer getCustomer(final String email) {
                            		return rafDao.getCustomer(email);
                            		
                            
                            	}
                            	
                            	@Override
                            	public List<Recommendee> getPendingRecommendeeForToday() {
                            		return rafDao.getPendingRecommendeeForToday();
                            		
                            
                            	}
                            	
                            	@Override
                            	public List<Recommendee> getAllApprovedRecommendee() {
                            		return rafDao.getAllApprovedRecommendee();
                            
                            	}
                            	
                            	@Override	
                            	public void markAllApprovedAsCompleted() {
                            		rafDao.markAllApprovedAsCompleted();
                            	}
                            	
                            	@Override	
                            	public List<Customer> getAllCustomer() {
                            		return rafDao.getAllCustomer();
                            		
                            
                            	}
                            
                            	private JdbcTemplate getJdbcTemplate() {
                            		return this.jdbcTemplate;
                            	}
                            
                            	@Override	
                            	public void expireRecommendations() {
                            		rafDao.expireRecommendations();		
                            
                            	}
                            	
                            
                            }

                            Comment


                            • #15
                              DAO

                              Code:
                              package com.monitormedia.net.dao;
                              
                              import java.util.List;
                              
                              import com.myCompany.net.domain.Customer;
                              import com.myCompany.net.domain.Recommendation;
                              import com.myCompany.net.domain.Recommendee;
                              import com.myCompany.net.integration.DataFeed;
                              
                              public interface IRAFDAO {
                              	int saveOrUpdateCustomer(final Customer customer);
                              	void addFriends(Recommendation account, Customer customer);
                              	boolean friendAlreadyExist(final List<Recommendee> recomendations);
                              	int[] storeDataFeed(final List<DataFeed> dataFeed);
                              	List<Recommendee> getAllRecommendee();
                              	List<Recommendee> getPendingRecommendeeForToday();
                              	List<Recommendee> getAllApprovedRecommendee();
                              	Customer getCustomer(final String email) ;
                              	void markAllApprovedAsCompleted();
                              	List<Customer> getAllCustomer();
                              	void expireRecommendations();
                              	String getCustomerRefNumber(final String customerFirstName, final String customerLastName, final String dobString);
                              	void dummyInserCustomer();
                              }

                              Comment

                              Working...
                              X