← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7713: Replaced statement manager with jdbc template in aggregated data value store

 

------------------------------------------------------------
revno: 7713
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-07-26 08:41:43 +0200
message:
  Replaced statement manager with jdbc template in aggregated data value store
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
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-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2012-07-24 04:04:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2012-07-26 06:41:43 +0000
@@ -874,9 +874,10 @@
         return last3Months;
     }
 
-    public void setLast3Months( boolean last3Months )
+    public RelativePeriods setLast3Months( boolean last3Months )
     {
         this.last3Months = last3Months;
+        return this;
     }
 
     @JsonProperty

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java	2012-07-25 16:22:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java	2012-07-26 06:41:43 +0000
@@ -74,19 +74,19 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private StatementManager statementManager;
-
-    public void setStatementManager( StatementManager statementManager )
-    {
-        this.statementManager = statementManager;
-    }
-
     private JdbcTemplate jdbcTemplate;
     
     public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
         this.jdbcTemplate = jdbcTemplate;
     }
+    
+    private StatementManager statementManager; //TODO remove
+
+    public void setStatementManager( StatementManager statementManager )
+    {
+        this.statementManager = statementManager;
+    }
 
     // -------------------------------------------------------------------------
     // AggregatedDataValue
@@ -101,7 +101,7 @@
             "AND periodid = " + period + " " +
             "AND organisationunitid = " + organisationUnit;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Double getAggregatedDataValue( int dataElement, int categoryOptionCombo, int period, int organisationUnit )
@@ -114,7 +114,7 @@
             "AND periodid = " + period + " " +
             "AND organisationunitid = " + organisationUnit;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Double getAggregatedDataValue( int dataElement, int categoryOptionCombo, Collection<Integer> periodIds, int organisationUnit )
@@ -127,7 +127,7 @@
             "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
             "AND organisationunitid = " + organisationUnit;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
     
     public Double getAggregatedDataValue( DataElement dataElement, DataElementCategoryOption categoryOption, Period period, OrganisationUnit organisationUnit )
@@ -142,153 +142,68 @@
             "AND periodid = " + period.getId() + " " +
             "AND organisationunitid = " + organisationUnit.getId();
 
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT * " +
-                "FROM aggregateddatavalue " +
-                "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT * " +
+            "FROM aggregateddatavalue " +
+            "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );
     }
     
     public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
-                "FROM aggregateddatavalue " +
-                "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
-                "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
+            "FROM aggregateddatavalue " +
+            "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
+            "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
+        
+        return jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );
     }
 
     public Collection<AggregatedDataValue> getAggregatedDataValues( int dataElementId, 
         Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT * " +
-                "FROM aggregateddatavalue " +
-                "WHERE dataelementid = " + dataElementId + " " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT * " +
+            "FROM aggregateddatavalue " +
+            "WHERE dataelementid = " + dataElementId + " " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );
     }
 
     public Collection<AggregatedDataValue> getAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT * " +
-                "FROM aggregateddatavalue " +
-                "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT * " +
+            "FROM aggregateddatavalue " +
+            "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );        
     }
 
     public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
-                "FROM aggregateddatavalue " +
-                "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
-                "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, periodtypeid, level, SUM(value) as value " +
+            "FROM aggregateddatavalue " +
+            "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " ) " +
+            "GROUP BY dataelementid, periodid, organisationunitid, periodtypeid, level";
+        
+        return jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );
     }
 
     public StoreIterator<AggregatedDataValue> getAggregatedDataValuesAtLevel( OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods )
@@ -341,7 +256,7 @@
             " AND ous.idlevel" + rootOrgunit.getLevel() + "=" + rootOrgunit.getId() +
             " AND adv.periodid IN (" + periodids + ") ";
 
-        return statementManager.getHolder().queryForInteger( sql );
+        return jdbcTemplate.queryForInt( sql );
     }
 
     public void deleteAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
@@ -352,14 +267,14 @@
             "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
             "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     public void deleteAggregatedDataValues()
     {
         final String sql = "DELETE FROM aggregateddatavalue";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
     
     // -------------------------------------------------------------------------
@@ -377,7 +292,7 @@
             "AND a.organisationunitid IN (" + getCommaDelimitedString( organisationUnitIds ) + ") " +
             "GROUP BY a.periodid, o.organisationunitid, o.name";
         
-        return jdbcTemplate.query( sql, new AggregatedDataMapValueRowMapper() );        
+        return jdbcTemplate.query( sql, new AggregatedDataMapValueRowMapper() );
     }
 
     public Collection<AggregatedMapValue> getAggregatedDataMapValues( Collection<Integer> dataElementIds, int periodId, int organisationUnitId )
@@ -418,65 +333,31 @@
             "AND periodid = " + period + " " +
             "AND organisationunitid = " + organisationUnit;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Collection<AggregatedIndicatorValue> getAggregatedIndicatorValues( Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedIndicatorValue> mapper = new ObjectMapper<AggregatedIndicatorValue>();
-        
-        try
-        {
-            final String sql =
-                "SELECT * " +
-                "FROM aggregatedindicatorvalue " +
-                "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedIndicatorValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated indicator value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql =
+            "SELECT * " +
+            "FROM aggregatedindicatorvalue " +
+            "WHERE periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedIndicatorValueRowMapper() );
     }
 
     public Collection<AggregatedIndicatorValue> getAggregatedIndicatorValues( Collection<Integer> indicatorIds, 
         Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedIndicatorValue> mapper = new ObjectMapper<AggregatedIndicatorValue>();
-        
-        try
-        {
-            final String sql =
-                "SELECT * " +
-                "FROM aggregatedindicatorvalue " +
-                "WHERE indicatorid IN ( " + getCommaDelimitedString( indicatorIds ) + " ) " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedIndicatorValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated indicator value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql =
+            "SELECT * " +
+            "FROM aggregatedindicatorvalue " +
+            "WHERE indicatorid IN ( " + getCommaDelimitedString( indicatorIds ) + " ) " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedIndicatorValueRowMapper() );
     }
 
     public void deleteAggregatedIndicatorValues( Collection<Integer> indicatorIds, Collection<Integer> periodIds,
@@ -488,14 +369,14 @@
             "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
             "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     public void deleteAggregatedIndicatorValues()
     {
         final String sql = "DELETE FROM aggregatedindicatorvalue";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     @Override
@@ -524,6 +405,7 @@
             final ResultSet resultSet = statement.executeQuery( sql );
 
             RowMapper<AggregatedIndicatorValue> rm = new AggregatedIndicatorValueRowMapper();
+            
             return new JdbcStoreIterator<AggregatedIndicatorValue>( resultSet, holder, rm );
         }
         catch ( SQLException ex )
@@ -539,38 +421,19 @@
     @Override
     public int countIndicatorValuesAtLevel( OrganisationUnit rootOrgunit, OrganisationUnitLevel level, Collection<Period> periods )
     {
-        final StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            int rootlevel = rootOrgunit.getLevel();
-
-            String periodids = getCommaDelimitedString( getIdentifiers(Period.class, periods));
-
-            final String sql =
-                "SELECT count(*) as rowcount " +
-                "FROM aggregatedindicatorvalue AS aiv " +
-                "INNER JOIN _orgunitstructure AS ous on aiv.organisationunitid=ous.organisationunitid " +
-                "WHERE aiv.level = " + level.getLevel() +
-                " AND ous.idlevel" + rootlevel + "=" + rootOrgunit.getId() +
-                " AND aiv.periodid IN (" + periodids + ") ";
-
-            Statement statement = holder.getStatement();
-
-            final ResultSet resultSet = statement.executeQuery( sql );
-
-            resultSet.next();
-
-            return resultSet.getInt( "rowcount");
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated indicator values", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        int rootlevel = rootOrgunit.getLevel();
+
+        String periodids = getCommaDelimitedString( getIdentifiers(Period.class, periods));
+        
+        final String sql =
+            "SELECT count(*) as rowcount " +
+            "FROM aggregatedindicatorvalue AS aiv " +
+            "INNER JOIN _orgunitstructure AS ous on aiv.organisationunitid=ous.organisationunitid " +
+            "WHERE aiv.level = " + level.getLevel() +
+            " AND ous.idlevel" + rootlevel + "=" + rootOrgunit.getId() +
+            " AND aiv.periodid IN (" + periodids + ") ";
+        
+        return jdbcTemplate.queryForInt( sql );
     }
 
     // -------------------------------------------------------------------------
@@ -613,33 +476,16 @@
 
     public Collection<DeflatedDataValue> getDeflatedDataValues( int dataElementId, int periodId, Collection<Integer> sourceIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-            
-        final ObjectMapper<DeflatedDataValue> mapper = new ObjectMapper<DeflatedDataValue>();
+        final String sql =
+            "SELECT * FROM datavalue " +
+            "WHERE dataelementid = " + dataElementId + " " +
+            "AND periodid = " + periodId + " " +
+            "AND sourceid IN ( " + getCommaDelimitedString( sourceIds ) + " )";
         
-        try
-        {
-            final String sql =
-                "SELECT * FROM datavalue " +
-                "WHERE dataelementid = " + dataElementId + " " +
-                "AND periodid = " + periodId + " " +
-                "AND sourceid IN ( " + getCommaDelimitedString( sourceIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new DeflatedDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get deflated data values", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        return jdbcTemplate.query( sql, new DeflatedDataValueRowMapper() );
     }
     
-    public DataValue getDataValue( int dataElementId, int categoryOptionComboId, int periodId, int sourceId )
+    public DataValue getDataValue( int dataElementId, int categoryOptionComboId, int periodId, int sourceId ) //TODO remove
     {
         final StatementHolder holder = statementManager.getHolder();
         

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java	2012-07-25 16:22:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java	2012-07-26 06:41:43 +0000
@@ -29,18 +29,14 @@
 
 import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.util.Collection;
 
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
-import org.amplecode.quick.mapper.ObjectMapper;
 import org.hisp.dhis.aggregation.AggregatedDataValue;
 import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
 import org.hisp.dhis.aggregation.AggregatedOrgUnitDataValueStore;
 import org.hisp.dhis.system.objectmapper.AggregatedOrgUnitDataValueRowMapper;
 import org.hisp.dhis.system.objectmapper.AggregatedOrgUnitIndicatorValueRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
 
 public class JdbcAggregatedOrgUnitDataValueStore
     implements AggregatedOrgUnitDataValueStore
@@ -49,13 +45,13 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private StatementManager statementManager;
-
-    public void setStatementManager( StatementManager statementManager )
+    private JdbcTemplate jdbcTemplate;
+    
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
-        this.statementManager = statementManager;
+        this.jdbcTemplate = jdbcTemplate;
     }
-
+    
     // -------------------------------------------------------------------------
     // AggregatedOrgUnitDataValueStore implementation
     // -------------------------------------------------------------------------
@@ -71,39 +67,22 @@
             "AND organisationunitid = " + organisationUnit + " " +
             "AND organisationunitgroupid = " + organisationUnitGroup;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Collection<AggregatedDataValue> getAggregatedDataValueTotals( Collection<Integer> dataElementIds, 
         Collection<Integer> periodIds, int organisationUnitId, Collection<Integer> organisationUnitGroupIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedDataValue> mapper = new ObjectMapper<AggregatedDataValue>();
-        
-        try
-        {
-            final String sql = 
-                "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, organisationunitgroupid, periodtypeid, level, SUM(value) as value " +
-                "FROM aggregatedorgunitdatavalue " +
-                "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid = " + organisationUnitId + " " +
-                "AND organisationunitgroupid IN ( " + getCommaDelimitedString( organisationUnitGroupIds ) + " ) " +
-                "GROUP BY dataelementid, periodid, organisationunitid, organisationunitgroupid, periodtypeid, level";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedOrgUnitDataValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated org unit data value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql = 
+            "SELECT dataelementid, 0 as categoryoptioncomboid, periodid, organisationunitid, organisationunitgroupid, periodtypeid, level, SUM(value) as value " +
+            "FROM aggregatedorgunitdatavalue " +
+            "WHERE dataelementid IN ( " + getCommaDelimitedString( dataElementIds ) + " ) " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid = " + organisationUnitId + " " +
+            "AND organisationunitgroupid IN ( " + getCommaDelimitedString( organisationUnitGroupIds ) + " ) " +
+            "GROUP BY dataelementid, periodid, organisationunitid, organisationunitgroupid, periodtypeid, level";
+        
+        return jdbcTemplate.query( sql, new AggregatedOrgUnitDataValueRowMapper() );
     }
 
     public void deleteAggregatedDataValues( Collection<Integer> dataElementIds, Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
@@ -114,14 +93,14 @@
             "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
             "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     public void deleteAggregatedDataValues()
     {
         final String sql = "DELETE FROM aggregatedorgunitdatavalue";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     // -------------------------------------------------------------------------
@@ -138,38 +117,21 @@
             "AND organisationunitid = " + organisationUnit + " " +
             "AND organisationunitgroupid = " + organisationUnitGroup;
         
-        return statementManager.getHolder().queryForDouble( sql );
+        return jdbcTemplate.queryForObject( sql, Double.class );
     }
 
     public Collection<AggregatedIndicatorValue> getAggregatedIndicatorValues( Collection<Integer> indicatorIds, 
         Collection<Integer> periodIds, int organisationUnitId, Collection<Integer> organisationUnitGroupIds )
     {
-        final StatementHolder holder = statementManager.getHolder();
-        
-        final ObjectMapper<AggregatedIndicatorValue> mapper = new ObjectMapper<AggregatedIndicatorValue>();
-        
-        try
-        {
-            final String sql =
-                "SELECT * " +
-                "FROM aggregatedorgunitindicatorvalue " +
-                "WHERE indicatorid IN ( " + getCommaDelimitedString( indicatorIds ) + " ) " +
-                "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
-                "AND organisationunitid = " + organisationUnitId + " " +
-                "AND organisationunitgroupid IN ( " + getCommaDelimitedString( organisationUnitGroupIds ) + " )";
-            
-            final ResultSet resultSet = holder.getStatement().executeQuery( sql );
-            
-            return mapper.getCollection( resultSet, new AggregatedOrgUnitIndicatorValueRowMapper() );
-        }
-        catch ( SQLException ex )
-        {
-            throw new RuntimeException( "Failed to get aggregated indicator value", ex );
-        }
-        finally
-        {
-            holder.close();
-        }
+        final String sql =
+            "SELECT * " +
+            "FROM aggregatedorgunitindicatorvalue " +
+            "WHERE indicatorid IN ( " + getCommaDelimitedString( indicatorIds ) + " ) " +
+            "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
+            "AND organisationunitid = " + organisationUnitId + " " +
+            "AND organisationunitgroupid IN ( " + getCommaDelimitedString( organisationUnitGroupIds ) + " )";
+        
+        return jdbcTemplate.query( sql, new AggregatedOrgUnitIndicatorValueRowMapper() );
     }
 
     public void deleteAggregatedIndicatorValues( Collection<Integer> indicatorIds, Collection<Integer> periodIds,
@@ -181,13 +143,13 @@
             "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
             "AND organisationunitid IN ( " + getCommaDelimitedString( organisationUnitIds ) + " )";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 
     public void deleteAggregatedIndicatorValues()
     {
         final String sql = "DELETE FROM aggregatedorgunitindicatorvalue ";
         
-        statementManager.getHolder().executeUpdate( sql );
+        jdbcTemplate.execute( sql );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-07-24 04:04:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-07-26 06:41:43 +0000
@@ -401,7 +401,7 @@
         executeSql( "update reporttable set lastsixmonth = false where lastsixmonth is null" );
         executeSql( "update reporttable set last4quarters = false where last4quarters is null" );
         executeSql( "update reporttable set last12months = false where last12months is null" );
-		executeSql( "update reporttable set last3months = false where last3months is null" );
+	executeSql( "update reporttable set last3months = false where last3months is null" );
         executeSql( "update reporttable set last6bimonths = false where last6bimonths is null" );
         executeSql( "update reporttable set last4quarters = false where last4quarters is null" );
         executeSql( "update reporttable set last2sixmonths = false where last2sixmonths is null" );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-07-25 14:44:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-07-26 06:41:43 +0000
@@ -226,7 +226,7 @@
   </bean>
 
   <bean id="org.hisp.dhis.aggregation.AggregatedOrgUnitDataValueStore" class="org.hisp.dhis.aggregation.jdbc.JdbcAggregatedOrgUnitDataValueStore">
-    <property name="statementManager" ref="statementManager" />
+    <property name="jdbcTemplate" ref="jdbcTemplate" />
   </bean>
 
   <bean id="org.hisp.dhis.user.UserAuthorityGroupStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">