← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 887: Improved the startup routine for categories, it now updates primary keys and removes old foreign ...

 

------------------------------------------------------------
revno: 887
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-10-19 20:09:13 +0200
message:
  Improved the startup routine for categories, it now updates primary keys and removes old foreign keys to reflect the change to list and 1-n.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/OptionsCategoriesDefaultSortOrderPopulator.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/dataelement/OptionsCategoriesDefaultSortOrderPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/OptionsCategoriesDefaultSortOrderPopulator.java	2009-10-19 17:10:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/OptionsCategoriesDefaultSortOrderPopulator.java	2009-10-19 18:09:13 +0000
@@ -40,7 +40,7 @@
 public class OptionsCategoriesDefaultSortOrderPopulator
     extends AbstractStartupRoutine
 {
-    private static final Log LOG = LogFactory.getLog( OptionsCategoriesDefaultSortOrderPopulator.class );
+    private static final Log log = LogFactory.getLog( OptionsCategoriesDefaultSortOrderPopulator.class );
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -60,16 +60,47 @@
     @Transactional
     public void execute()
     {
-        statementManager.getHolder().executeUpdate( "update categoryoptioncombos_categoryoptions set sort_order=categoryoptionid where sort_order is NULL or sort_order=0" );
-        
-        LOG.info( "Updated categoryoptioncombos_categoryoptions" );
-        
-        statementManager.getHolder().executeUpdate( "update categorycombos_categories set sort_order=categoryid where sort_order is NULL or sort_order=0" );
-        
-        LOG.info( "Updated categorycombos_categories" );       
-        
-        statementManager.getHolder().executeUpdate( "update categories_categoryoptions set sort_order=categoryoptionid where sort_order is NULL or sort_order=0" );
-        
-        LOG.info( "Updated categories_categoryoptions" );  
+        //categories_categoryoptions
+        executeSql( "UPDATE categories_categoryoptions SET sort_order=categoryoptionid WHERE sort_order is NULL OR sort_order=0" );
+        executeSql( "ALTER TABLE categories_categoryoptions DROP CONSTRAINT categories_categoryoptions_pkey" );
+        executeSql( "ALTER TABLE categories_categoryoptions ADD CONSTRAINT categories_categoryoptions_pkey PRIMARY KEY (categoryid, sort_order)" );
+
+        //categorycombos_categories
+        executeSql( "update categorycombos_categories SET sort_order=categoryid where sort_order is NULL or sort_order=0" );
+        executeSql( "ALTER TABLE categorycombos_categories DROP CONSTRAINT categorycombos_categories_pkey" );
+        executeSql( "ALTER TABLE categorycombos_categories ADD CONSTRAINT categorycombos_categories_pkey PRIMARY KEY (categorycomboid, sort_order)" );
+        
+        //categorycombos_optioncombos
+        executeSql( "ALTER TABLE categorycombos_optioncombos DROP CONSTRAINT categorycombos_optioncombos_pkey" );
+        executeSql( "ALTER TABLE categorycombos_optioncombos ADD CONSTRAINT categorycombos_optioncombos_pkey PRIMARY KEY (categoryoptioncomboid)" );
+        executeSql( "ALTER TABLE categorycombos_optioncombos DROP CONSTRAINT fk4bae70f697e49675" );
+        
+        //categoryoptioncombo
+        executeSql( "ALTER TABLE categoryoptioncombo DROP COLUMN displayorder" );
+        
+        //categoryoptioncombos_categoryoptions
+        executeSql( "update categoryoptioncombos_categoryoptions SET sort_order=categoryoptionid where sort_order is NULL or sort_order=0" );
+        executeSql( "ALTER TABLE categoryoptioncombos_categoryoptions DROP CONSTRAINT categoryoptioncombos_categoryoptions_pkey" );
+        executeSql( "ALTER TABLE categoryoptioncombos_categoryoptions ADD CONSTRAINT categoryoptioncombos_categoryoptions_pkey PRIMARY KEY (categoryoptioncomboid, sort_order)" );
+        
+        //dataelementcategoryoption
+        executeSql( "ALTER TABLE dataelementcategoryoption DROP COLUMN shortname" );
+        executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT fk_dataelement_categoryid" );
+        executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT dataelementcategoryoption_name_key" );
+        executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT dataelementcategoryoption_shortname_key" );
+        
+        log.info( "Updated Category sort order and primary keys" );  
+    }
+    
+    private void executeSql( String sql )
+    {
+        try
+        {
+            statementManager.getHolder().executeUpdate( sql );
+        }
+        catch ( Exception ex )
+        {
+            log.info( ex );
+        }
     }
 }

=== 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	2009-10-19 17:10:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2009-10-19 18:09:13 +0000
@@ -260,6 +260,7 @@
     class="org.hisp.dhis.dataelement.OptionsCategoriesDefaultSortOrderPopulator">
     <property name="statementManager" ref="statementManager"/>
     <property name="runlevel" value="1"/>
+	<property name="skipInTests" value="true"/>
   </bean>
 	
   <bean id="org.hisp.dhis.expression.MultiDimensionExpressionUpgrader"