← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18736: Moved program stage data elements upgrade routine to InitTableAlteror

 

------------------------------------------------------------
revno: 18736
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-30 09:56:29 +0200
message:
  Moved program stage data elements upgrade routine to InitTableAlteror
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java


--
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/startup/InitTableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-03-30 07:56:29 +0000
@@ -31,6 +31,7 @@
 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.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -45,6 +46,9 @@
 
     @Autowired
     private StatementManager statementManager;
+    
+    @Autowired
+    private StatementBuilder statementBuilder;
 
     // -------------------------------------------------------------------------
     // Execute
@@ -65,12 +69,37 @@
         executeSql( "UPDATE programstageinstance SET status='COMPLETED' WHERE status='1';" );
         executeSql( "UPDATE programstageinstance SET status='SKIPPED' WHERE status='5';" );
         executeSql( "ALTER TABLE program DROP COLUMN displayonallorgunit" );
+        
+        upgradeProgramStageDataElements();
     }
 
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
 
+    private void upgradeProgramStageDataElements()
+    {
+        int r = executeSql( "select 1 from programstage_dataelements" );
+        
+        if ( r != -1 )
+        {
+            String autoIncr = statementBuilder.getAutoIncrementValue();
+            
+            String insertSql = 
+                "insert into programstagedataelement(programstagedataelementid,programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,allowfuturedate) " +
+                "select " + autoIncr + ",programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,allowfuturedate " +
+                "from programstage_dataelements";
+            
+            executeSql( insertSql );
+            
+            String dropSql = "drop table programstage_dataelements";
+            
+            executeSql( dropSql );
+            
+            log.info( "Upgraded program stage data elements" );
+        }
+    }
+    
     private int executeSql( String sql )
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2015-03-27 23:28:52 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2015-03-30 07:56:29 +0000
@@ -315,37 +315,12 @@
         executeSql( "update userroleauthorities set authority='F_ADD_TRACKED_ENTITY_FORM' where authority='F_TRACKED_ENTITY_FORM_ADD'" );
 
         updateProgramExpressionUid();
-        
-        upgradeProgramStageDataElements();
     }
 
     // -------------------------------------------------------------------------
     // Supporting methods
     // -------------------------------------------------------------------------
 
-    private void upgradeProgramStageDataElements()
-    {
-        int r = executeSql( "select 1 from programstage_dataelements" );
-        
-        if ( r != -1 )
-        {
-            String autoIncr = statementBuilder.getAutoIncrementValue();
-            
-            String insertSql = 
-                "insert into programstagedataelement(programstagedataelementid,programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,allowfuturedate) " +
-                "select " + autoIncr + ",programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,allowfuturedate " +
-                "from programstage_dataelements";
-            
-            executeSql( insertSql );
-            
-            String dropSql = "drop table programstage_dataelements";
-            
-            executeSql( dropSql );
-            
-            log.info( "Upgraded program stage data elements" );
-        }
-    }
-    
     private void updateAggregateQueryBuilder()
     {
         StatementHolder holder = statementManager.getHolder();