[FEATURE] HikariCP выключен по умолчанию

This commit is contained in:
Gravit 2019-03-12 15:08:51 +07:00
parent 96254b11ea
commit f157e9c01f
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -31,6 +31,7 @@ public final class MySQLSourceConfig implements AutoCloseable {
private String password; private String password;
private String database; private String database;
private String timeZone; private String timeZone;
private boolean enableHikari;
// Cache // Cache
private transient DataSource source; private transient DataSource source;
@ -79,20 +80,24 @@ public synchronized Connection getConnection() throws SQLException {
hikari = false; hikari = false;
// Try using HikariCP // Try using HikariCP
source = mysqlSource; source = mysqlSource;
try { if(enableHikari)
Class.forName("com.zaxxer.hikari.HikariDataSource"); {
hikari = true; // Used for shutdown. Not instanceof because of possible classpath error try {
HikariConfig cfg = new HikariConfig(); Class.forName("com.zaxxer.hikari.HikariDataSource");
cfg.setDataSource(mysqlSource); hikari = true; // Used for shutdown. Not instanceof because of possible classpath error
cfg.setPoolName(poolName); HikariConfig cfg = new HikariConfig();
cfg.setMaximumPoolSize(MAX_POOL_SIZE); cfg.setDataSource(mysqlSource);
// Set HikariCP pool cfg.setPoolName(poolName);
// Replace source with hds cfg.setMaximumPoolSize(MAX_POOL_SIZE);
source = new HikariDataSource(cfg); // Set HikariCP pool
LogHelper.warning("HikariCP pooling enabled for '%s'", poolName); // Replace source with hds
} catch (ClassNotFoundException ignored) { source = new HikariDataSource(cfg);
LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName); LogHelper.warning("HikariCP pooling enabled for '%s'", poolName);
} catch (ClassNotFoundException ignored) {
LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName);
}
} }
} }
return source.getConnection(); return source.getConnection();
} }