dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11712
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3415: Code cleanup in datamart
------------------------------------------------------------
revno: 3415
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-04-15 17:02:55 +0200
message:
Code cleanup in datamart
modified:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/CalculatedDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/IndicatorDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.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-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -78,7 +77,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, List<String> keys )
+ final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -86,7 +85,7 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), keys );
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -82,7 +81,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
+ final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -99,7 +98,7 @@
for ( final Integer unitId : unitIds )
{
final Collection<CrossTabDataValue> crossTabValues =
- crossTabService.getCrossTabDataValues( operands, aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), unitId, keys );
+ crossTabService.getCrossTabDataValues( operands, aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), unitId, key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -82,7 +81,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
+ final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -90,7 +89,7 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), keys );
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java 2011-04-15 15:02:55 +0000
@@ -29,7 +29,6 @@
import java.util.Collection;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import org.hisp.dhis.dataelement.DataElementOperand;
@@ -47,7 +46,7 @@
final String TRUE = "true";
Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, List<String> keys );
+ final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, String key );
Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel );
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2011-04-15 15:02:55 +0000
@@ -36,7 +36,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -79,7 +78,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
+ final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -87,7 +86,7 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), keys );
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <data element id, [total value, total relevant days]>
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -82,7 +81,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
+ final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -90,7 +89,7 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), keys );
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/CalculatedDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/CalculatedDataElementDataMart.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/CalculatedDataElementDataMart.java 2011-04-15 15:02:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.dataelement.CalculatedDataElement;
import org.hisp.dhis.dataelement.DataElementOperand;
@@ -42,5 +41,5 @@
public interface CalculatedDataElementDataMart
{
int exportCalculatedDataElements( Collection<CalculatedDataElement> calculatedDataElements,
- Collection<Period> periods, Collection<OrganisationUnit> organisationUnits, Collection<DataElementOperand> operands, List<String> keys );
+ Collection<Period> periods, Collection<OrganisationUnit> organisationUnits, Collection<DataElementOperand> operands, String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2011-04-15 15:02:55 +0000
@@ -33,7 +33,6 @@
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.amplecode.quick.BatchHandler;
@@ -120,7 +119,7 @@
// -------------------------------------------------------------------------
public int exportCalculatedDataElements( final Collection<CalculatedDataElement> calculatedDataElements, final Collection<Period> periods,
- final Collection<OrganisationUnit> organisationUnits, final Collection<DataElementOperand> operands, List<String> keys )
+ final Collection<OrganisationUnit> organisationUnits, final Collection<DataElementOperand> operands, String key )
{
final DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
@@ -148,9 +147,9 @@
{
final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
- final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperands, period, unit, level, hierarchy, keys );
- final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperands, period, unit, level, hierarchy, keys );
- final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperands, period, unit, level, hierarchy, keys );
+ final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperands, period, unit, level, hierarchy, key );
+ final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperands, period, unit, level, hierarchy, key );
+ final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperands, period, unit, level, hierarchy, key );
final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>( sumIntValueMap );
valueMap.putAll( averageIntValueMap );
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java 2011-01-20 21:08:24 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java 2011-04-15 15:02:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.CrossTabDataValue;
@@ -58,7 +57,7 @@
* @param organisationUnitIds the collection of OrganisationUnit identifiers.
* @return a List of random keys for each generated crosstab table.
*/
- List<String> populateCrossTabTable( Collection<DataElementOperand> operands,
+ String populateCrossTabTable( Collection<DataElementOperand> operands,
Collection<Integer> periodIds, Collection<Integer> organisationUnitIds );
/**
@@ -75,7 +74,7 @@
* @return collection of CrossTabDataValues.
*/
Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands, Collection<Integer> periodIds,
- Collection<Integer> sourceIds, List<String> keys );
+ Collection<Integer> sourceIds, String key );
/**
* Gets all CrossTabDataValues for the given collection of period ids and the source id.
@@ -86,5 +85,5 @@
* @return collection of CrossTabDataValues.
*/
Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands, Collection<Integer> periodIds,
- int sourceId, List<String> keys );
+ int sourceId, String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java 2011-04-14 09:05:18 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java 2011-04-15 15:02:55 +0000
@@ -43,7 +43,6 @@
import org.hisp.dhis.datamart.crosstab.jdbc.CrossTabStore;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.jdbc.batchhandler.GenericBatchHandler;
-import org.hisp.dhis.system.util.PaginatedList;
/**
* @author Lars Helge Overland
@@ -55,13 +54,6 @@
private static final int MAX_LENGTH = 20;
- private int maxColumns = 1500;
-
- public void setMaxColumns( int maxColumns )
- {
- this.maxColumns = maxColumns;
- }
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -103,74 +95,61 @@
return dataValueService.getOperandsWithDataValues( operands );
}
- public List<String> populateCrossTabTable( final Collection<DataElementOperand> operands,
+ public String populateCrossTabTable( final Collection<DataElementOperand> operands,
final Collection<Integer> periodIds, final Collection<Integer> organisationUnitIds )
{
+ final String key = RandomStringUtils.randomAlphanumeric( 8 );
+
if ( validate( operands, periodIds, organisationUnitIds ) )
{
- final PaginatedList<DataElementOperand> operandList = new PaginatedList<DataElementOperand>( operands, maxColumns );
-
- final List<String> crossTabTableKeys = new ArrayList<String>();
-
- List<DataElementOperand> operandPage = new ArrayList<DataElementOperand>();
-
- while ( ( operandPage = operandList.nextPage() ) != null )
+ crossTabStore.dropCrossTabTable( key );
+ crossTabStore.createCrossTabTable( operands, key );
+
+ final BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class );
+ batchHandler.setTableName( CrossTabStore.TABLE_PREFIX + key );
+ batchHandler.init();
+
+ for ( final Integer periodId : periodIds )
{
- final String key = RandomStringUtils.randomAlphanumeric( 8 );
-
- crossTabTableKeys.add( key );
-
- crossTabStore.dropCrossTabTable( key );
- crossTabStore.createCrossTabTable( operandPage, key );
-
- final BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class );
- batchHandler.setTableName( CrossTabStore.TABLE_PREFIX + key );
- batchHandler.init();
-
- for ( final Integer periodId : periodIds )
+ for ( final Integer sourceId : organisationUnitIds )
{
- for ( final Integer sourceId : organisationUnitIds )
- {
- final Map<DataElementOperand, String> map = aggregatedDataValueService.getDataValueMap( periodId, sourceId );
-
- final List<String> valueList = new ArrayList<String>( operandPage.size() + 2 );
-
- valueList.add( String.valueOf( periodId ) );
- valueList.add( String.valueOf( sourceId ) );
-
- boolean hasValues = false;
-
- for ( DataElementOperand operand : operandPage )
- {
- String value = map.get( operand );
-
- if ( value != null && value.length() > MAX_LENGTH )
- {
- log.warn( "Value ignored, too long: '" + value + "'" );
- value = null;
- }
-
- if ( value != null )
- {
- hasValues = true;
- }
-
- valueList.add( value );
- }
-
- if ( hasValues )
- {
- batchHandler.addObject( valueList );
- }
+ final Map<DataElementOperand, String> map = aggregatedDataValueService.getDataValueMap( periodId, sourceId );
+
+ final List<String> valueList = new ArrayList<String>( operands.size() + 2 );
+
+ valueList.add( String.valueOf( periodId ) );
+ valueList.add( String.valueOf( sourceId ) );
+
+ boolean hasValues = false;
+
+ for ( DataElementOperand operand : operands )
+ {
+ String value = map.get( operand );
+
+ if ( value != null && value.length() > MAX_LENGTH )
+ {
+ log.warn( "Value ignored, too long: '" + value + "'" );
+ value = null;
+ }
+
+ if ( value != null )
+ {
+ hasValues = true;
+ }
+
+ valueList.add( value );
+ }
+
+ if ( hasValues )
+ {
+ batchHandler.addObject( valueList );
}
}
-
- batchHandler.flush();
-
- log.info( "Populated crosstab table for key: " + key );
}
- return crossTabTableKeys;
+ batchHandler.flush();
+
+ return key;
}
return null;
@@ -182,15 +161,15 @@
}
public Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands,
- Collection<Integer> periodIds, Collection<Integer> sourceIds, List<String> keys )
+ Collection<Integer> periodIds, Collection<Integer> sourceIds, String key )
{
- return crossTabStore.getCrossTabDataValues( operands, periodIds, sourceIds, keys );
+ return crossTabStore.getCrossTabDataValues( operands, periodIds, sourceIds, key );
}
public Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands,
- Collection<Integer> periodIds, int sourceId, List<String> keys )
+ Collection<Integer> periodIds, int sourceId, String key )
{
- return crossTabStore.getCrossTabDataValues( operands, periodIds, sourceId, keys );
+ return crossTabStore.getCrossTabDataValues( operands, periodIds, sourceId, key );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java 2011-04-14 09:05:18 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java 2011-04-15 15:02:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.CrossTabDataValue;
@@ -50,7 +49,7 @@
*
* @param operands the DataElementOperands.
*/
- void createCrossTabTable( List<DataElementOperand> operands, String key );
+ void createCrossTabTable( Collection<DataElementOperand> operands, String key );
/**
* Drops the crosstab table.
@@ -66,7 +65,7 @@
* @return collection of CrossTabDataValues.
*/
Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands, Collection<Integer> periodIds,
- Collection<Integer> sourceIds, List<String> keys );
+ Collection<Integer> sourceIds, String key );
/**
* Gets all CrossTabDataValues for the given collection of period ids and the source id.
@@ -77,5 +76,5 @@
* @return collection of CrossTabDataValues.
*/
Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands, Collection<Integer> periodIds,
- int sourceId, List<String> keys );
+ int sourceId, String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java 2011-04-14 09:05:18 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java 2011-04-15 15:02:55 +0000
@@ -28,13 +28,11 @@
*/
import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
-import static org.hisp.dhis.system.util.TextUtils.trimEnd;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import org.amplecode.quick.StatementHolder;
import org.amplecode.quick.StatementManager;
@@ -63,7 +61,7 @@
// CrossTabStore implementation
// -------------------------------------------------------------------------
- public void createCrossTabTable( final List<DataElementOperand> operands, String key )
+ public void createCrossTabTable( final Collection<DataElementOperand> operands, String key )
{
final StatementHolder holder = statementManager.getHolder();
@@ -118,13 +116,12 @@
// -------------------------------------------------------------------------
public Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands,
- Collection<Integer> periodIds, Collection<Integer> sourceIds, List<String> keys )
+ Collection<Integer> periodIds, Collection<Integer> sourceIds, String key )
{
final StatementHolder holder = statementManager.getHolder();
- String sql = getCrossTabSelectJoin( keys );
-
- sql += " WHERE c.periodid IN (" + getCommaDelimitedString( periodIds ) + ") AND c.sourceid IN (" + getCommaDelimitedString( sourceIds ) + ")";
+ final String sql = "SELECT * FROM " + TABLE_PREFIX + key + " AS c WHERE c.periodid IN (" +
+ getCommaDelimitedString( periodIds ) + ") AND c.sourceid IN (" + getCommaDelimitedString( sourceIds ) + ")";
try
{
@@ -143,13 +140,12 @@
}
public Collection<CrossTabDataValue> getCrossTabDataValues( Collection<DataElementOperand> operands,
- Collection<Integer> periodIds, int sourceId, List<String> keys )
+ Collection<Integer> periodIds, int sourceId, String key )
{
final StatementHolder holder = statementManager.getHolder();
- String sql = getCrossTabSelectJoin( keys );
-
- sql += " WHERE c.periodid IN (" + getCommaDelimitedString( periodIds ) + ") AND c.sourceid = " + sourceId;
+ final String sql = "SELECT * FROM " + TABLE_PREFIX + key + " AS c WHERE c.periodid IN (" +
+ getCommaDelimitedString( periodIds ) + ") AND c.sourceid = " + sourceId;
try
{
@@ -200,39 +196,4 @@
return values;
}
-
- private String getCrossTabSelectJoin( List<String> keys )
- {
- String sql = "SELECT";
-
- if ( keys.size() == 1 )
- {
- sql += " * FROM " + TABLE_PREFIX + keys.get( 0 ) + " AS c";
- }
- else
- {
- sql += " c.periodid, c.sourceid";
-
- for ( String key : keys )
- {
- sql += ", " + TABLE_PREFIX + key + ".*";
- }
-
- sql += " FROM ( SELECT DISTINCT periodid, sourceid FROM (";
-
- for ( String key : keys )
- {
- sql += " SELECT periodid, sourceid FROM " + TABLE_PREFIX + key + " UNION";
- }
-
- sql = trimEnd( sql, " UNION".length() ) + " ) AS x ) AS c";
-
- for ( String key : keys )
- {
- sql += " LEFT JOIN " + TABLE_PREFIX + key + " ON c.periodid = " + TABLE_PREFIX + key + ".periodid AND c.sourceid = " + TABLE_PREFIX + key + ".sourceid";
- }
- }
-
- return sql;
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java 2011-04-15 15:02:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.aggregation.dataelement.DataElementAggregator;
@@ -41,5 +40,5 @@
public interface DataElementDataMart
{
int exportDataValues( Collection<DataElementOperand> operands, Collection<Period> periods,
- Collection<OrganisationUnit> organisationUnits, DataElementAggregator dataElementAggregator, List<String> keys );
+ Collection<OrganisationUnit> organisationUnits, DataElementAggregator dataElementAggregator, String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2011-04-15 15:02:55 +0000
@@ -30,7 +30,6 @@
import static org.hisp.dhis.system.util.MathUtils.getRounded;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -84,7 +83,7 @@
// -------------------------------------------------------------------------
public int exportDataValues( final Collection<DataElementOperand> operands, final Collection<Period> periods,
- final Collection<OrganisationUnit> organisationUnits, final DataElementAggregator dataElementAggregator, List<String> keys )
+ final Collection<OrganisationUnit> organisationUnits, final DataElementAggregator dataElementAggregator, String key )
{
final BatchHandler<AggregatedDataValue> batchHandler = batchHandlerFactory.createBatchHandler( AggregatedDataValueBatchHandler.class ).init();
@@ -104,7 +103,7 @@
{
final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
- final Map<DataElementOperand, Double> valueMap = dataElementAggregator.getAggregatedValues( currentOperands, period, unit, level, hierarchy, keys );
+ final Map<DataElementOperand, Double> valueMap = dataElementAggregator.getAggregatedValues( currentOperands, period, unit, level, hierarchy, key );
for ( Entry<DataElementOperand, Double> entry : valueMap.entrySet() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2011-01-21 12:44:09 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2011-04-15 15:02:55 +0000
@@ -29,7 +29,6 @@
import java.util.Collection;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -259,14 +258,14 @@
Collection<Integer> childrenIds = organisationUnitService.getOrganisationUnitHierarchy().getChildren( organisationUnitIds );
Collection<Integer> intersectingPeriodIds = ConversionUtils.getIdentifiers( Period.class, periodService.getIntersectionPeriods( periods ) );
- List<String> keys = crossTabService.populateCrossTabTable( allOperands, intersectingPeriodIds, childrenIds );
+ String key = crossTabService.populateCrossTabTable( allOperands, intersectingPeriodIds, childrenIds );
- if ( CollectionUtils.isEmpty( allOperands ) || CollectionUtils.isEmpty( keys ) )
+ if ( CollectionUtils.isEmpty( allOperands ) )
{
return 0;
}
- log.info( "Number of crosstab tables: " + keys.size() + ", " + TimeUtils.getHMS() );
+ log.info( "Populated crosstab table: " + TimeUtils.getHMS() );
// ---------------------------------------------------------------------
// Drop potential indexes
@@ -299,23 +298,23 @@
if ( nonCalculatedOperands.size() > 0 )
{
- count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, sumIntAggregator, keys );
+ count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, sumIntAggregator, key );
log.info( "Exported values for data element operands with sum aggregation operator of type number: " + TimeUtils.getHMS() );
- count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageIntAggregator, keys );
+ count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageIntAggregator, key );
log.info( "Exported values for data element operands with average aggregation operator of type number: " + TimeUtils.getHMS() );
- count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageIntSingleValueAggregator, keys );
+ count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageIntSingleValueAggregator, key );
log.info( "Exported values for data element operands with average aggregation operator with single value of type number: " + TimeUtils.getHMS() );
- count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, sumBoolAggregator, keys );
+ count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, sumBoolAggregator, key );
log.info( "Exported values for data element operands with sum aggregation operator of type yes/no: " + TimeUtils.getHMS() );
- count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageBoolAggregator, keys );
+ count += dataElementDataMart.exportDataValues( nonCalculatedOperands, periods, organisationUnits, averageBoolAggregator, key );
log.info( "Exported values for data element operands with average aggregation operator of type yes/no: " + TimeUtils.getHMS() );
}
@@ -328,7 +327,7 @@
if ( isIndicators )
{
- count += indicatorDataMart.exportIndicatorValues( indicators, periods, organisationUnits, indicatorOperands, keys );
+ count += indicatorDataMart.exportIndicatorValues( indicators, periods, organisationUnits, indicatorOperands, key );
log.info( "Exported values for indicators (" + indicators.size() + "): " + TimeUtils.getHMS() );
}
@@ -341,7 +340,7 @@
if ( isCalculatedDataElements )
{
- count += calculatedDataElementDataMart.exportCalculatedDataElements( calculatedDataElements, periods, organisationUnits, calculatedOperands, keys );
+ count += calculatedDataElementDataMart.exportCalculatedDataElements( calculatedDataElements, periods, organisationUnits, calculatedOperands, key );
log.info( "Exported values for calculated data elements (" + calculatedDataElements.size() + "): " + TimeUtils.getHMS() );
}
@@ -350,12 +349,9 @@
// Drop crosstab tables
// ---------------------------------------------------------------------
- for ( String key : keys )
- {
- crossTabService.dropCrossTabTable( key );
- }
+ crossTabService.dropCrossTabTable( key );
- log.info( "Dropped crosstab tables: " + TimeUtils.getHMS() );
+ log.info( "Dropped crosstab table: " + TimeUtils.getHMS() );
// ---------------------------------------------------------------------
// Create potential indexes
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2011-01-13 15:38:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.amplecode.quick.BatchHandler;
@@ -123,7 +122,7 @@
// -------------------------------------------------------------------------
public int exportIndicatorValues( final Collection<Indicator> indicators, final Collection<Period> periods,
- final Collection<OrganisationUnit> organisationUnits, final Collection<DataElementOperand> operands, List<String> keys )
+ final Collection<OrganisationUnit> organisationUnits, final Collection<DataElementOperand> operands, String key )
{
final BatchHandler<AggregatedIndicatorValue> batchHandler = batchHandlerFactory.createBatchHandler( AggregatedIndicatorValueBatchHandler.class ).init();
@@ -152,9 +151,9 @@
{
final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
- final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperands, period, unit, level, hierarchy, keys );
- final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperands, period, unit, level, hierarchy, keys );
- final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperands, period, unit, level, hierarchy, keys );
+ final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperands, period, unit, level, hierarchy, key );
+ final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperands, period, unit, level, hierarchy, key );
+ final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperands, period, unit, level, hierarchy, key );
final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>( sumIntValueMap );
valueMap.putAll( averageIntValueMap );
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/IndicatorDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/IndicatorDataMart.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/IndicatorDataMart.java 2011-04-15 15:02:55 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.indicator.Indicator;
@@ -41,5 +40,5 @@
public interface IndicatorDataMart
{
int exportIndicatorValues( Collection<Indicator> indicators, Collection<Period> periods,
- Collection<OrganisationUnit> organisationUnits, Collection<DataElementOperand> operands, List<String> keys );
+ Collection<OrganisationUnit> organisationUnits, Collection<DataElementOperand> operands, String key );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java 2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java 2011-04-15 15:02:55 +0000
@@ -35,7 +35,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.dataelement.DataElement;
@@ -179,9 +178,9 @@
@Test
public void testPopulateCrossTabValue()
{
- List<String> keys = crossTabService.populateCrossTabTable( operands, periodIds, organisationUnitIds );
+ String key = crossTabService.populateCrossTabTable( operands, periodIds, organisationUnitIds );
- Collection<CrossTabDataValue> values = crossTabService.getCrossTabDataValues( operands, periodIds, organisationUnitIds, keys );
+ Collection<CrossTabDataValue> values = crossTabService.getCrossTabDataValues( operands, periodIds, organisationUnitIds, key );
assertNotNull( values );