← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11851: Reintroduced the name columns in group set resource tables, this time with quoted column names

 

------------------------------------------------------------
revno: 11851
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-01 20:30:05 +0200
message:
  Reintroduced the name columns in group set resource tables, this time with quoted column names
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
  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/statement/CreateCategoryTableStatement.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateDataElementGroupSetTableStatement.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateIndicatorGroupSetTableStatement.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java
  dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.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/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2013-09-01 18:30:05 +0000
@@ -293,13 +293,14 @@
             {
                 DataElementGroup group = groupSet.getGroup( dataElement );
                 
+                values.add( group != null ? group.getName() : null );
                 values.add( group != null ? group.getUid() : null );
             }
             
             batchArgs.add( values.toArray() );
         }
         
-        resourceTableStore.batchUpdate( groupSets.size() + 2, CreateDataElementGroupSetTableStatement.TABLE_NAME, batchArgs );
+        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 2, CreateDataElementGroupSetTableStatement.TABLE_NAME, batchArgs );
     }
 
     // -------------------------------------------------------------------------
@@ -339,13 +340,14 @@
             {
                 IndicatorGroup group = groupSet.getGroup( indicator );
                 
+                values.add( group != null ? group.getName() : null );
                 values.add( group != null ? group.getUid() : null );
             }
             
             batchArgs.add( values.toArray() );
         }
         
-        resourceTableStore.batchUpdate( groupSets.size() + 2, CreateIndicatorGroupSetTableStatement.TABLE_NAME, batchArgs );
+        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 2, CreateIndicatorGroupSetTableStatement.TABLE_NAME, batchArgs );
     }
     
     // -------------------------------------------------------------------------
@@ -387,13 +389,14 @@
             {
                 OrganisationUnitGroup group = groupSet.getGroup( unit );
                 
+                values.add( group != null ? group.getName() : null );
                 values.add( group != null ? group.getUid() : null );
             }
 
             batchArgs.add( values.toArray() );
         }
 
-        resourceTableStore.batchUpdate( groupSets.size() + 2, CreateOrganisationUnitGroupSetTableStatement.TABLE_NAME, batchArgs );
+        resourceTableStore.batchUpdate( ( groupSets.size() * 2 ) + 2, CreateOrganisationUnitGroupSetTableStatement.TABLE_NAME, batchArgs );
     }
     
     // -------------------------------------------------------------------------

=== 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	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2013-09-01 18:30:05 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
+import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.resourcetable.ResourceTableStore;
@@ -64,6 +65,13 @@
     {
         this.jdbcTemplate = jdbcTemplate;
     }
+    
+    private StatementBuilder statementBuilder;
+
+    public void setStatementBuilder( StatementBuilder statementBuilder )
+    {
+        this.statementBuilder = statementBuilder;
+    }
 
     // -------------------------------------------------------------------------
     // ResourceTableStore implementation
@@ -159,7 +167,7 @@
             // Do nothing, table does not exist
         }
         
-        Statement statement = new CreateDataElementGroupSetTableStatement( groupSets );
+        Statement statement = new CreateDataElementGroupSetTableStatement( groupSets, statementBuilder.getColumnQuote() );
         
         jdbcTemplate.execute( statement.getStatement() );
     }
@@ -179,7 +187,7 @@
             // Do nothing, table does not exist
         }
         
-        Statement statement = new CreateIndicatorGroupSetTableStatement( groupSets );
+        Statement statement = new CreateIndicatorGroupSetTableStatement( groupSets, statementBuilder.getColumnQuote() );
         
         jdbcTemplate.execute( statement.getStatement() );
     }
@@ -199,7 +207,7 @@
             // Do nothing, table does not exist
         }
         
-        Statement statement = new CreateOrganisationUnitGroupSetTableStatement( groupSets );
+        Statement statement = new CreateOrganisationUnitGroupSetTableStatement( groupSets, statementBuilder.getColumnQuote() );
         
         jdbcTemplate.execute( statement.getStatement() );
     }
@@ -219,7 +227,7 @@
             // Do nothing, table does not exist
         }
         
-        Statement statement = new CreateCategoryTableStatement( categories );
+        Statement statement = new CreateCategoryTableStatement( categories, statementBuilder.getColumnQuote() );
         
         jdbcTemplate.execute( statement.getStatement() );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateCategoryTableStatement.java	2013-09-01 18:30:05 +0000
@@ -34,7 +34,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataelement.DataElementCategory;
-import org.hisp.dhis.system.util.CodecUtils;
 
 /**
  * @author Lars Helge Overland
@@ -49,10 +48,13 @@
     public static final String TABLE_NAME = "_categorystructure";
     
     private List<DataElementCategory> categories;
+
+    private String quote;
     
-    public CreateCategoryTableStatement( List<DataElementCategory> categories )
+    public CreateCategoryTableStatement( List<DataElementCategory> categories, String quote )
     {
         this.categories = categories;
+        this.quote = quote;
     }    
 
     public String getStatement()
@@ -63,7 +65,7 @@
         
         for ( DataElementCategory category : categories )
         {
-            statement += CodecUtils.databaseEncode( category.getName() ) + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
+            statement += quote + category.getName() + quote + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
             statement += category.getUid() + SPACE + "CHARACTER(11)" + SEPARATOR;
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateDataElementGroupSetTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateDataElementGroupSetTableStatement.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateDataElementGroupSetTableStatement.java	2013-09-01 18:30:05 +0000
@@ -49,9 +49,12 @@
     
     private List<DataElementGroupSet> groupSets;
     
-    public CreateDataElementGroupSetTableStatement( List<DataElementGroupSet> groupSets )
+    private String quote;
+    
+    public CreateDataElementGroupSetTableStatement( List<DataElementGroupSet> groupSets, String quote )
     {
         this.groupSets = groupSets;
+        this.quote = quote;
     }
     
     public String getStatement()
@@ -62,6 +65,7 @@
         
         for ( DataElementGroupSet groupSet : groupSets )
         {
+            statement += quote + groupSet.getName() + quote + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
             statement += groupSet.getUid() + SPACE + "CHARACTER(11)" + SEPARATOR;
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateIndicatorGroupSetTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateIndicatorGroupSetTableStatement.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateIndicatorGroupSetTableStatement.java	2013-09-01 18:30:05 +0000
@@ -47,11 +47,15 @@
     
     public static final String TABLE_NAME = "_indicatorgroupsetstructure";
     
-    private List<IndicatorGroupSet> groupSets;
-    
-    public CreateIndicatorGroupSetTableStatement( List<IndicatorGroupSet> groupSets )
+    private List<IndicatorGroupSet> groupSets;    
+
+    private String quote;
+    
+    
+    public CreateIndicatorGroupSetTableStatement( List<IndicatorGroupSet> groupSets, String quote )
     {
         this.groupSets = groupSets;
+        this.quote = quote;
     }
     
     public String getStatement()
@@ -62,6 +66,7 @@
         
         for ( IndicatorGroupSet groupSet : groupSets )
         {
+            statement += quote + groupSet.getName() + quote + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
             statement += groupSet.getUid() + SPACE + "CHARACTER(11)" + SEPARATOR;
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/statement/CreateOrganisationUnitGroupSetTableStatement.java	2013-09-01 18:30:05 +0000
@@ -48,10 +48,13 @@
     private static final String LONG_TEXT_COLUMN_TYPE = "VARCHAR (250)";
     
     private List<OrganisationUnitGroupSet> groupSets;
+
+    private String quote;
     
-    public CreateOrganisationUnitGroupSetTableStatement( List<OrganisationUnitGroupSet> groupSets )
+    public CreateOrganisationUnitGroupSetTableStatement( List<OrganisationUnitGroupSet> groupSets, String quote )
     {
         this.groupSets = groupSets;
+        this.quote = quote;
     }
     
     public String getStatement()
@@ -62,6 +65,7 @@
                 
         for ( OrganisationUnitGroupSet groupSet : groupSets )
         {
+            statement += quote + groupSet.getName() + quote + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR;
             statement += groupSet.getUid() + SPACE + "CHARACTER(11)" + SEPARATOR;
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2013-04-30 08:03:51 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2013-09-01 18:30:05 +0000
@@ -6,6 +6,7 @@
 
   <bean id="org.hisp.dhis.resourcetable.ResourceTableStore" class="org.hisp.dhis.resourcetable.jdbc.JdbcResourceTableStore">
     <property name="jdbcTemplate" ref="jdbcTemplate" />
+    <property name="statementBuilder" ref="statementBuilder" />
   </bean>
 
   <bean id="org.hisp.dhis.resourcetable.ResourceTableService" class="org.hisp.dhis.resourcetable.DefaultResourceTableService">

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2013-09-01 18:30:05 +0000
@@ -52,6 +52,13 @@
     String encode( String value );
     
     /**
+     * Returns the character used to quote database table and column names.
+     * 
+     * @return a quote character.
+     */
+    String getColumnQuote();
+    
+    /**
      * Returns statement for vacuum and analyze operations for a table. Returns
      * null if such statement is not relevant.
      * 

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2013-09-01 18:30:05 +0000
@@ -41,6 +41,12 @@
     {
         return "double";
     }
+    
+    @Override
+    public String getColumnQuote()
+    {
+        return "\"";
+    }
 
     @Override
     public String getVacuum( String table )

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2013-09-01 18:30:05 +0000
@@ -43,6 +43,12 @@
     }
 
     @Override
+    public String getColumnQuote()
+    {
+        return "`";
+    }
+
+    @Override
     public String getVacuum( String table )
     {
         return "optimize table " + table + ";";

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2013-09-01 18:30:05 +0000
@@ -43,6 +43,12 @@
     }
 
     @Override
+    public String getColumnQuote()
+    {
+        return "\"";
+    }
+
+    @Override
     public String getVacuum( String table )
     {
         return "vacuum analyze " + table + ";";