Update hikari version

This commit is contained in:
Luck 2017-03-11 10:31:51 +00:00
parent 7b712e7f90
commit 680ad3c145
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 52 additions and 31 deletions

View File

@ -101,13 +101,6 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- HikariCP - needed as source -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<!-- Lombok --> <!-- Lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>

View File

@ -50,7 +50,7 @@
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>2.5.1</version> <version>2.6.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Jedis --> <!-- Jedis -->

View File

@ -33,7 +33,7 @@ public enum Dependency {
POSTGRESQL_DRIVER("https://repo1.maven.org/maven2/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar", "9.4.1212", "org.postgresql.ds.PGSimpleDataSource"), POSTGRESQL_DRIVER("https://repo1.maven.org/maven2/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar", "9.4.1212", "org.postgresql.ds.PGSimpleDataSource"),
H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193", "org.h2.Driver"), H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193", "org.h2.Driver"),
SQLITE_DRIVER("https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.15.1/sqlite-jdbc-3.15.1.jar", "3.15.1", "org.sqlite.JDBC"), SQLITE_DRIVER("https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.15.1/sqlite-jdbc-3.15.1.jar", "3.15.1", "org.sqlite.JDBC"),
HIKARI("https://repo1.maven.org/maven2/com/zaxxer/HikariCP/2.5.1/HikariCP-2.5.1.jar", "2.5.1", "com.zaxxer.hikari.HikariDataSource"), HIKARI("https://repo1.maven.org/maven2/com/zaxxer/HikariCP/2.6.1/HikariCP-2.6.1.jar", "2.6.1", "com.zaxxer.hikari.HikariConfig"),
SLF4J_SIMPLE("https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.9/slf4j-simple-1.7.9.jar", "1.7.9", "org.slf4j.impl.SimpleLoggerFactory"), SLF4J_SIMPLE("https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.9/slf4j-simple-1.7.9.jar", "1.7.9", "org.slf4j.impl.SimpleLoggerFactory"),
SLF4J_API("https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar", "1.7.9", "org.slf4j.helpers.BasicMarkerFactory"), SLF4J_API("https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar", "1.7.9", "org.slf4j.helpers.BasicMarkerFactory"),
MONGODB_DRIVER("https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.4.1/mongo-java-driver-3.4.1.jar", "3.4.1", "com.mongodb.Mongo"), MONGODB_DRIVER("https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.4.1/mongo-java-driver-3.4.1.jar", "3.4.1", "com.mongodb.Mongo"),

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.common.storage.backing.sqlprovider; package me.lucko.luckperms.common.storage.backing.sqlprovider;
import java.io.File; import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -57,18 +58,25 @@ abstract class FlatfileProvider extends SQLProvider {
public WrappedConnection getConnection() throws SQLException { public WrappedConnection getConnection() throws SQLException {
lock.lock(); lock.lock();
try { try {
if (connection == null || connection.isClosed()) { if (this.connection == null || this.connection.isClosed()) {
try { try {
Class.forName(getDriverClass()); Class.forName(getDriverClass());
} catch (ClassNotFoundException ignored) {} } catch (ClassNotFoundException ignored) {}
connection = new WrappedConnection(DriverManager.getConnection(getDriverId() + ":" + file.getAbsolutePath()), false); Connection connection = DriverManager.getConnection(getDriverId() + ":" + file.getAbsolutePath());
if (connection != null) {
this.connection = new WrappedConnection(connection, false);
}
} }
} finally { } finally {
lock.unlock(); lock.unlock();
} }
return connection; if (this.connection == null) {
throw new SQLException("Connection is null");
}
return this.connection;
} }
} }

View File

@ -27,6 +27,7 @@ import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.common.storage.DatastoreConfiguration; import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -62,21 +63,26 @@ public class MySQLProvider extends SQLProvider {
config.addDataSourceProperty("databaseName", database); config.addDataSourceProperty("databaseName", database);
config.addDataSourceProperty("user", username); config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password); config.addDataSourceProperty("password", password);
config.addDataSourceProperty("cachePrepStmts", true); config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", 250); config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", true); config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("cacheCallableStmts", true); config.addDataSourceProperty("cacheCallableStmts", "true");
config.addDataSourceProperty("alwaysSendSetIsolation", false); config.addDataSourceProperty("alwaysSendSetIsolation", "false");
config.addDataSourceProperty("cacheServerConfiguration", true); config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", true); config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("useLocalSessionState", true); config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("characterEncoding", "utf8"); config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("useUnicode", "true"); config.addDataSourceProperty("useUnicode", "true");
config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10)); // 10000
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(5)); // 5000 // We will wait for 15 seconds to get a connection from the pool.
config.setValidationTimeout(TimeUnit.SECONDS.toMillis(3)); // 3000 // Default is 30, but it shouldn't be taking that long.
config.setInitializationFailFast(true); config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000
// If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000
// The drivers are really old in some of the older Spigot binaries, so Connection#isValid doesn't work.
config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1"); config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1");
hikari = new HikariDataSource(config); hikari = new HikariDataSource(config);
@ -91,6 +97,10 @@ public class MySQLProvider extends SQLProvider {
@Override @Override
public WrappedConnection getConnection() throws SQLException { public WrappedConnection getConnection() throws SQLException {
return new WrappedConnection(hikari.getConnection(), true); Connection connection = hikari.getConnection();
if (connection == null) {
throw new SQLException("Connection is null");
}
return new WrappedConnection(connection, true);
} }
} }

View File

@ -27,6 +27,7 @@ import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.common.storage.DatastoreConfiguration; import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -62,10 +63,15 @@ public class PostgreSQLProvider extends SQLProvider {
config.addDataSourceProperty("databaseName", database); config.addDataSourceProperty("databaseName", database);
config.addDataSourceProperty("user", username); config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password); config.addDataSourceProperty("password", password);
config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10)); // 10000
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(5)); // 5000 // We will wait for 15 seconds to get a connection from the pool.
config.setValidationTimeout(TimeUnit.SECONDS.toMillis(3)); // 3000 // Default is 30, but it shouldn't be taking that long.
config.setInitializationFailFast(true); config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000
// If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000
// Just in-case the driver isn't JDBC4+
config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1"); config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1");
hikari = new HikariDataSource(config); hikari = new HikariDataSource(config);
@ -80,6 +86,10 @@ public class PostgreSQLProvider extends SQLProvider {
@Override @Override
public WrappedConnection getConnection() throws SQLException { public WrappedConnection getConnection() throws SQLException {
return new WrappedConnection(hikari.getConnection(), true); Connection connection = hikari.getConnection();
if (connection == null) {
throw new SQLException("Connection is null");
}
return new WrappedConnection(connection, true);
} }
} }