FINERACT-2081: Avoid creating unnecessary connection pools
This commit is contained in:
committed by
Arnold Gálovics
parent
bb8480a03d
commit
263866c03a
+2
@@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationException;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.JdbcTemplateFactory;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.infrastructure.core.service.tenant.TenantDetailsService;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -50,6 +51,7 @@ public class GlobalConfigurationValidationService implements InitializingBean {
|
||||
|
||||
if (isNotEmpty(tenants)) {
|
||||
for (FineractPlatformTenant tenant : tenants) {
|
||||
ThreadLocalContextUtil.setTenant(tenant);
|
||||
validateGlobalConfigurationForIndividualTenant(tenant);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-7
@@ -18,10 +18,9 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.service;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.migration.TenantDataSourceFactory;
|
||||
import org.apache.fineract.infrastructure.core.service.database.RoutingDataSource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -30,15 +29,13 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class JdbcTemplateFactory {
|
||||
|
||||
private final TenantDataSourceFactory tenantDataSourceFactory;
|
||||
private final RoutingDataSource routingDataSource;
|
||||
|
||||
public JdbcTemplate create(FineractPlatformTenant tenant) {
|
||||
DataSource tenantDataSource = tenantDataSourceFactory.create(tenant);
|
||||
return new JdbcTemplate(tenantDataSource);
|
||||
return new JdbcTemplate(routingDataSource);
|
||||
}
|
||||
|
||||
public NamedParameterJdbcTemplate createNamedParameterJdbcTemplate(FineractPlatformTenant tenant) {
|
||||
DataSource tenantDataSource = tenantDataSourceFactory.create(tenant);
|
||||
return new NamedParameterJdbcTemplate(tenantDataSource);
|
||||
return new NamedParameterJdbcTemplate(routingDataSource);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -22,7 +22,6 @@ import static org.apache.fineract.infrastructure.core.domain.FineractPlatformTen
|
||||
import static org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection.toProtocol;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
||||
import org.apache.fineract.infrastructure.core.service.database.DatabasePasswordEncryptor;
|
||||
@@ -48,7 +47,7 @@ public class TenantDataSourceFactory {
|
||||
this.databasePasswordEncryptor = databasePasswordEncryptor;
|
||||
}
|
||||
|
||||
public DataSource create(FineractPlatformTenant tenant) {
|
||||
public HikariDataSource create(FineractPlatformTenant tenant) {
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setDriverClassName(tenantDataSource.getDriverClassName());
|
||||
dataSource.setDataSourceProperties(tenantDataSource.getDataSourceProperties());
|
||||
|
||||
+2
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.JdbcTemplateFactory;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.infrastructure.core.service.tenant.TenantDetailsService;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.BulkBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
|
||||
@@ -62,6 +63,7 @@ public class ExternalEventConfigurationValidationService implements Initializing
|
||||
|
||||
if (isNotEmpty(tenants)) {
|
||||
for (FineractPlatformTenant tenant : tenants) {
|
||||
ThreadLocalContextUtil.setTenant(tenant);
|
||||
validateEventConfigurationForIndividualTenant(tenant, eventClasses);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user