dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14440
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4906: Make sure we clean up database connection when disaster strikes on mydatamart export
------------------------------------------------------------
revno: 4906
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2011-10-12 10:59:23 +0100
message:
Make sure we clean up database connection when disaster strikes on mydatamart export
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.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-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-10-12 09:47:13 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-10-12 09:59:23 +0000
@@ -54,6 +54,7 @@
* Exports pivot view synchronously (using calling thread)
*
* TODO: use exportparams and abstract service
+ * factor out commonality between processIndicatorValues and processDataValues
*
* @author bobj
*/
@@ -187,32 +188,40 @@
{
StoreIterator<AggregatedDataValue> Iterator = aggregatedDataValueService.getAggregateDataValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
- AggregatedDataValue adv = Iterator.next();
-
- writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" );
-
- int values = 0;
-
- while ( adv != null )
+ try
{
- int periodId = adv.getPeriodId();
- String period = periodService.getPeriod( periodId ).getIsoDate();
-
- writer.write( "'" + period + "'," );
- writer.write( adv.getOrganisationUnitId() + "," );
- writer.write( adv.getDataElementId() + "," );
- writer.write( adv.getCategoryOptionComboId() + "," );
- writer.write( adv.getValue() + "\n" );
-
- // defend against expanding the writer buffer uncontrollably
- values = ++values % CHUNK;
-
- if (values == 0)
+ AggregatedDataValue adv = Iterator.next();
+
+ writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" );
+
+ int values = 0;
+
+ while ( adv != null )
{
- writer.flush();
+ int periodId = adv.getPeriodId();
+ String period = periodService.getPeriod( periodId ).getIsoDate();
+
+ writer.write( "'" + period + "'," );
+ writer.write( adv.getOrganisationUnitId() + "," );
+ writer.write( adv.getDataElementId() + "," );
+ writer.write( adv.getCategoryOptionComboId() + "," );
+ writer.write( adv.getValue() + "\n" );
+
+ // defend against expanding the writer buffer uncontrollably
+ values = ++values % CHUNK;
+
+ if ( values == 0 )
+ {
+ writer.flush();
+ }
+
+ adv = Iterator.next();
}
-
- adv = Iterator.next();
+ } catch ( IOException ex )
+ {
+ // whatever happens release the store iterator
+ Iterator.close();
+ throw ( ex );
}
writer.flush();
@@ -223,35 +232,44 @@
{
StoreIterator<AggregatedIndicatorValue> Iterator = aggregatedDataValueService.getAggregateIndicatorValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
- AggregatedIndicatorValue aiv = Iterator.next();
-
- writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" );
-
- int values = 0;
-
- while ( aiv != null )
+ try
{
- int periodId = aiv.getPeriodId();
- String period = periodService.getPeriod( periodId ).getIsoDate();
-
- writer.write( "'" + period + "'," );
- writer.write( aiv.getOrganisationUnitId() + "," );
- writer.write( aiv.getIndicatorId() + "," );
- writer.write( MathUtils.roundToString( aiv.getFactor(), PRECISION ) + "," );
- writer.write( MathUtils.roundToString( aiv.getNumeratorValue(), PRECISION ) + "," );
- writer.write( MathUtils.roundToString( aiv.getDenominatorValue(), PRECISION ) + "\n" );
-
- // defend against expanding the writer buffer uncontrollably
- values = ++values % CHUNK;
-
- if (values == 0)
+ AggregatedIndicatorValue aiv = Iterator.next();
+
+ writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" );
+
+ int values = 0;
+
+ while ( aiv != null )
{
- writer.flush();
+ int periodId = aiv.getPeriodId();
+ String period = periodService.getPeriod( periodId ).getIsoDate();
+
+ writer.write( "'" + period + "'," );
+ writer.write( aiv.getOrganisationUnitId() + "," );
+ writer.write( aiv.getIndicatorId() + "," );
+ writer.write( MathUtils.roundToString( aiv.getFactor(), PRECISION ) + "," );
+ writer.write( MathUtils.roundToString( aiv.getNumeratorValue(), PRECISION ) + "," );
+ writer.write( MathUtils.roundToString( aiv.getDenominatorValue(), PRECISION ) + "\n" );
+
+ // defend against expanding the writer buffer uncontrollably
+ values = ++values % CHUNK;
+
+ if ( values == 0 )
+ {
+ writer.flush();
+ }
+
+ aiv = Iterator.next();
}
-
- aiv = Iterator.next();
+ } catch ( IOException ex )
+ {
+ // whatever happens release the store iterator
+ Iterator.close();
+ throw (ex);
}
+
writer.flush();
}