← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 149: Impl support for derby database

 

------------------------------------------------------------
revno: 149
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-04-03 15:27:40 +0200
message:
  Impl support for derby database
added:
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/identifier/DerbyIdentifierExtractor.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementDialect.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/IdentifierExtractorFactory.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/StatementBuilderFactory.java
  dhis-2/dhis-support/dhis-support-hibernate/pom.xml
  docs/Technical Architecture DHIS 2.doc

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementDialect.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementDialect.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementDialect.java	2009-04-03 13:27:40 +0000
@@ -36,5 +36,5 @@
     MYSQL,
     POSTGRESQL,
     H2,
-    HSQL
+    DERBY
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java	2009-03-13 11:51:35 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java	2009-04-03 13:27:40 +0000
@@ -41,16 +41,16 @@
     implements JDBCConfigurationProvider
 {
     private static final String KEY_DIALECT = "hibernate.dialect";
-    private static final String DIALECT_MYSQL = "org.hibernate.dialect.MySQLDialect";
-    private static final String DIALECT_POSTGRESQL = "org.hibernate.dialect.PostgreSQLDialect";
-    private static final String DIALECT_H2 = "org.hibernate.dialect.H2Dialect";
-    private static final String DIALECT_HSQL = "org.hibernate.dialect.HSQLDialect";
-    
     private static final String KEY_DRIVER = "hibernate.connection.driver_class";
     private static final String KEY_CONNECTION_URL = "hibernate.connection.url";
     private static final String KEY_USERNAME = "hibernate.connection.username";
     private static final String KEY_PASSWORD = "hibernate.connection.password";
     
+    private static final String DIALECT_MYSQL = "org.hibernate.dialect.MySQLDialect";
+    private static final String DIALECT_POSTGRESQL = "org.hibernate.dialect.PostgreSQLDialect";
+    private static final String DIALECT_H2 = "org.hibernate.dialect.H2Dialect";
+    private static final String DIALECT_DERBY = "org.hibernate.dialect.H2Dialect";
+        
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -84,9 +84,9 @@
         {
             config.setDialect( StatementDialect.H2 );
         }
-        else if ( hibernateConfiguration.getProperty( KEY_DIALECT ).equals( DIALECT_HSQL ) )
+        else if ( hibernateConfiguration.getProperty( KEY_DIALECT ).equals( DIALECT_DERBY ) )
         {
-            config.setDialect( StatementDialect.HSQL );
+            config.setDialect( StatementDialect.DERBY );
         }
         
         config.setDriverClass( hibernateConfiguration.getProperty( KEY_DRIVER ) );            

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/IdentifierExtractorFactory.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/IdentifierExtractorFactory.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/IdentifierExtractorFactory.java	2009-04-03 13:27:40 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.hisp.dhis.jdbc.StatementDialect;
+import org.hisp.dhis.jdbc.identifier.DerbyIdentifierExtractor;
 import org.hisp.dhis.jdbc.identifier.H2IdentifierExtractor;
 import org.hisp.dhis.jdbc.identifier.IdentifierExtractor;
 import org.hisp.dhis.jdbc.identifier.MySQLIdentifierExtractor;
@@ -59,6 +60,10 @@
         {
             return new H2IdentifierExtractor();
         }
+        else if ( dialect.equals( StatementDialect.DERBY ) )
+        {
+            return new DerbyIdentifierExtractor();
+        }
         else
         {
             throw new RuntimeException( "Unsupported dialect" );

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/StatementBuilderFactory.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/StatementBuilderFactory.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/factory/StatementBuilderFactory.java	2009-04-03 13:27:40 +0000
@@ -29,6 +29,7 @@
 
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.jdbc.StatementDialect;
+import org.hisp.dhis.jdbc.statementbuilder.DerbyStatementBuilder;
 import org.hisp.dhis.jdbc.statementbuilder.H2StatementBuilder;
 import org.hisp.dhis.jdbc.statementbuilder.MySQLStatementBuilder;
 import org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder;
@@ -59,6 +60,10 @@
         {
             return new H2StatementBuilder();
         }
+        else if ( dialect.equals( StatementDialect.DERBY ) )
+        {
+            return new DerbyStatementBuilder();
+        }
         else
         {
             throw new RuntimeException( "Unsupported dialect" );

=== added file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/identifier/DerbyIdentifierExtractor.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/identifier/DerbyIdentifierExtractor.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/identifier/DerbyIdentifierExtractor.java	2009-04-03 13:27:40 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.jdbc.identifier;
+
+/*
+ * Copyright (c) 2004-2007, 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 java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class DerbyIdentifierExtractor
+    implements IdentifierExtractor
+{
+    public Collection<Integer> extract( Statement statement, int statementCount )
+        throws SQLException
+    {
+        Collection<Integer> identifiers = new ArrayList<Integer>();
+        
+        int firstIdentifier = extract( statement );
+        
+        if ( firstIdentifier != 0 )
+        {
+            for ( int i = 0; i < statementCount; i++ )
+            {
+                int identifier = i + firstIdentifier;
+                
+                identifiers.add( identifier );
+            }
+        }
+        
+        return identifiers;
+    }
+    
+    public int extract( Statement statement )
+        throws SQLException
+    {
+        String sql = "values IDENTITY_VAL_LOCAL()";
+        
+        ResultSet resultSet = statement.executeQuery( sql );
+        
+        return resultSet.next() ? resultSet.getInt( 1 ) : 0;
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2009-04-03 13:27:40 +0000
@@ -0,0 +1,270 @@
+package org.hisp.dhis.jdbc.statementbuilder;
+
+/*
+ * Copyright (c) 2004-2007, 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 java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.RelativePeriodType;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class DerbyStatementBuilder
+    extends AbstractStatementBuilder
+{
+    // -------------------------------------------------------------------------
+    // Constructor
+    // -------------------------------------------------------------------------
+    
+    public DerbyStatementBuilder()
+    {
+        super();
+    }
+
+    // -------------------------------------------------------------------------
+    // AbstractStatementBuilder implementation
+    // -------------------------------------------------------------------------
+ 
+    public String getInsertStatementOpening( String table )
+    {
+        StringBuffer buffer = new StringBuffer();
+        
+        buffer.append( "INSERT INTO " + table + " (" );
+        
+        for ( String column : columns )
+        {
+            buffer.append( column + SEPARATOR );
+        }
+        
+        if ( columns.size() > 0 )
+        {
+            buffer.deleteCharAt( buffer.length() - 1 );
+        }
+        
+        buffer.append( BRACKET_END + " VALUES " );
+        
+        columns.clear();
+        
+        return buffer.toString();
+    }
+    
+    public String getNoColumnInsertStatementOpening( String table )
+    {
+        String sql = "INSERT INTO " + table + " VALUES ";
+        
+        return sql;
+    }
+    
+    public String getInsertStatementValues()
+    {
+        StringBuffer buffer = new StringBuffer();
+        
+        buffer.append( BRACKET_START );
+        
+        for ( String value : values )
+        {
+            buffer.append( value + SEPARATOR );
+        }
+        
+        if ( values.size() > 0 )
+        {
+            buffer.deleteCharAt( buffer.length() - 1 );
+        }
+        
+        buffer.append( BRACKET_END + SEPARATOR );
+        
+        values.clear();
+        
+        return buffer.toString();
+    }
+    
+    public String getUpdateStatement( String table )
+    {
+        StringBuffer buffer = new StringBuffer();
+        
+        buffer.append( "UPDATE " + table + " SET " );
+
+        Iterator<String> columnIterator = columns.iterator();
+        Iterator<String> valueIterator = values.iterator();
+        
+        while ( columnIterator.hasNext() )
+        {
+            buffer.append( columnIterator.next() + "=" + valueIterator.next() + SEPARATOR );
+        }
+        
+        if ( columns.size() > 0 && values.size() > 0 )
+        {
+            buffer.deleteCharAt( buffer.length() - 1 );
+        }
+        
+        buffer.append( " WHERE " + identifierColumnName + "=" + identifierColumnValue );
+        
+        columns.clear();
+        values.clear();
+        
+        return buffer.toString();
+    }
+    
+    public String getValueStatement( String table, String returnField, String compareField, String value )
+    {
+        String sql = "SELECT " + returnField + " FROM " + table + " WHERE " + compareField + " = '" + sqlEncode( value ) + "'";
+        
+        return sql;
+    }
+    
+    public String getValueStatement( String table, String returnField1, String returnField2, String compareField1, String value1, String compareField2, String value2 )
+    {
+        String sql = "SELECT " + returnField1 + ", " + returnField2 + " FROM " + table + " WHERE " + compareField1 + "='" + sqlEncode( value1 ) + "' AND " + compareField2 + "='" + value2 + "'";
+        
+        return sql;
+    }
+    
+    public String getValueStatement( String table, String returnField, Map<String, String> fieldMap, boolean union )
+    {
+        String operator = union ? " AND " : " OR ";
+        
+        StringBuffer sqlBuffer = new StringBuffer();
+        sqlBuffer.append( "SELECT " ).append( returnField ).append( " FROM " ).append( table ).append( " WHERE " );
+        
+        for ( Entry<String, String> entry : fieldMap.entrySet() )
+        {
+            sqlBuffer.append( entry.getKey() ).append( "='" ).append( sqlEncode( entry.getValue() ) ).append( "'" ).append( operator );
+        }
+
+        String sql = sqlBuffer.toString();
+        sql = sql.substring( 0, sql.length() - operator.length() );
+        
+        return sql;
+    }
+
+    public String getDoubleColumnType()
+    {
+        String type = "DOUBLE";
+        
+        return type;
+    }
+    
+    public String getPeriodIdentifierStatement( Period period )
+    {
+        String sql = 
+            "SELECT periodid FROM period WHERE periodtypeid=" + period.getPeriodType().getId() + " " + 
+            "AND startdate='" + getDateString( period.getStartDate() ) + "' " +
+            "AND enddate='" + getDateString( period.getEndDate() ) + "'";
+        
+        return sql;
+    }    
+
+    public String getCreateAggregatedDataValueTable()
+    {
+        String sql = "CREATE TABLE aggregateddatavalue ( " +
+            "dataelementid INTEGER, " +
+            "categoryoptioncomboid INTEGER, " +
+            "periodid INTEGER, " +
+            "organisationunitid INTEGER, " +
+            "periodtypeid INTEGER, " +
+            "level INTEGER, " +
+            "value DOUBLE );";
+        
+        return sql;
+    }
+    
+    public String getCreateAggregatedIndicatorTable()
+    {
+        String sql = "CREATE TABLE aggregatedindicatorvalue ( " +
+            "indicatorid INTEGER, " +
+            "periodid INTEGER, " +
+            "organisationunitid INTEGER, " +
+            "periodtypeid INTEGER, " +
+            "level INTEGER, " +
+            "annualized VARCHAR( 10 ), " +
+            "factor DOUBLE, " +
+            "value DOUBLE, " +
+            "numeratorvalue DOUBLE, " +
+            "denominatorvalue DOUBLE );";
+        
+        return sql;
+    }
+
+    public String getCreateDataSetCompletenessTable()
+    {
+        String sql = "CREATE TABLE aggregateddatasetcompleteness ( " +
+            "datasetid INTEGER, " +
+            "periodid INTEGER, " +
+            "periodname VARCHAR( 30 ), " +
+            "organisationunitid INTEGER, " +
+            "reporttableid INTEGER, " +
+            "sources INTEGER, " +
+            "registrations INTEGER, " +
+            "registrationsOnTime INTEGER, " +
+            "value DOUBLE, " +
+            "valueOnTime DOUBLE );";
+        
+        return sql;
+    }
+
+    public String getCreateDataValueIndex()
+    {
+        String sql =
+            "CREATE INDEX crosstab " +
+            "ON datavalue ( periodid, sourceid );";
+        
+        return sql;
+    }
+
+    public String getDeleteRelativePeriods()
+    {
+        String sql =
+            "DELETE FROM period " +
+            "USING period, periodtype " +
+            "WHERE period.periodtypeid = periodtype.periodtypeid " +
+            "AND periodtype.name = '" + RelativePeriodType.NAME + "';";
+        
+        return sql;
+    }
+
+    public String getDeleteZeroDataValues()
+    {
+        String sql = 
+            "DELETE FROM datavalue " +
+            "USING datavalue, dataelement " +
+            "WHERE datavalue.dataelementid = dataelement.dataelementid " +
+            "AND dataelement.aggregationtype = 'sum' " +
+            "AND datavalue.value IN ( '0', '0.', '.0', '0.0' )";
+        
+        return sql;
+    }
+    
+    public int getMaximumNumberOfColumns()
+    {
+        return 1200; //TODO verify
+    }
+}

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/pom.xml'
--- dhis-2/dhis-support/dhis-support-hibernate/pom.xml	2009-04-03 06:58:28 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/pom.xml	2009-04-03 13:27:40 +0000
@@ -63,11 +63,10 @@
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
     </dependency>
-    <!--
 	<dependency>
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
-    </dependency> -->
+    </dependency>
     
     <!-- Other -->
     

=== modified file 'docs/Technical Architecture DHIS 2.doc'
Binary files docs/Technical Architecture DHIS 2.doc	2009-03-29 20:22:42 +0000 and docs/Technical Architecture DHIS 2.doc	2009-04-03 13:27:40 +0000 differ


--
Trunk
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.