=== 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">
+