← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13791: Fixed bug with analytics related to index creation

 

------------------------------------------------------------
revno: 13791
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-01-20 21:12:22 +0100
message:
  Fixed bug with analytics related to index creation
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-12-10 14:17:42 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-01-20 20:12:22 +0000
@@ -35,6 +35,7 @@
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Future;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.AnalyticsIndex;
@@ -154,13 +155,15 @@
                 break taskLoop;
             }
             
-            final String index = PREFIX_INDEX + inx.getColumn() + "_" + inx.getTable() + "_" + CodeGenerator.generateCode();
-            
-            final String sql = "create index " + index + " on " + inx.getTable() + " (" + inx.getColumn() + ")";
-                
-            executeSilently( sql );
-            
-            log.info( "Created index: " + index );
+            final String indexName = quote( PREFIX_INDEX + removeQuote( inx.getColumn() ) + "_" + inx.getTable() + "_" + CodeGenerator.generateCode() );
+            
+            final String sql = "create index " + indexName + " on " + inx.getTable() + " (" + inx.getColumn() + ")";
+            
+            log.debug( "Create index SQL: " + sql );
+            
+            jdbcTemplate.execute( sql );
+            
+            log.info( "Created index: " + indexName );
         }
         
         return null;
@@ -241,6 +244,14 @@
     }
     
     /**
+     * Remove quotes from the given column name.
+     */
+    protected String removeQuote( String column )
+    {
+        return column != null ? column.replaceAll( statementBuilder.getColumnQuote(), StringUtils.EMPTY ) : null;
+    }
+    
+    /**
      * Indicates whether the given table exists and has at least one row.
      */
     protected boolean hasRows( String tableName )