← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10987: Analytics table manager, made pruning more robust

 

------------------------------------------------------------
revno: 10987
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-24 16:48:40 +0200
message:
  Analytics table manager, made pruning more robust
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.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-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2013-05-07 08:37:33 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2013-05-24 14:48:40 +0000
@@ -139,11 +139,7 @@
 
     public boolean pruneTable( String tableName )
     {
-        final String sql = "select * from " + tableName + " limit 1";
-        
-        final boolean hasRows = jdbcTemplate.queryForRowSet( sql ).next();
-        
-        if ( !hasRows )
+        if ( !hasRows( tableName ) )
         {
             final String sqlDrop = "drop table " + tableName;
             
@@ -192,6 +188,23 @@
     // -------------------------------------------------------------------------
   
     /**
+     * Indicates whether the given table exists and has at least one row.
+     */
+    protected boolean hasRows( String tableName )
+    {
+        final String sql = "select * from " + tableName + " limit 1";
+        
+        try
+        {
+            return jdbcTemplate.queryForRowSet( sql ).next();
+        }
+        catch ( BadSqlGrammarException ex )
+        {
+            return false;
+        }
+    }
+    
+    /**
      * Executes a SQL statement. Ignores existing tables/indexes when attempting
      * to create new.
      */