MIFOSX-254 Make JDBC Pool Configuration Setting Work Better

Fix time-of-check-time-of-use bug in
TomcatJdbcDataSourcePerTenantService.java
Close database connection in ReadReportingServiceImpl.java
This commit is contained in:
Robert Tuck
2013-05-06 23:50:28 +01:00
parent 5a2acd7897
commit aaeec4e9f3
2 changed files with 21 additions and 8 deletions
@@ -44,13 +44,16 @@ public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenant
MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
if (tenant != null) { if (tenant != null) {
// if tenant information available switch to appropriate datasource synchronized(this.tenantToDataSourceMap)
// for that tenant. {
if (this.tenantToDataSourceMap.containsKey(tenant.getId())) { // if tenant information available switch to appropriate datasource
tenantDataSource = this.tenantToDataSourceMap.get(tenant.getId()); // for that tenant.
} else { if (this.tenantToDataSourceMap.containsKey(tenant.getId())) {
tenantDataSource = createNewDataSourceFor(tenant); tenantDataSource = this.tenantToDataSourceMap.get(tenant.getId());
this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource); } else {
tenantDataSource = createNewDataSourceFor(tenant);
this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource);
}
} }
} }
@@ -12,6 +12,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.Connection;
import java.sql.Date; import java.sql.Date;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@@ -333,7 +334,16 @@ public class ReadReportingServiceImpl implements ReadReportingService {
// passed as parameters to allow multitenant penaho reporting // passed as parameters to allow multitenant penaho reporting
// and // and
// data scoping // 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(); String userhierarchy = currentUser.getOffice().getHierarchy();
logger.info("db name:" + tenantdb + " userhierarchy:" + userhierarchy); logger.info("db name:" + tenantdb + " userhierarchy:" + userhierarchy);
rptParamValues.put("tenantdb", tenantdb); rptParamValues.put("tenantdb", tenantdb);