← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2073: Seperate the sql to support mysql.

 

------------------------------------------------------------
revno: 2073
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Sun 2010-07-04 11:39:44 +0700
message:
  Seperate the sql to support mysql.
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.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-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java	2010-06-28 15:31:34 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java	2010-07-04 04:39:44 +0000
@@ -28,10 +28,8 @@
  */
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Set;
-
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -73,9 +71,7 @@
         }
 
         List<OrganisationUnit> deletedOrgUnits = pruneOrganisationUnitLocal( organisationUnit );
-
-        Collections.reverse( deletedOrgUnits );
-
+        
         dataPruneStore.deleteMultiOrganisationUnit( deletedOrgUnits );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java	2010-06-28 15:31:34 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java	2010-07-04 04:39:44 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataprune.DataPruneStore;
@@ -63,30 +64,76 @@
         
         String orgUnitIds = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( OrganisationUnit.class, orgUnits )) ;
         
-        String sql = "delete from datasetlocksource where sourceid in (" + orgUnitIds + ");" + 
-                        "delete from completedatasetregistration where sourceid in (" + orgUnitIds + ");" +
-                        "delete from datasetsource where sourceid in (" + orgUnitIds + ");" +
-                        "delete from frequencyoverrideassociation where sourceid in (" + orgUnitIds + ");" +
-                        "delete from minmaxdataelement where sourceid in (" + orgUnitIds + ");" +
-                        "delete from orgunitgroupmembers where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from usermembership where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from datamartexportorgunits where orgunitid in (" + orgUnitIds + ");" +
-                        "delete from excelgroup_associations where organisationid in (" + orgUnitIds + ");" +
-                        "delete from reportexcel_associations where organisationid in (" + orgUnitIds + ");" +
-                        "delete from maporganisationunitrelation where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from maporganisationunitrelation where mapid in (select mapid from map where organisationunitid in (" + orgUnitIds + "));" +
-                        "delete from map where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from patientidentifier where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from program_organisationunits where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from chart_organisationunits where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from reporttable_organisationunits where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from datavalue_audit where (dataelementid, periodid, sourceid, categoryoptioncomboid) in (select dataelementid, periodid, sourceid, categoryoptioncomboid from datavalue where sourceid in (" + orgUnitIds + "));" + 
-                        "delete from datavalue where sourceid in (" + orgUnitIds + ");" + 
-                        "delete from organisationunit where organisationunitid in (" + orgUnitIds + ");" +
-                        "delete from source where sourceid in (" + orgUnitIds + ");";
-        
         long before = System.currentTimeMillis();
-        jdbcTemplate.execute( sql );
+        
+        String sql = "delete from datasetlocksource where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+        
+        sql = "delete from completedatasetregistration where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from datasetsource where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from frequencyoverrideassociation where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from minmaxdataelement where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from orgunitgroupmembers where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from usermembership where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from datamartexportorgunits where orgunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from excelgroup_associations where organisationid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from reportexcel_associations where organisationid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from maporganisationunitrelation where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from maporganisationunitrelation where mapid in (select mapid from map where organisationunitid in ("
+            + orgUnitIds + "));";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from map where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from patientidentifier where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from program_organisationunits where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from chart_organisationunits where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from reporttable_organisationunits where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from datavalue_audit where (dataelementid, periodid, sourceid, categoryoptioncomboid) in (select dataelementid, periodid, sourceid, categoryoptioncomboid from datavalue where sourceid in ("
+            + orgUnitIds + "));";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from datavalue where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "update organisationunit set parentid=null where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from organisationunit where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
+        sql = "delete from source where sourceid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+        
         log.info( "Deleting " + orgUnits.size() + " organisations units sucessfully in " + (System.currentTimeMillis() - before) + " ms.");
     }
 }