Switched to using HikariCP for connection pool
All checks were successful
Locusworks Team/eight-track/pipeline/head This commit looks good
All checks were successful
Locusworks Team/eight-track/pipeline/head This commit looks good
This commit is contained in:
@@ -30,21 +30,19 @@ package net.locusworks.discord.eighttrack.database.config;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||
|
||||
@Primary
|
||||
@@ -76,35 +74,22 @@ public class EightTrackDataSource {
|
||||
*/
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
return getDataSource(false);
|
||||
logger.debug("Getting datasource");
|
||||
return getDataSource(confService.getDatabaseUsername(),
|
||||
confService.getDatabasePassword(),
|
||||
"/eighttrack");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource flywayDataSource() throws Exception {
|
||||
logger.debug("Logging in with flyway for migrations");
|
||||
|
||||
String user = confService.getDatabaseRootUsername();
|
||||
String passwd = confService.getDatabaseRootPassword();
|
||||
|
||||
String url = String.format("jdbc:mariadb://%s:%d?user=%s&password=%s",
|
||||
confService.getDatabaseHost(), confService.getDatabasePort(),
|
||||
user, passwd);
|
||||
|
||||
MariaDbDataSource mariadbDS = new MariaDbDataSource(url);
|
||||
|
||||
return mariadbDS;
|
||||
return getDataSource(confService.getDatabaseRootUsername(),
|
||||
confService.getDatabaseRootPassword(),
|
||||
"");
|
||||
}
|
||||
|
||||
private DataSource getDataSource(Boolean isFlyway) throws Exception {
|
||||
logger.debug("Getting datasource");
|
||||
|
||||
String user = confService.getDatabaseUsername();
|
||||
String passwd = confService.getDatabasePassword();
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("user", user);
|
||||
props.setProperty("password", passwd);
|
||||
|
||||
private DataSource getDataSource(String user, String passwd, String db) throws Exception {
|
||||
List<String> params = mysqlProperties
|
||||
.entrySet()
|
||||
.stream()
|
||||
@@ -114,22 +99,19 @@ public class EightTrackDataSource {
|
||||
String host = confService.getDatabaseHost();
|
||||
int port = confService.getDatabasePort();
|
||||
|
||||
String url = String.format(JNDI_STRING, host, port, "/eighttrack");
|
||||
String url = String.format(JNDI_STRING, host, port, db);
|
||||
|
||||
url = String.format("%s?%s", url, StringUtils.join(params, "&"));
|
||||
|
||||
logger.debug("Database connection string: %s", url);
|
||||
|
||||
ComboPooledDataSource cpds = new ComboPooledDataSource();
|
||||
cpds.setDriverClass(DRIVER);
|
||||
cpds.setJdbcUrl(url);
|
||||
cpds.setUser(user);
|
||||
cpds.setPassword(passwd);
|
||||
cpds.setMinPoolSize(5);
|
||||
cpds.setMaxPoolSize(100);
|
||||
cpds.setAcquireIncrement(10);
|
||||
|
||||
return cpds;
|
||||
return DataSourceBuilder
|
||||
.create()
|
||||
.username(user)
|
||||
.password(passwd)
|
||||
.url(url)
|
||||
.driverClassName(DRIVER)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user