dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20545
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9414: Checking for empty collections in data set report service
------------------------------------------------------------
revno: 9414
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-12-29 17:37:15 +0100
message:
Checking for empty collections in data set report service
modified:
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.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-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java 2012-07-19 19:20:26 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/JdbcDataSetReportStore.java 2012-12-29 16:37:15 +0000
@@ -75,28 +75,31 @@
FilterUtils.filter( dataElements, new AggregatableDataElementFilter() );
- final String sql = rawData ?
- "select dataelementid, categoryoptioncomboid, value " +
- "from datavalue " +
- "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
- "and periodid = " + period.getId() + " " +
- "and sourceid = " + unit.getId()
- :
- "select dataelementid, categoryoptioncomboid, value " +
- "from aggregateddatavalue " +
- "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
- "and periodid = " + period.getId() + " " +
- "and organisationunitid = " + unit.getId();
-
- SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
-
- while ( rowSet.next() )
+ if ( !dataElements.isEmpty() )
{
- int dataElementId = rowSet.getInt( "dataelementid" );
- int categoryOptionComboId = rowSet.getInt( "categoryoptioncomboid" );
- Double value = rowSet.getDouble( "value" );
-
- map.put( dataElementId + SEPARATOR + categoryOptionComboId, value );
+ final String sql = rawData ?
+ "select dataelementid, categoryoptioncomboid, value " +
+ "from datavalue " +
+ "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+ "and periodid = " + period.getId() + " " +
+ "and sourceid = " + unit.getId()
+ :
+ "select dataelementid, categoryoptioncomboid, value " +
+ "from aggregateddatavalue " +
+ "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+ "and periodid = " + period.getId() + " " +
+ "and organisationunitid = " + unit.getId();
+
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
+
+ while ( rowSet.next() )
+ {
+ int dataElementId = rowSet.getInt( "dataelementid" );
+ int categoryOptionComboId = rowSet.getInt( "categoryoptioncomboid" );
+ Double value = rowSet.getDouble( "value" );
+
+ map.put( dataElementId + SEPARATOR + categoryOptionComboId, value );
+ }
}
return map;
@@ -111,25 +114,28 @@
DataElementCategoryCombo categoryCombo = section.getCategoryCombo();
Set<DataElement> dataElements = new HashSet<DataElement>( section.getDataElements() );
- for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() )
+ if ( !dataElements.isEmpty() )
{
- final String sql =
- "select dataelementid, sum(value) as total " +
- "from aggregateddatavalue " +
- "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
- "and categoryoptioncomboid in (" + getCommaDelimitedString( getIdentifiers( DataElementCategoryOptionCombo.class, categoryOption.getCategoryOptionCombos() ) ) + ") " +
- "and periodid = " + period.getId() + " " +
- "and organisationunitid = " + unit.getId() + " " +
- "group by dataelementid";
-
- SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
-
- while ( rowSet.next() )
+ for ( DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions() )
{
- int dataElementId = rowSet.getInt( "dataelementid" );
- Double value = rowSet.getDouble( "total" );
-
- map.put( dataElementId + SEPARATOR + categoryOption.getId(), value );
+ final String sql =
+ "select dataelementid, sum(value) as total " +
+ "from aggregateddatavalue " +
+ "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+ "and categoryoptioncomboid in (" + getCommaDelimitedString( getIdentifiers( DataElementCategoryOptionCombo.class, categoryOption.getCategoryOptionCombos() ) ) + ") " +
+ "and periodid = " + period.getId() + " " +
+ "and organisationunitid = " + unit.getId() + " " +
+ "group by dataelementid";
+
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
+
+ while ( rowSet.next() )
+ {
+ int dataElementId = rowSet.getInt( "dataelementid" );
+ Double value = rowSet.getDouble( "total" );
+
+ map.put( dataElementId + SEPARATOR + categoryOption.getId(), value );
+ }
}
}
}
@@ -145,22 +151,25 @@
FilterUtils.filter( dataElements, new AggregatableDataElementFilter() );
- final String sql =
- "select dataelementid, sum(value) as total " +
- "from aggregateddatavalue " +
- "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
- "and periodid = " + period.getId() + " " +
- "and organisationunitid = " + unit.getId() + " " +
- "group by dataelementid";
-
- SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
-
- while ( rowSet.next() )
+ if ( !dataElements.isEmpty() )
{
- int dataElementId = rowSet.getInt( "dataelementid" );
- Double value = rowSet.getDouble( "total" );
+ final String sql =
+ "select dataelementid, sum(value) as total " +
+ "from aggregateddatavalue " +
+ "where dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+ "and periodid = " + period.getId() + " " +
+ "and organisationunitid = " + unit.getId() + " " +
+ "group by dataelementid";
+
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
- map.put( String.valueOf( dataElementId ), value );
+ while ( rowSet.next() )
+ {
+ int dataElementId = rowSet.getInt( "dataelementid" );
+ Double value = rowSet.getDouble( "total" );
+
+ map.put( String.valueOf( dataElementId ), value );
+ }
}
return map;
@@ -172,22 +181,25 @@
Set<Indicator> indicators = new HashSet<Indicator>( dataSet.getIndicators() );
- final String sql =
- "select indicatorid, sum(value) as total " +
- "from aggregatedindicatorvalue " +
- "where indicatorid in (" + getCommaDelimitedString( getIdentifiers( Indicator.class, indicators ) ) + ") " +
- "and periodid = " + period.getId() + " " +
- "and organisationunitid = " + unit.getId() + " " +
- "group by indicatorid";
-
- SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
-
- while ( rowSet.next() )
+ if ( !indicators.isEmpty() )
{
- int indicatorid = rowSet.getInt( "indicatorid" );
- Double value = rowSet.getDouble( "total" );
+ final String sql =
+ "select indicatorid, sum(value) as total " +
+ "from aggregatedindicatorvalue " +
+ "where indicatorid in (" + getCommaDelimitedString( getIdentifiers( Indicator.class, indicators ) ) + ") " +
+ "and periodid = " + period.getId() + " " +
+ "and organisationunitid = " + unit.getId() + " " +
+ "group by indicatorid";
+
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
- map.put( String.valueOf( indicatorid ), value );
+ while ( rowSet.next() )
+ {
+ int indicatorid = rowSet.getInt( "indicatorid" );
+ Double value = rowSet.getDouble( "total" );
+
+ map.put( String.valueOf( indicatorid ), value );
+ }
}
return map;