← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1498: Chanage to use jdbcTemplate for DataEntryFormPopulator.

 

------------------------------------------------------------
revno: 1498
committer: Viet <Viet@Viet-Laptop>
branch nick: trunk
timestamp: Thu 2010-02-25 12:20:50 +0530
message:
  Chanage to use jdbcTemplate for DataEntryFormPopulator.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java	2010-02-24 12:54:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java	2010-02-25 06:50:50 +0000
@@ -1,14 +1,13 @@
 package org.hisp.dhis.dataentryform;
 
-import java.sql.Statement;
-
-import org.amplecode.quick.StatementManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.transaction.annotation.Transactional;
 
+@Transactional
 public class DataEntryFormPopulator
     extends AbstractStartupRoutine
 {
@@ -18,15 +17,15 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private StatementManager statementManager;
+    private JdbcTemplate jdbcTemplate;
 
-    public void setStatementManager( StatementManager statementManager )
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
-        this.statementManager = statementManager;
+        this.jdbcTemplate = jdbcTemplate;
     }
-    
+
     private StatementBuilder statementBuilder;
-    
+
     public void setStatementBuilder( StatementBuilder statementBuilder )
     {
         this.statementBuilder = statementBuilder;
@@ -35,18 +34,14 @@
     // -------------------------------------------------------------------------
     // Execute
     // -------------------------------------------------------------------------
-    
-    @Transactional
+
     public void execute()
         throws Exception
     {
         log.info( "Remove datasetid column from dataentryform table" );
-        Statement stmnt = statementManager.getHolder().getStatement();
         try
         {
-            stmnt.executeUpdate(  statementBuilder.getDropDatasetForeignKeyForDataEntryFormTable() );
-            stmnt.executeUpdate( "INSERT INTO dataentryformassociation  SELECT 'dataset', datasetid, dataentryformid FROM dataentryform;" );
-            stmnt.executeUpdate( "ALTER TABLE dataentryform DROP COLUMN datasetid;" );
+            executeTransactional();
         }
         catch ( Exception ex )
         {
@@ -54,7 +49,13 @@
         }
     }
 
-
-    
+    @Transactional( rollbackFor = Exception.class )
+    public void executeTransactional()
+        throws Exception
+    {
+        jdbcTemplate.execute( "INSERT INTO dataentryformassociation  SELECT 'dataset', datasetid, dataentryformid FROM dataentryform;" );
+        jdbcTemplate.execute( statementBuilder.getDropDatasetForeignKeyForDataEntryFormTable() );
+        jdbcTemplate.execute( "ALTER TABLE dataentryform DROP COLUMN datasetid;" );
+    }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2010-02-24 12:17:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2010-02-25 06:50:50 +0000
@@ -397,7 +397,7 @@
 	
   <bean id="org.hisp.dhis.dataentryform.DataEntryFormPopulator"
     class="org.hisp.dhis.dataentryform.DataEntryFormPopulator">
-  	<property name="statementManager" ref="statementManager"/>
+  	<property name="jdbcTemplate" ref="jdbcTemplate"/>
   	<property name="statementBuilder" ref="statementBuilder"/>
     <property name="runlevel" value="1"/>
   </bean>