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();
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);
}
}
}
@@ -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);