diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java index d7290548a..3bcc54014 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java @@ -44,13 +44,16 @@ public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenant MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); if (tenant != null) { - // if tenant information available switch to appropriate datasource - // for that tenant. - if (this.tenantToDataSourceMap.containsKey(tenant.getId())) { - tenantDataSource = this.tenantToDataSourceMap.get(tenant.getId()); - } else { - tenantDataSource = createNewDataSourceFor(tenant); - this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource); + synchronized(this.tenantToDataSourceMap) + { + // if tenant information available switch to appropriate datasource + // for that tenant. + if (this.tenantToDataSourceMap.containsKey(tenant.getId())) { + tenantDataSource = this.tenantToDataSourceMap.get(tenant.getId()); + } else { + tenantDataSource = createNewDataSourceFor(tenant); + this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource); + } } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java index 7418c0200..7d4ca2b08 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java @@ -12,6 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.sql.Connection; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; @@ -333,7 +334,16 @@ public class ReadReportingServiceImpl implements ReadReportingService { // passed as parameters to allow multitenant penaho reporting // and // data scoping - String tenantdb = dataSource.getConnection().getCatalog(); + Connection connection = dataSource.getConnection(); + String tenantdb; + try + { + tenantdb = connection.getCatalog(); + } + finally + { + connection.close(); + } String userhierarchy = currentUser.getOffice().getHierarchy(); logger.info("db name:" + tenantdb + " userhierarchy:" + userhierarchy); rptParamValues.put("tenantdb", tenantdb);