Minor clean ups in DataSource Connection Pool related code
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
99794914a5
commit
5f2ba51f5a
+4
-5
@@ -42,10 +42,10 @@ public class JDBCDriverConfig {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
protected void init() {
|
protected void init() {
|
||||||
Environment environment = context.getEnvironment() ;
|
Environment environment = context.getEnvironment() ;
|
||||||
driverClassName = (String)environment.getProperty(DRIVER_CLASS_PROPERTYNAME) ;
|
driverClassName = environment.getProperty(DRIVER_CLASS_PROPERTYNAME) ;
|
||||||
protocol = (String) environment.getProperty(PROTOCOL_PROPERTYNAME) ;
|
protocol = environment.getProperty(PROTOCOL_PROPERTYNAME) ;
|
||||||
subProtocol = (String) environment.getProperty(SUBPROTOCOL_PROPERTYNAME) ;
|
subProtocol = environment.getProperty(SUBPROTOCOL_PROPERTYNAME) ;
|
||||||
port = Integer.parseInt((String) environment.getProperty(PORT_PROPERTYNAME)) ;
|
port = Integer.parseInt(environment.getProperty(PORT_PROPERTYNAME)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDriverClassName() {
|
public String getDriverClassName() {
|
||||||
@@ -69,5 +69,4 @@ public class JDBCDriverConfig {
|
|||||||
.append('/').append(schemaName).toString();
|
.append('/').append(schemaName).toString();
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -54,5 +54,4 @@ public class FineractPlatformTenant {
|
|||||||
public FineractPlatformTenantConnection getConnection() {
|
public FineractPlatformTenantConnection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-85
@@ -20,8 +20,7 @@ package org.apache.fineract.infrastructure.core.domain;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds DB server connection details.
|
* Holds Tenant's DB server connection connection details.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class FineractPlatformTenantConnection {
|
public class FineractPlatformTenantConnection {
|
||||||
|
|
||||||
@@ -77,161 +76,78 @@ public class FineractPlatformTenantConnection {
|
|||||||
this.testOnBorrow=tesOnBorrow;
|
this.testOnBorrow=tesOnBorrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
//The Connection Protocol should be built based on jdbc.properties. We can't hard code this here and also, constructing protocol is not this class
|
|
||||||
//responsibility
|
|
||||||
/*public String databaseURL() {
|
|
||||||
final String url = new StringBuilder("jdbc:mysql:thin://").append(this.schemaServer).append(':').append(this.schemaServerPort)
|
|
||||||
.append('/').append(this.schemaName).toString();
|
|
||||||
return url;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the schemaServer
|
|
||||||
*/
|
|
||||||
public String getSchemaServer() {
|
public String getSchemaServer() {
|
||||||
return this.schemaServer;
|
return this.schemaServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the schemaServerPort
|
|
||||||
*/
|
|
||||||
public String getSchemaServerPort() {
|
public String getSchemaServerPort() {
|
||||||
return this.schemaServerPort;
|
return this.schemaServerPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the schemaUsername
|
|
||||||
*/
|
|
||||||
public String getSchemaUsername() {
|
public String getSchemaUsername() {
|
||||||
return this.schemaUsername;
|
return this.schemaUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the schemaPassword
|
|
||||||
*/
|
|
||||||
public String getSchemaPassword() {
|
public String getSchemaPassword() {
|
||||||
return this.schemaPassword;
|
return this.schemaPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the autoUpdateEnabled
|
|
||||||
*/
|
|
||||||
public boolean isAutoUpdateEnabled() {
|
public boolean isAutoUpdateEnabled() {
|
||||||
return this.autoUpdateEnabled;
|
return this.autoUpdateEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the initialSize
|
|
||||||
*/
|
|
||||||
public int getInitialSize() {
|
public int getInitialSize() {
|
||||||
return this.initialSize;
|
return this.initialSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the validationInterval
|
|
||||||
*/
|
|
||||||
public long getValidationInterval() {
|
public long getValidationInterval() {
|
||||||
return this.validationInterval;
|
return this.validationInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the removeAbandoned
|
|
||||||
*/
|
|
||||||
public boolean isRemoveAbandoned() {
|
public boolean isRemoveAbandoned() {
|
||||||
return this.removeAbandoned;
|
return this.removeAbandoned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the removeAbandonedTimeout
|
|
||||||
*/
|
|
||||||
public int getRemoveAbandonedTimeout() {
|
public int getRemoveAbandonedTimeout() {
|
||||||
return this.removeAbandonedTimeout;
|
return this.removeAbandonedTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the logAbandoned
|
|
||||||
*/
|
|
||||||
public boolean isLogAbandoned() {
|
public boolean isLogAbandoned() {
|
||||||
return this.logAbandoned;
|
return this.logAbandoned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the abandonWhenPercentageFull
|
|
||||||
*/
|
|
||||||
public int getAbandonWhenPercentageFull() {
|
public int getAbandonWhenPercentageFull() {
|
||||||
return this.abandonWhenPercentageFull;
|
return this.abandonWhenPercentageFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the maxActive
|
|
||||||
*/
|
|
||||||
public int getMaxActive() {
|
public int getMaxActive() {
|
||||||
return this.maxActive;
|
return this.maxActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the minIdle
|
|
||||||
*/
|
|
||||||
public int getMinIdle() {
|
public int getMinIdle() {
|
||||||
return this.minIdle;
|
return this.minIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the maxIdle
|
|
||||||
*/
|
|
||||||
public int getMaxIdle() {
|
public int getMaxIdle() {
|
||||||
return this.maxIdle;
|
return this.maxIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suspectTimeout
|
|
||||||
*/
|
|
||||||
public int getSuspectTimeout() {
|
public int getSuspectTimeout() {
|
||||||
return this.suspectTimeout;
|
return this.suspectTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the timeBetweenEvictionRunsMillis
|
|
||||||
*/
|
|
||||||
public int getTimeBetweenEvictionRunsMillis() {
|
public int getTimeBetweenEvictionRunsMillis() {
|
||||||
return this.timeBetweenEvictionRunsMillis;
|
return this.timeBetweenEvictionRunsMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the minEvictableIdleTimeMillis
|
|
||||||
*/
|
|
||||||
public int getMinEvictableIdleTimeMillis() {
|
public int getMinEvictableIdleTimeMillis() {
|
||||||
return this.minEvictableIdleTimeMillis;
|
return this.minEvictableIdleTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the maxRetriesOnDeadlock
|
|
||||||
*/
|
|
||||||
public int getMaxRetriesOnDeadlock() {
|
public int getMaxRetriesOnDeadlock() {
|
||||||
return this.maxRetriesOnDeadlock;
|
return this.maxRetriesOnDeadlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the maxIntervalBetweenRetries
|
|
||||||
*/
|
|
||||||
public int getMaxIntervalBetweenRetries() {
|
public int getMaxIntervalBetweenRetries() {
|
||||||
return this.maxIntervalBetweenRetries;
|
return this.maxIntervalBetweenRetries;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-15
@@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation that returns a new or existing tomcat 7 jdbc connection pool
|
* Implementation that returns a new or existing connection pool
|
||||||
* datasource based on the tenant details stored in a {@link ThreadLocal}
|
* datasource based on the tenant details stored in a {@link ThreadLocal}
|
||||||
* variable for this request.
|
* variable for this request.
|
||||||
*
|
*
|
||||||
@@ -54,7 +54,6 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSource retrieveDataSource() {
|
public DataSource retrieveDataSource() {
|
||||||
|
|
||||||
// default to tenant database datasource
|
// default to tenant database datasource
|
||||||
DataSource tenantDataSource = this.tenantDataSource;
|
DataSource tenantDataSource = this.tenantDataSource;
|
||||||
|
|
||||||
@@ -63,12 +62,10 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
|||||||
final FineractPlatformTenantConnection tenantConnection = tenant.getConnection();
|
final FineractPlatformTenantConnection tenantConnection = tenant.getConnection();
|
||||||
|
|
||||||
synchronized (this.tenantToDataSourceMap) {
|
synchronized (this.tenantToDataSourceMap) {
|
||||||
// if tenantConnection information available switch to
|
// if tenantConnection information available switch to the appropriate datasource for that tenant.
|
||||||
// appropriate
|
DataSource possibleDS = this.tenantToDataSourceMap.get(tenantConnection.getConnectionId());
|
||||||
// datasource
|
if (possibleDS != null) {
|
||||||
// for that tenant.
|
tenantDataSource = possibleDS;
|
||||||
if (this.tenantToDataSourceMap.containsKey(tenantConnection.getConnectionId())) {
|
|
||||||
tenantDataSource = this.tenantToDataSourceMap.get(tenantConnection.getConnectionId());
|
|
||||||
} else {
|
} else {
|
||||||
tenantDataSource = createNewDataSourceFor(tenantConnection);
|
tenantDataSource = createNewDataSourceFor(tenantConnection);
|
||||||
this.tenantToDataSourceMap.put(tenantConnection.getConnectionId(), tenantDataSource);
|
this.tenantToDataSourceMap.put(tenantConnection.getConnectionId(), tenantDataSource);
|
||||||
@@ -79,12 +76,8 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
|||||||
return tenantDataSource;
|
return tenantDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates the data source oltp and report databases
|
// creates the tenant data source for the oltp and report database
|
||||||
private DataSource createNewDataSourceFor(final FineractPlatformTenantConnection tenantConnectionObj) {
|
private DataSource createNewDataSourceFor(final FineractPlatformTenantConnection tenantConnectionObj) {
|
||||||
// see
|
|
||||||
// http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
|
|
||||||
|
|
||||||
// see also org.apache.fineract.DataSourceProperties.setDefaults()
|
|
||||||
String jdbcUrl = this.driverConfig.constructProtocol(tenantConnectionObj.getSchemaServer(), tenantConnectionObj.getSchemaServerPort(), tenantConnectionObj.getSchemaName());
|
String jdbcUrl = this.driverConfig.constructProtocol(tenantConnectionObj.getSchemaServer(), tenantConnectionObj.getSchemaServerPort(), tenantConnectionObj.getSchemaName());
|
||||||
|
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
@@ -93,12 +86,12 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
|||||||
config.setJdbcUrl(jdbcUrl);
|
config.setJdbcUrl(jdbcUrl);
|
||||||
config.setUsername(tenantConnectionObj.getSchemaUsername());
|
config.setUsername(tenantConnectionObj.getSchemaUsername());
|
||||||
config.setPassword(tenantConnectionObj.getSchemaPassword());
|
config.setPassword(tenantConnectionObj.getSchemaPassword());
|
||||||
|
|
||||||
config.setConnectionTestQuery("SELECT 1");
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
config.setValidationTimeout(tenantConnectionObj.getValidationInterval());
|
config.setValidationTimeout(tenantConnectionObj.getValidationInterval());
|
||||||
|
|
||||||
config.setAutoCommit(true);
|
config.setAutoCommit(true);
|
||||||
|
|
||||||
|
// https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
|
||||||
|
|
||||||
return new HikariDataSource(config);
|
return new HikariDataSource(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user