FINERACT-796

Use Hikari instead of Tomcat Connection Pool
 - Created hikari connection pool bean
 - Configured connection parameters to match hikari
 - Removed tomcat-jdbc and dbcp
 - Remove unused classes
 - Add Hikari to logback
 - update hikaridatasource bean

closes https://issues.apache.org/jira/browse/FINERACT-796

remove hikaricp import from gradle files

more specific bean config

- Set up datasource properties
- Cleanup unused classes
- Add hikari to logback
This commit is contained in:
xurror
2020-03-28 15:06:34 +01:00
committed by Michael Vorburger ⛑️
parent 2e620b4de8
commit 3475c0cfb7
20 changed files with 100 additions and 496 deletions
-29
View File
@@ -31,35 +31,6 @@
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource type="javax.sql.DataSource"
name="jdbc/fineract_tenants"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="${fineract_tenants_driver}"
url="${fineract_tenants_url}"
username="${fineract_tenants_uid}"
password="${fineract_tenants_pwd}"
initialSize="3"
maxActive="10"
maxIdle="6"
minIdle="3"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
logAbandoned="true"
suspectTimeout="60"
/>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
+1 -7
View File
@@ -129,10 +129,7 @@ dependencyManagement {
entry 'tomcat-embed-jasper'
entry 'tomcat-embed-logging-log4j'
}
dependencySet(group: 'org.apache.tomcat', version: '7.0.94') {
entry 'tomcat-dbcp'
entry 'tomcat-jdbc'
}
}
}
@@ -404,7 +401,6 @@ tomcatRun {
stopPort = 8081
stopKey= 'stopKey'
enableSSL = true
configFile = file('src/test/resources/META-INF/context.xml')
}
tomcatRunWar {
@@ -415,7 +411,6 @@ tomcatRunWar {
enableSSL = true
keystoreFile = file('src/main/resources/keystore.jks')
keystorePass = 'openmf'
configFile = file('src/test/resources/META-INF/context.xml')
}
task tomcatRunWarAsDaemonForIntegrationTest(type: com.bmuschko.gradle.tomcat.tasks.TomcatRunWar) {
@@ -426,7 +421,6 @@ task tomcatRunWarAsDaemonForIntegrationTest(type: com.bmuschko.gradle.tomcat.tas
enableSSL = true
keystoreFile = file('src/main/resources/keystore.jks')
keystorePass = 'openmf'
configFile = file('src/test/resources/META-INF/context.xml')
daemon = true
}
+4 -9
View File
@@ -22,17 +22,14 @@ dependencies {
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
tomcat "org.apache.tomcat:tomcat-dbcp"
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
spotbugsPlugins "jp.skypencil.findbugs.slf4j:bug-pattern:1.4.2@jar"
compile ("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group: 'com.zaxxer', module: 'HikariCP'
}
compile ("org.springframework.boot:spring-boot-starter-data-jpa")
api(
api(
'com.google.code.gson:gson',
'org.quartz-scheduler:quartz',
'org.apache.openjpa:openjpa',
@@ -78,8 +75,6 @@ dependencies {
//'mysql:mysql-connector-java',
'org.drizzle.jdbc:drizzle-jdbc',
'org.apache.tomcat:tomcat-jdbc',
'org.apache.poi:poi',
'org.apache.poi:poi-ooxml',
@@ -125,6 +120,6 @@ dependencies {
'com.mockrunner:mockrunner-jdbc'
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
}
+3 -6
View File
@@ -22,7 +22,6 @@ dependencies {
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
tomcat "org.apache.tomcat:tomcat-dbcp"
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
@@ -79,8 +78,6 @@ dependencies {
//'mysql:mysql-connector-java',
'org.drizzle.jdbc:drizzle-jdbc',
'org.apache.tomcat:tomcat-jdbc',
'org.apache.poi:poi',
'org.apache.poi:poi-ooxml',
@@ -125,7 +122,7 @@ dependencies {
'com.sun.jersey:jersey-core',
'com.mockrunner:mockrunner-jdbc'
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
}
@@ -39,7 +39,7 @@ import org.springframework.context.annotation.ImportResource;
*/
public class WarWebApplicationInitializer extends SpringBootServletInitializer {
@ImportResource({ "classpath*:META-INF/spring/jndi.xml" })
@ImportResource({ "classpath*:META-INF/spring/hikariDataSource.xml" })
private static class Configuration extends AbstractApplicationConfiguration {
}
@@ -1,56 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.boot.db;
import javax.sql.DataSource;
import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration for a DataSource.
* @see DataSourceProperties about how to configure this DS
*/
@Configuration
public class DataSourceConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DataSourceConfiguration.class);
@Autowired JDBCDriverConfig config ;
@Bean
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties(config.getDriverClassName(), config.getProtocol(), config.getSubProtocol(), config.getPort());
}
@Bean
public DataSource tenantDataSourceJndi() {
PoolConfiguration p = getProperties();
org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p);
logger.info("Created new DataSource; url={}", p.getUrl());
return ds;
}
protected DataSourceProperties getProperties() {
return dataSourceProperties();
}
}
@@ -1,156 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.boot.db;
import javax.validation.constraints.NotNull;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
/**
* Configurable DataSource. Properties have sensible defaults, but end-users can
* override those via the Spring Values listed below; i.e. via -D Java System
* properties, or main() command line arguments, OS environment variables, from
* JNDI, or application.properties (thanks Spring Boot). For example:
* -Dfineract.datasource.port=3307.
*/
// NOT a @Component - we do not want this to picked up by component scan, only explicitly declared in DataSourceConfiguration (if that's active)
public class DataSourceProperties extends PoolProperties {
public final static String PORT = "fineract.datasource.port";
public final static String HOST = "fineract.datasource.host";
public final static String DB = "fineract.datasource.db";
public final static String UID = "fineract.datasource.username";
public final static String PWD = "fineract.datasource.password";
public final static String PROTOCOL = "fineract.datasource.protocol";
public final static String SUBPROTOCOL = "fineract.datasource.subprotocol";
@Value("${" + PORT + ":3306}")
private volatile @NotNull int port;
@Value("${" + HOST + ":localhost}")
private volatile @NotNull String hostname;
@Value("${" + DB + ":fineract_tenants}")
private volatile @NotNull String dbName;
@Value("${" + UID + ":root}")
private volatile @NotNull String username;
@Value("${" + PWD + ":mysql}")
private volatile @NotNull String password;
@Value("${" + PROTOCOL + ":jdbc}")
private volatile @NotNull String jdbcProtocol;
@Value("${" + SUBPROTOCOL + ":mysql:thin}")
private volatile @NotNull String jdbcSubprotocol;
public DataSourceProperties(String driverClassName, String protocol, String subProtocol, Integer port) {
super();
setDriverClassName(driverClassName);
this.jdbcProtocol = protocol ;
this.jdbcSubprotocol = subProtocol ;
this.port = port ;
setDefaults();
}
/**
* as per (some of..) INSTALL.md and
* org.apache.fineract.infrastructure.core.service
* .TomcatJdbcDataSourcePerTenantService
* .createNewDataSourceFor(FineractPlatformTenant)
*/
protected void setDefaults() {
setInitialSize(3);
// setMaxIdle(6); -- strange, why?
// setMinIdle(3); -- JavaDoc says default is initialSize.. so shouldn't
// be needed
if (getValidationQuery() == null) setValidationQuery("SELECT 1");
setTestOnBorrow(true);
setTestOnReturn(true);
setTestWhileIdle(true);
setTimeBetweenEvictionRunsMillis(30000);
setTimeBetweenEvictionRunsMillis(60000);
setLogAbandoned(true);
setSuspectTimeout(60);
setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport");
}
@Override
public void setUrl(@SuppressWarnings("unused") String url) {
throw new UnsupportedOperationException("Use setHost/Port/DB() instead of setURL()");
}
@Override
public String getUrl() {
String url = super.getUrl();
if (StringUtils.hasText(url)) {
throw new IllegalStateException();
}
return jdbcProtocol + ":" + jdbcSubprotocol + "://" + getHost() + ":" + getPort() + "/" + getDBName();
}
public String getHost() {
return hostname;
}
public int getPort() {
return port;
}
public String getDBName() {
return dbName;
}
public void setPort(int port) {
this.port = port;
}
public void setHost(String hostname) {
this.hostname = hostname;
}
public void setDBName(String dbName) {
this.dbName = dbName;
}
@Override
public String getUsername() {
return this.username;
}
@Override
public void setUsername(String username) {
this.username = username;
}
@Override
public String getPassword() {
return this.password;
}
@Override
public void setPassword(String password) {
this.password = password;
}
}
@@ -1,93 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.boot.db;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
/**
* Service which "fixes up" the schemaServerPort in the tenants table of the
* fineract_tenants schema. It sets it to the actual current port of
* MariaDB4j, instead of the default 3306 which is hard-coded in the initial
* set-up SQL script (V1__mifos-platform-shared-tenants.sql).
*
* This service is called by the TenantDatabaseUpgradeService
* "just at the right time" during start-up, that is AFTER the initialization of
* the fineract_tenants but BEFORE Flyway runs on all tenant schemas.
*
* It's difficult to achieve the same goal elsewhere, because we cannot do this
* e.g. in MariaDB4jSetupService, as that's too early
* (TenantDatabaseUpgradeService has not yet run), nor e.g. in
* TomcatJdbcDataSourcePerTenantService because in there we do not have access
* to and should not depend on MariaDB4j configuration.
*/
@Service
public class TenantDataSourcePortFixService {
private static final Logger logger = LoggerFactory.getLogger(TenantDataSourcePortFixService.class);
/**
* While what this class does is convenient in 96% you may would like to
* completely disable it if you've hand tuned your tenants table for an
* advanced configuration and use e.g. different databases maybe on
* different hosts for different tenants.
*/
public final static String ENABLED = "fineract.tenantdb.fixup";
@Value("${" + ENABLED + ":true}")
private boolean enabled;
// required=false is important here, because in
// WebApplicationInitializerConfiguration for classic WAR there
// is (intentionally) no MariaDB4j nor a DataSourceProperties
// bean (because in the WAR we're using a DS from JNDI)
private @Autowired(required = false) DataSourceProperties dsp;
private JdbcTemplate jdbcTemplate;
@Autowired
public TenantDataSourcePortFixService(@Qualifier("tenantDataSourceJndi") final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public void fixUpTenantsSchemaServerPort() {
if (!enabled) {
logger.info("No schema_server_port UPDATE made to tenant_server_connections table of the fineract_tenants schema, because {} = false", ENABLED);
return;
}
if (dsp == null) {
// we don't have any generic mechanism to know the DB port, given just a tenant DataSource
logger.debug("No schema_server_port UPDATE made to tenant_server_connections table of the fineract_tenants schema (because neither MariaDB4j nor our own Spring Boot DataSourceConfiguration is used in a traditional WAR)");
return;
}
int r = jdbcTemplate
.update("UPDATE tenant_server_connections SET schema_server = ?, schema_server_port = ?, schema_username = ?, schema_password = ?",
dsp.getHost(), dsp.getPort(), dsp.getUsername(), dsp.getPassword());
if ( r == 0 )
logger.warn("UPDATE tenant_server_connections SET ... did not update ANY rows - something is probably wrong");
else
logger.info("Upated {} rows in the tenant_server_connections table of the fineract_tenants schema to the real current host: {}, port: {}",
new Object[] { r, dsp.getHost(), dsp.getPort() });
}
}
@@ -32,7 +32,7 @@ public class DataSourceForTenants implements RoutingDataSourceService {
private final DataSource tenantDataSource;
@Autowired
public DataSourceForTenants(final @Qualifier("tenantDataSourceJndi") DataSource tenantDataSource) {
public DataSourceForTenants(final @Qualifier("hikariTenantDataSource") DataSource tenantDataSource) {
this.tenantDataSource = tenantDataSource;
}
@@ -26,7 +26,6 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
import org.apache.fineract.infrastructure.core.boot.db.TenantDataSourcePortFixService;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
import org.apache.fineract.infrastructure.security.service.TenantDetailsService;
@@ -47,16 +46,13 @@ public class TenantDatabaseUpgradeService {
private final TenantDetailsService tenantDetailsService;
protected final DataSource tenantDataSource;
protected final TenantDataSourcePortFixService tenantDataSourcePortFixService;
@Autowired private JDBCDriverConfig driverConfig;
@Autowired
public TenantDatabaseUpgradeService(final TenantDetailsService detailsService,
@Qualifier("tenantDataSourceJndi") final DataSource dataSource, TenantDataSourcePortFixService tenantDataSourcePortFixService) {
public TenantDatabaseUpgradeService(final TenantDetailsService detailsService, @Qualifier("hikariTenantDataSource") final DataSource dataSource) {
this.tenantDetailsService = detailsService;
this.tenantDataSource = dataSource;
this.tenantDataSourcePortFixService = tenantDataSourcePortFixService;
}
@PostConstruct
@@ -104,8 +100,6 @@ public class TenantDatabaseUpgradeService {
"fineract_default_tenantdb_uid", dbUid,
"fineract_default_tenantdb_pwd", dbPwd));
flyway.migrate();
tenantDataSourcePortFixService.fixUpTenantsSchemaServerPort();
}
private String getEnvVar(String name, String defaultValue) {
@@ -18,14 +18,14 @@
*/
package org.apache.fineract.infrastructure.core.service;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@@ -48,7 +48,7 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
private JDBCDriverConfig driverConfig ;
@Autowired
public TomcatJdbcDataSourcePerTenantService(final @Qualifier("tenantDataSourceJndi") DataSource tenantDataSource) {
public TomcatJdbcDataSourcePerTenantService(final @Qualifier("hikariTenantDataSource") DataSource tenantDataSource) {
this.tenantDataSource = tenantDataSource;
}
@@ -85,42 +85,20 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
// 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()) ;
//final String jdbcUrl = tenantConnectionObj.databaseURL();
final PoolConfiguration poolConfiguration = new PoolProperties();
poolConfiguration.setDriverClassName(this.driverConfig.getDriverClassName());
poolConfiguration.setName(tenantConnectionObj.getSchemaName() + "_pool");
poolConfiguration.setUrl(jdbcUrl);
poolConfiguration.setUsername(tenantConnectionObj.getSchemaUsername());
poolConfiguration.setPassword(tenantConnectionObj.getSchemaPassword());
String jdbcUrl = this.driverConfig.constructProtocol(tenantConnectionObj.getSchemaServer(), tenantConnectionObj.getSchemaServerPort(), tenantConnectionObj.getSchemaName());
poolConfiguration.setInitialSize(tenantConnectionObj.getInitialSize());
HikariConfig config = new HikariConfig();
config.setDriverClassName(this.driverConfig.getDriverClassName());
config.setPoolName(tenantConnectionObj.getSchemaName() + "_pool");
config.setJdbcUrl(jdbcUrl);
config.setUsername(tenantConnectionObj.getSchemaUsername());
config.setPassword(tenantConnectionObj.getSchemaPassword());
poolConfiguration.setTestOnBorrow(tenantConnectionObj.isTestOnBorrow());
poolConfiguration.setValidationQuery("SELECT 1");
poolConfiguration.setValidationInterval(tenantConnectionObj.getValidationInterval());
config.setConnectionTestQuery("SELECT 1");
config.setValidationTimeout(tenantConnectionObj.getValidationInterval());
poolConfiguration.setRemoveAbandoned(tenantConnectionObj.isRemoveAbandoned());
poolConfiguration.setRemoveAbandonedTimeout(tenantConnectionObj.getRemoveAbandonedTimeout());
poolConfiguration.setLogAbandoned(tenantConnectionObj.isLogAbandoned());
poolConfiguration.setAbandonWhenPercentageFull(tenantConnectionObj.getAbandonWhenPercentageFull());
poolConfiguration.setDefaultAutoCommit(true);
config.setAutoCommit(true);
/**
* Vishwas- Do we need to enable the below properties and add
* ResetAbandonedTimer for long running batch Jobs?
**/
// poolConfiguration.setMaxActive(tenant.getMaxActive());
// poolConfiguration.setMinIdle(tenant.getMinIdle());
// poolConfiguration.setMaxIdle(tenant.getMaxIdle());
// poolConfiguration.setSuspectTimeout(tenant.getSuspectTimeout());
// poolConfiguration.setTimeBetweenEvictionRunsMillis(tenant.getTimeBetweenEvictionRunsMillis());
// poolConfiguration.setMinEvictableIdleTimeMillis(tenant.getMinEvictableIdleTimeMillis());
poolConfiguration.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport");
return new org.apache.tomcat.jdbc.pool.DataSource(poolConfiguration);
return new HikariDataSource(config);
}
}
@@ -42,7 +42,7 @@ public class BasicAuthTenantDetailsServiceJdbc implements BasicAuthTenantDetails
private final JdbcTemplate jdbcTemplate;
@Autowired
public BasicAuthTenantDetailsServiceJdbc(@Qualifier("tenantDataSourceJndi") final DataSource dataSource) {
public BasicAuthTenantDetailsServiceJdbc(@Qualifier("hikariTenantDataSource") final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@@ -43,7 +43,7 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public JdbcTenantDetailsService(@Qualifier("tenantDataSourceJndi") final DataSource dataSource) {
public JdbcTenantDetailsService(@Qualifier("hikariTenantDataSource") final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<!-- HikariCP Database bean -->
<bean id="hikariTenantDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
<!-- HikariConfig config that is fed to above dataSource -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="${fineract_tenants_driver}" />
<property name="jdbcUrl" value="${fineract_tenants_url}" />
<property name="username" value="${fineract_tenants_uid}" />
<property name="password" value="${fineract_tenants_pwd}" />
<property name="minimumIdle" value="3" />
<property name="maximumPoolSize" value="10" />
<property name="idleTimeout" value="60000" />
<property name="ConnectionTestQuery" value="SELECT 1" />
<!-- https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration -->
<property name="dataSourceProperties">
<props>
<prop key="cachePrepStmts">true</prop>
<prop key="prepStmtCacheSize">250</prop>
<prop key="prepStmtCacheSqlLimit">2048</prop>
<prop key="useServerPrepStmts">true</prop>
<prop key="useLocalSessionState">true</prop>
<prop key="rewriteBatchedStatements">true</prop>
<prop key="cacheResultSetMetadata">true</prop>
<prop key="cacheServerConfiguration">true</prop>
<prop key="elideSetAutoCommits">true</prop>
<prop key="maintainTimeStats">true</prop>
</props>
</property>
</bean>
</beans>
@@ -20,4 +20,9 @@
DRIVERCLASS_NAME:org.drizzle.jdbc.DrizzleDriver
PROTOCOL:jdbc
SUB_PROTOCOL:mysql:thin
PORT:3306
PORT:3306
fineract_tenants_driver:org.drizzle.jdbc.DrizzleDriver
fineract_tenants_url:jdbc:mysql:thin://localhost:3306/fineract_tenants
fineract_tenants_uid:root
fineract_tenants_pwd:mysql
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<!-- name here must match TestDataSourceConfiguration -->
<jee:jndi-lookup jndi-name="java:comp/env/jdbc/fineract_tenants"
id="tenantDataSourceJndi" />
</beans>
@@ -44,6 +44,7 @@
<logger name="org.springframework.beans" level="info" />
<logger name="net.sf.ehcache" level="error" />
<logger name="org.hibernate.cache" level="error" />
<logger name="com.zaxxer.hikari" level="debug" additivity="false" />
<root level="info">
<appender-ref ref="STDOUT" />
@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Context>
<ResourceLink name="jdbc/fineract_tenants" global="jdbc/fineract_tenants"
type="javax.sql.DataSource" />
</Context>
@@ -39,7 +39,7 @@ public class TestsWithoutDatabaseAndNoJobsConfiguration extends AbstractApplicat
*/
@Bean
public TenantDatabaseUpgradeService tenantDatabaseUpgradeService() {
return new TenantDatabaseUpgradeService(null, null, null) {
return new TenantDatabaseUpgradeService(null, null) {
@Override
public void upgradeAllTenants() {
// NOOP
@@ -62,7 +62,7 @@ public class TestsWithoutDatabaseAndNoJobsConfiguration extends AbstractApplicat
* DataSource with Mockito RETURNS_MOCKS black magic.
*/
@Bean
public DataSource tenantDataSourceJndi() {
public DataSource hikariTenantDataSource() {
DataSource mockDataSource = Mockito.mock(DataSource.class, Mockito.RETURNS_MOCKS);
return mockDataSource;
}
@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Context>
<Resource type="javax.sql.DataSource" name="jdbc/fineract_tenants"
driverClassName="org.drizzle.jdbc.DrizzleDriver" url="jdbc:mysql:thin://localhost:3306/fineract_tenants"
username="root" password="mysql" validationQuery="select 1" maxActive="10"
maxIdle="4" />
</Context>