← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10569: Using spring DataSourceUtils in report service to retrieve connections from the pool instead of d...

 

------------------------------------------------------------
revno: 10569
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-15 21:04:24 +0200
message:
  Using spring DataSourceUtils in report service to retrieve connections from the pool instead of directly through statement manager
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-services/dhis-service-reporting/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-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-02-12 06:55:14 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-04-15 19:04:24 +0000
@@ -38,6 +38,8 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.sql.DataSource;
+
 import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
@@ -61,6 +63,7 @@
 import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.JRExportUtils;
 import org.hisp.dhis.system.util.StreamUtils;
+import org.springframework.jdbc.datasource.DataSourceUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -97,13 +100,6 @@
     {
         this.constantService = constantService;
     }
-
-    private StatementManager statementManager;
-
-    public void setStatementManager( StatementManager statementManager )
-    {
-        this.statementManager = statementManager;
-    }
     
     private OrganisationUnitService organisationUnitService;
     
@@ -126,6 +122,13 @@
         this.periodService = periodService;
     }
 
+    private DataSource dataSource;
+
+    public void setDataSource( DataSource dataSource )
+    {
+        this.dataSource = dataSource;
+    }
+
     // -------------------------------------------------------------------------
     // ReportService implementation
     // -------------------------------------------------------------------------
@@ -180,8 +183,6 @@
             }
             else // Use JDBC data source
             {
-                Connection connection = statementManager.getHolder().getConnection();
-
                 if ( report.hasRelativePeriods() )
                 {
                     Collection<Period> periods = periodService.reloadPeriods( report.getRelatives().getRelativePeriods( reportDate, null, false ) );
@@ -193,14 +194,16 @@
                 {
                     params.put( PARAM_ORG_UNITS, String.valueOf( orgUnit.getId() ) );
                 }
-                
+
+                Connection connection = DataSourceUtils.getConnection( dataSource );
+
                 try
                 {
                     print = JasperFillManager.fillReport( jasperReport, params, connection );
-                } 
+                }
                 finally
-                {
-                    connection.close();
+                {                    
+                    DataSourceUtils.releaseConnection( connection, dataSource );
                 }
             }
 

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-03-04 14:44:15 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-04-15 19:04:24 +0000
@@ -36,10 +36,10 @@
     <property name="reportStore" ref="org.hisp.dhis.report.ReportStore" />
     <property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" />
     <property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
-    <property name="statementManager" ref="statementManager" />
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
     <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
     <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+    <property name="dataSource" ref="dataSource" />
   </bean>
 
   <!-- Chart -->