← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13962: Analytics, fixed issue with index names

 

------------------------------------------------------------
revno: 13962
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-02-09 17:58:24 +0200
message:
  Analytics, fixed issue with index names
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	2014-02-05 13:12:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-02-09 15:58:24 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.analytics.AnalyticsIndex;
 import org.hisp.dhis.analytics.AnalyticsTable;
 import org.hisp.dhis.analytics.AnalyticsTableManager;
+import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.jdbc.StatementBuilder;
@@ -154,7 +155,7 @@
                 break taskLoop;
             }
             
-            final String indexName = quote( PREFIX_INDEX + removeQuote( inx.getColumn() ) + "_" + inx.getTable() );
+            final String indexName = getIndexName( inx );
             
             final String sql = "create index " + indexName + " on " + inx.getTable() + " (" + inx.getColumn() + ")";
             
@@ -251,6 +252,23 @@
     }
     
     /**
+     * Remove temp part of name from the given column name.
+     */
+    protected String removeTemp( String column )
+    {
+        return column != null ? column.replaceAll( TABLE_TEMP_SUFFIX, StringUtils.EMPTY ) : null;
+    }
+    
+    /**
+     * Returns index name for column. Purpose of code suffix is to avoid uniqueness
+     * collision between indexes for temp and real tables.
+     */
+    protected String getIndexName( AnalyticsIndex inx )
+    {
+        return quote( PREFIX_INDEX + removeQuote( removeTemp( inx.getColumn() ) ) + "_" + inx.getTable() + "_" + CodeGenerator.generateCode( 5 ) );        
+    }
+    
+    /**
      * Indicates whether the given table exists and has at least one row.
      */
     protected boolean hasRows( String tableName )