From f157e9c01f7593e9c411cf4f332adb363a7f91ea Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 12 Mar 2019 15:08:51 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20HikariCP=20=D0=B2=D1=8B=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE?= =?UTF-8?q?=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/auth/MySQLSourceConfig.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java index fccb3b40..19c348c1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -31,6 +31,7 @@ public final class MySQLSourceConfig implements AutoCloseable { private String password; private String database; private String timeZone; + private boolean enableHikari; // Cache private transient DataSource source; @@ -79,20 +80,24 @@ public synchronized Connection getConnection() throws SQLException { hikari = false; // Try using HikariCP source = mysqlSource; - try { - Class.forName("com.zaxxer.hikari.HikariDataSource"); - hikari = true; // Used for shutdown. Not instanceof because of possible classpath error - HikariConfig cfg = new HikariConfig(); - cfg.setDataSource(mysqlSource); - cfg.setPoolName(poolName); - cfg.setMaximumPoolSize(MAX_POOL_SIZE); - // Set HikariCP pool - // Replace source with hds - source = new HikariDataSource(cfg); - LogHelper.warning("HikariCP pooling enabled for '%s'", poolName); - } catch (ClassNotFoundException ignored) { - LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName); + if(enableHikari) + { + try { + Class.forName("com.zaxxer.hikari.HikariDataSource"); + hikari = true; // Used for shutdown. Not instanceof because of possible classpath error + HikariConfig cfg = new HikariConfig(); + cfg.setDataSource(mysqlSource); + cfg.setPoolName(poolName); + cfg.setMaximumPoolSize(MAX_POOL_SIZE); + // Set HikariCP pool + // Replace source with hds + source = new HikariDataSource(cfg); + LogHelper.warning("HikariCP pooling enabled for '%s'", poolName); + } catch (ClassNotFoundException ignored) { + LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName); + } } + } return source.getConnection(); }