← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15692: Added new startup routine InitTableAlteror. For certain statements it is necessary to run before ...

 

------------------------------------------------------------
revno: 15692
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-16 11:50:27 +0200
message:
  Added new startup routine InitTableAlteror. For certain statements it is necessary to run before other routines.
added:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.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
=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2014-06-16 09:50:27 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.startup;
+
+import org.amplecode.quick.StatementManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.system.startup.AbstractStartupRoutine;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+public class InitTableAlteror
+    extends AbstractStartupRoutine
+{
+    private static final Log log = LogFactory.getLog( InitTableAlteror.class );
+    
+    @Autowired
+    private StatementManager statementManager;
+
+    // -------------------------------------------------------------------------
+    // Execute
+    // -------------------------------------------------------------------------
+
+    @Transactional
+    public void execute()
+    {
+        // domain type
+        
+        executeSql( "update dataelement set domaintype='AGGREGATE' where domaintype='aggregate' or domaintype is null;" );
+        executeSql( "update dataelement set domaintype='TRACKER' where domaintype='patient';" );
+        executeSql( "alter table dataelement alter column domaintype set not null;" );
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private int executeSql( String sql )
+    {
+        try
+        {
+            // TODO use jdbcTemplate
+
+            return statementManager.getHolder().executeUpdate( sql );
+        }
+        catch ( Exception ex )
+        {
+            log.debug( ex );
+
+            return -1;
+        }
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-06-15 13:20:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-06-16 09:50:27 +0000
@@ -252,9 +252,6 @@
         // update periodType field to ValidationRule
         executeSql( "UPDATE validationrule SET periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name='Monthly') WHERE periodtypeid is null" );
 
-        // update dataelement.domainTypes of which values is null
-        executeSql( "UPDATE dataelement SET domaintype='aggregate' WHERE domaintype is null" );
-
         // set varchar to text
         executeSql( "ALTER TABLE dataelement ALTER description TYPE text" );
         executeSql( "ALTER TABLE indicator ALTER description TYPE text" );
@@ -657,7 +654,6 @@
         executeSql( "UPDATE chart SET publicaccess='--------' WHERE user IS NULL AND publicaccess IS NULL;" );
         executeSql( "UPDATE map SET publicaccess='-------' WHERE user IS NULL AND publicaccess IS NULL;" );
 
-        executeSql( "ALTER TABLE dataelement ALTER COLUMN domaintype SET NOT NULL" );
         executeSql( "update dataelementcategory set datadimension = false where datadimension is null" );
 
         executeSql( "UPDATE dataset SET dataelementdecoration=false WHERE dataelementdecoration is null" );
@@ -725,8 +721,6 @@
         upgradeMapViewsToAnalyticalObject();
         upgradeTranslations();
         
-        executeSql( "update dataelement set domaintype='tracker' where domaintype='patient'");
-
         log.info( "Tables updated" );
     }
 

=== 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	2014-06-09 14:26:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-06-16 09:50:27 +0000
@@ -912,10 +912,16 @@
 
   <!-- Startup routine definitions -->
 
+  <bean id="org.hisp.dhis.startup.InitTableAlteror" class="org.hisp.dhis.startup.InitTableAlteror">
+    <property name="name" value="TableAlteror" />
+    <property name="runlevel" value="1" />
+    <property name="skipInTests" value="true" />
+  </bean>
+
   <bean id="org.hisp.dhis.period.PeriodTypePopulator" class="org.hisp.dhis.period.PeriodTypePopulator">
     <property name="periodStore" ref="org.hisp.dhis.period.PeriodStore" />
     <property name="name" value="PeriodTypePopulator" />
-    <property name="runlevel" value="1" />
+    <property name="runlevel" value="2" />
   </bean>
 
   <bean id="org.hisp.dhis.dataelement.DataElementDefaultDimensionPopulator"
@@ -924,18 +930,18 @@
     <property name="conceptService" ref="org.hisp.dhis.concept.ConceptService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
     <property name="name" value="DataElementDefaultDimensionPopulator" />
-    <property name="runlevel" value="1" />
+    <property name="runlevel" value="2" />
   </bean>
 
   <bean id="org.hisp.dhis.startup.TableAlteror" class="org.hisp.dhis.startup.TableAlteror">
     <property name="name" value="TableAlteror" />
-    <property name="runlevel" value="2" />
+    <property name="runlevel" value="3" />
     <property name="skipInTests" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.common.IdentityPopulator" class="org.hisp.dhis.common.IdentityPopulator">
     <property name="name" value="IdentityPopulator" />
-    <property name="runlevel" value="3" />
+    <property name="runlevel" value="4" />
     <property name="skipInTests" value="true" />
     <property name="tables">
       <list>
@@ -975,35 +981,35 @@
 
   <bean id="org.hisp.dhis.startup.TableCreator" class="org.hisp.dhis.startup.TableCreator">
     <property name="name" value="TableCreator" />
-    <property name="runlevel" value="3" />
+    <property name="runlevel" value="5" />
   </bean>
 
   <bean id="org.hisp.dhis.startup.MapViewUpgrader" class="org.hisp.dhis.startup.MapViewUpgrader">
     <property name="statementManager" ref="statementManager" />
     <property name="batchHandlerFactory" ref="batchHandlerFactory" />
     <property name="name" value="MapViewUpgrader" />
-    <property name="runlevel" value="4" />
+    <property name="runlevel" value="7" />
     <property name="skipInTests" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.dataentryform.DataEntryFormUpgrader" class="org.hisp.dhis.dataentryform.DataEntryFormUpgrader">
     <property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
-    <property name="runlevel" value="5" />
+    <property name="runlevel" value="7" />
     <property name="skipInTests" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.startup.ExpressionUpgrader" class="org.hisp.dhis.startup.ExpressionUpgrader">
-    <property name="runlevel" value="6" />
+    <property name="runlevel" value="8" />
     <property name="skipInTests" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.startup.ConfigurationPopulator" class="org.hisp.dhis.startup.ConfigurationPopulator">
-    <property name="runlevel" value="7" />
+    <property name="runlevel" value="9" />
     <property name="skipInTests" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.startup.I18nLocalePopulator" class="org.hisp.dhis.startup.I18nLocalePopulator">
-    <property name="runlevel" value="7" />
+    <property name="runlevel" value="9" />
     <property name="skipInTests" value="true" />
   </bean>
 
@@ -1013,6 +1019,7 @@
     <property name="arguments">
       <list>
         <list>
+          <ref local="org.hisp.dhis.startup.InitTableAlteror" />
           <ref local="org.hisp.dhis.startup.TableAlteror" />
           <ref local="org.hisp.dhis.startup.MapViewUpgrader" />
           <ref local="org.hisp.dhis.common.IdentityPopulator" />