← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21595: Resource tables. Drop temp tables if they already exists.

 

------------------------------------------------------------
revno: 21595
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 17:30:33 +0100
message:
  Resource tables. Drop temp tables if they already exists.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTable.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.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-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTable.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTable.java	2016-01-05 16:30:33 +0000
@@ -76,6 +76,11 @@
         return "drop table " + getTableName() + ";";
     }
     
+    public final String getDropTempTableStatement()
+    {
+        return "drop table " + getTempTableName() + ";";
+    }
+    
     public final String getRenameTempTableStatement()
     {
         return "alter table " + getTempTableName() + " rename to " + getTableName() + ";";

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2016-01-05 16:30:33 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.dbms.DbmsManager;
 import org.hisp.dhis.resourcetable.ResourceTable;
 import org.hisp.dhis.resourcetable.ResourceTableStore;
+import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 /**
@@ -76,7 +77,16 @@
         final List<String> createIndexSql = resourceTable.getCreateIndexStatements();
 
         // ---------------------------------------------------------------------
-        // Create table
+        // Drop temporary table if it exists
+        // ---------------------------------------------------------------------
+
+        if ( dbmsManager.tableExists( resourceTable.getTempTableName() ) )
+        {
+            jdbcTemplate.execute( resourceTable.getDropTempTableStatement() );
+        }
+                
+        // ---------------------------------------------------------------------
+        // Create temporary table
         // ---------------------------------------------------------------------
 
         log.info( "Create table SQL: " + createTableSql );
@@ -84,7 +94,7 @@
         jdbcTemplate.execute( createTableSql );
 
         // ---------------------------------------------------------------------
-        // Populate table through SQL or object batch update
+        // Populate temporary table through SQL or object batch update
         // ---------------------------------------------------------------------
 
         if ( populateTableSql.isPresent() )