← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5274: Fixed minor bug with sql encoding. Centralized some methods in statement builders to an abstract ...

 

------------------------------------------------------------
revno: 5274
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-12-03 15:23:43 +0100
message:
  Fixed minor bug with sql encoding. Centralized some methods in statement builders to an abstract class
added:
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java
modified:
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.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
=== added file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java	2011-12-03 14:23:43 +0000
@@ -0,0 +1,92 @@
+package org.hisp.dhis.jdbc.statementbuilder;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.jdbc.StatementBuilder;
+
+/**
+ * @author Lars Helge Overland
+ */
+public abstract class AbstractStatementBuilder
+    implements StatementBuilder
+{
+    public String encode( String value )
+    {
+        if ( value != null )
+        {
+            value = value.endsWith( "\\" ) ? value.substring( 0, value.length() - 1 ) : value;
+            value = value.replaceAll( QUOTE, QUOTE + QUOTE );
+        }
+        
+        return QUOTE + value + QUOTE;
+    }
+
+    public String getCreateAggregatedDataValueTable()
+    {
+        return
+            "CREATE TABLE aggregateddatavalue ( " +
+            "dataelementid INTEGER, " +
+            "categoryoptioncomboid INTEGER, " +
+            "periodid INTEGER, " +
+            "organisationunitid INTEGER, " +
+            "periodtypeid INTEGER, " +
+            "level INTEGER, " +
+            "value " + getDoubleColumnType() + " );";
+    }
+    
+    public String getCreateAggregatedIndicatorTable()
+    {
+        return
+            "CREATE TABLE aggregatedindicatorvalue ( " +
+            "indicatorid INTEGER, " +
+            "periodid INTEGER, " +
+            "organisationunitid INTEGER, " +
+            "periodtypeid INTEGER, " +
+            "level INTEGER, " +
+            "annualized VARCHAR( 10 ), " +
+            "factor " + getDoubleColumnType() + ", " +
+            "value " + getDoubleColumnType() + ", " +
+            "numeratorvalue " + getDoubleColumnType() + ", " +
+            "denominatorvalue " + getDoubleColumnType() + " );";
+    }
+
+    public String getCreateDataSetCompletenessTable()
+    {
+        return
+            "CREATE TABLE aggregateddatasetcompleteness ( " +
+            "datasetid INTEGER, " +
+            "periodid INTEGER, " +
+            "periodname VARCHAR( 30 ), " +
+            "organisationunitid INTEGER, " +
+            "sources INTEGER, " +
+            "registrations INTEGER, " +
+            "registrationsOnTime INTEGER, " +
+            "value " + getDoubleColumnType() + ", " +
+            "valueOnTime " + getDoubleColumnType() + " );";
+    }
+}

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2011-06-04 14:46:25 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2011-12-03 14:23:43 +0000
@@ -29,33 +29,22 @@
 
 import static org.hisp.dhis.system.util.DateUtils.getSqlDateString;
 
-import org.hisp.dhis.jdbc.StatementBuilder;
+import java.util.List;
+
 import org.hisp.dhis.period.Period;
-import java.util.List;
 
 /**
  * @author Lars Helge Overland
  * @version $Id$
  */
 public class DerbyStatementBuilder
-    implements StatementBuilder
+    extends AbstractStatementBuilder
 {
     public String getDoubleColumnType()
     {
         return "DOUBLE";
     }
     
-    public String encode( String value )
-    {
-        if ( value != null )
-        {
-            value = value.endsWith( "\\" ) ? value.substring( 0, value.length() - 1 ) : value;
-            value = value.replaceAll( QUOTE, QUOTE + QUOTE );
-        }
-        
-        return QUOTE + value + QUOTE;
-    }
-    
     public String getPeriodIdentifierStatement( Period period )
     {
         return 
@@ -64,50 +53,6 @@
             "AND enddate='" + getSqlDateString( period.getEndDate() ) + "'";
     }    
 
-    public String getCreateAggregatedDataValueTable()
-    {
-        return
-            "CREATE TABLE aggregateddatavalue ( " +
-            "dataelementid INTEGER, " +
-            "categoryoptioncomboid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "value DOUBLE );";
-    }
-    
-    public String getCreateAggregatedIndicatorTable()
-    {
-        return
-            "CREATE TABLE aggregatedindicatorvalue ( " +
-            "indicatorid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "annualized VARCHAR( 10 ), " +
-            "factor DOUBLE, " +
-            "value DOUBLE, " +
-            "numeratorvalue DOUBLE, " +
-            "denominatorvalue DOUBLE );";
-    }
-
-    public String getCreateDataSetCompletenessTable()
-    {
-        return 
-            "CREATE TABLE aggregateddatasetcompleteness ( " +
-            "datasetid INTEGER, " +
-            "periodid INTEGER, " +
-            "periodname VARCHAR( 30 ), " +
-            "organisationunitid INTEGER, " +
-            "sources INTEGER, " +
-            "registrations INTEGER, " +
-            "registrationsOnTime INTEGER, " +
-            "value DOUBLE, " +
-            "valueOnTime DOUBLE );";
-    }
-
     public String getDeleteZeroDataValues()
     {
         return 
@@ -245,7 +190,6 @@
 
     public String deleteOldestOverlappingDataValue()
     {
-
         return "DELETE FROM datavalue AS d " 
             + "USING datavaluearchive AS a "
             + "WHERE d.dataelementid=a.dataelementid " 

=== 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	2011-06-04 14:46:25 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2011-12-03 14:23:43 +0000
@@ -29,32 +29,21 @@
 
 import static org.hisp.dhis.system.util.DateUtils.getSqlDateString;
 
-import org.hisp.dhis.jdbc.StatementBuilder;
+import java.util.List;
+
 import org.hisp.dhis.period.Period;
-import java.util.List;
 /**
  * @author Lars Helge Overland
  * @version $Id: H2StatementBuilder.java 5715 2008-09-17 14:05:28Z larshelg $
  */
 public class H2StatementBuilder
-    implements StatementBuilder
+    extends AbstractStatementBuilder
 {
     public String getDoubleColumnType()
     {
         return "DOUBLE";
     }
     
-    public String encode( String value )
-    {
-        if ( value != null )
-        {
-            value = value.endsWith( "\\" ) ? value.substring( 0, value.length() - 1 ) : value;
-            value = value.replaceAll( QUOTE, QUOTE + QUOTE );
-        }
-        
-        return QUOTE + value + QUOTE;
-    }
-    
     public String getPeriodIdentifierStatement( Period period )
     {
         return
@@ -62,53 +51,7 @@
             "AND startdate='" + getSqlDateString( period.getStartDate() ) + "' " +
             "AND enddate='" + getSqlDateString( period.getEndDate() ) + "'";
     }
-    
-    public String getCreateAggregatedDataValueTable()
-    {
-        return
-            "CREATE TABLE aggregateddatavalue ( " +
-            "dataelementid INTEGER, " +
-            "categoryoptioncomboid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "value DOUBLE, " +
-            "modified TIMESTAMP DEFAULT now() );";
-    }
-    
-    public String getCreateAggregatedIndicatorTable()
-    {
-        return
-            "CREATE TABLE aggregatedindicatorvalue ( " +
-            "indicatorid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "annualized VARCHAR( 10 ), " +
-            "factor DOUBLE, " +
-            "value DOUBLE, " +
-            "numeratorvalue DOUBLE, " +
-            "denominatorvalue DOUBLE, " +
-            "modified TIMESTAMP DEFAULT now() );";
-    }
-
-    public String getCreateDataSetCompletenessTable()
-    {
-        return
-            "CREATE TABLE aggregateddatasetcompleteness ( " +
-            "datasetid INTEGER, " +
-            "periodid INTEGER, " +
-            "periodname VARCHAR( 30 ), " +
-            "organisationunitid INTEGER, " +
-            "sources INTEGER, " +
-            "registrations INTEGER, " +
-            "registrationsOnTime INTEGER, " +
-            "value DOUBLE, " +
-            "valueOnTime DOUBLE );";
-    }
-    
+        
     public String getDeleteZeroDataValues()
     {
         return

=== 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	2011-05-23 06:10:58 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2011-12-03 14:23:43 +0000
@@ -29,33 +29,22 @@
 
 import static org.hisp.dhis.system.util.DateUtils.getSqlDateString;
 
-import org.hisp.dhis.jdbc.StatementBuilder;
+import java.util.List;
+
 import org.hisp.dhis.period.Period;
-import java.util.List;
 
 /**
  * @author Lars Helge Overland
  * @version $Id: MySQLStatementBuilder.java 5715 2008-09-17 14:05:28Z larshelg $
  */
 public class MySQLStatementBuilder
-    implements StatementBuilder
+    extends AbstractStatementBuilder
 {
     public String getDoubleColumnType()
     {
         return "DECIMAL";
     }
 
-    public String encode( String value )
-    {
-        if ( value != null )
-        {
-            value = value.endsWith( "\\" ) ? value.substring( 0, value.length() - 1 ) : value;
-            value = value.replaceAll( QUOTE, "\\\\" + QUOTE );
-        }
-        
-        return QUOTE + value + QUOTE;
-    }
-    
     public String getPeriodIdentifierStatement( Period period )
     {
         return
@@ -64,52 +53,6 @@
             "AND enddate='" + getSqlDateString( period.getEndDate() ) + "'";
     }    
 
-    public String getCreateAggregatedDataValueTable()
-    {
-        return
-            "CREATE TABLE aggregateddatavalue ( " +
-            "dataelementid INTEGER, " +
-            "categoryoptioncomboid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "value DOUBLE, " +
-            "modified TIMESTAMP);";
-    }
-    
-    public String getCreateAggregatedIndicatorTable()
-    {
-        return
-            "CREATE TABLE aggregatedindicatorvalue ( " +
-            "indicatorid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "annualized VARCHAR( 10 ), " +
-            "factor DOUBLE, " +
-            "value DOUBLE, " +
-            "numeratorvalue DOUBLE, " +
-            "denominatorvalue DOUBLE, " +
-            "modified TIMESTAMP);";
-    }
-
-    public String getCreateDataSetCompletenessTable()
-    {
-        return
-            "CREATE TABLE aggregateddatasetcompleteness ( " +
-            "datasetid INTEGER, " +
-            "periodid INTEGER, " +
-            "periodname VARCHAR( 30 ), " +
-            "organisationunitid INTEGER, " +
-            "sources INTEGER, " +
-            "registrations INTEGER, " +
-            "registrationsOnTime INTEGER, " +
-            "value DOUBLE, " +
-            "valueOnTime DOUBLE );";
-    }
-
     public String getDeleteZeroDataValues()
     {
         return

=== 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	2011-05-23 06:10:58 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2011-12-03 14:23:43 +0000
@@ -29,33 +29,22 @@
 
 import static org.hisp.dhis.system.util.DateUtils.getSqlDateString;
 
-import org.hisp.dhis.jdbc.StatementBuilder;
+import java.util.List;
+
 import org.hisp.dhis.period.Period;
-import java.util.List;
 
 /**
  * @author Lars Helge Overland
  * @version $Id: PostgreSQLStatementBuilder.java 5715 2008-09-17 14:05:28Z larshelg $
  */
 public class PostgreSQLStatementBuilder
-    implements StatementBuilder
+    extends AbstractStatementBuilder
 {    
     public String getDoubleColumnType()
     {
         return "DOUBLE PRECISION";
     }
     
-    public String encode( String value )
-    {
-        if ( value != null )
-        {
-            value = value.endsWith( "\\" ) ? value.substring( 0, value.length() - 1 ) : value;
-            value = value.replaceAll( QUOTE, "\\\\" + QUOTE );
-        }
-        
-        return QUOTE + value + QUOTE;
-    }
-    
     public String getPeriodIdentifierStatement( Period period )
     {
         return
@@ -64,50 +53,6 @@
             "AND enddate='" + getSqlDateString( period.getEndDate() ) + "'";
     }
 
-    public String getCreateAggregatedDataValueTable()
-    {
-        return
-            "CREATE TABLE aggregateddatavalue ( " +
-            "dataelementid INTEGER, " +
-            "categoryoptioncomboid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "value DOUBLE PRECISION );";
-    }
-    
-    public String getCreateAggregatedIndicatorTable()
-    {
-        return
-            "CREATE TABLE aggregatedindicatorvalue ( " +
-            "indicatorid INTEGER, " +
-            "periodid INTEGER, " +
-            "organisationunitid INTEGER, " +
-            "periodtypeid INTEGER, " +
-            "level INTEGER, " +
-            "annualized VARCHAR( 10 ), " +
-            "factor DOUBLE PRECISION, " +
-            "value DOUBLE PRECISION, " +
-            "numeratorvalue DOUBLE PRECISION, " +
-            "denominatorvalue DOUBLE PRECISION );";
-    }
-
-    public String getCreateDataSetCompletenessTable()
-    {
-        return
-            "CREATE TABLE aggregateddatasetcompleteness ( " +
-            "datasetid INTEGER, " +
-            "periodid INTEGER, " +
-            "periodname VARCHAR( 30 ), " +
-            "organisationunitid INTEGER, " +
-            "sources INTEGER, " +
-            "registrations INTEGER, " +
-            "registrationsOnTime INTEGER, " +
-            "value DOUBLE PRECISION, " +
-            "valueOnTime DOUBLE PRECISION );";
-    }
-
     public String getDeleteZeroDataValues()
     {
         return