mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-05 18:39:40 +01:00
Switch back to official Postgres JDBC driver
This commit is contained in:
parent
d859085056
commit
2e5a1d79a4
@ -29,7 +29,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -39,7 +39,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -31,7 +31,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -78,6 +78,6 @@ dependencies {
|
||||
compileOnly 'io.nats:jnats:2.16.4'
|
||||
compileOnly 'com.rabbitmq:amqp-client:5.12.0'
|
||||
compileOnly 'org.mongodb:mongodb-driver-legacy:4.5.0'
|
||||
compileOnly 'com.impossibl.pgjdbc-ng:pgjdbc-ng:0.8.9'
|
||||
compileOnly 'org.postgresql:postgresql:42.6.0'
|
||||
compileOnly 'org.yaml:snakeyaml:1.28'
|
||||
}
|
||||
|
@ -153,18 +153,11 @@ public enum Dependency {
|
||||
Relocation.of("mysql", "com{}mysql")
|
||||
),
|
||||
POSTGRESQL_DRIVER(
|
||||
"com{}impossibl{}pgjdbc-ng",
|
||||
"pgjdbc-ng",
|
||||
"0.8.9",
|
||||
"WEYMezl02Rot2n2ATs7NABcvL9ceQ/oLA/XPduIEaWA=",
|
||||
Relocation.of("postgresql", "com{}impossibl")
|
||||
),
|
||||
POSTGRESQL_DRIVER_SPY(
|
||||
"com{}impossibl{}pgjdbc-ng",
|
||||
"spy",
|
||||
"0.8.9",
|
||||
"72ZuhpMy/4EYJZuSjBjGI5NGgdWmOpwjDHW9ISnqso8=",
|
||||
Relocation.of("postgresql", "com{}impossibl")
|
||||
"org{}postgresql",
|
||||
"postgresql",
|
||||
"42.6.0",
|
||||
"uBfGekDJQkn9WdTmhuMyftDT0/rkJrINoPHnVlLPxGE=",
|
||||
Relocation.of("postgresql", "org{}postgresql")
|
||||
),
|
||||
H2_DRIVER_LEGACY(
|
||||
"com.h2database",
|
||||
|
@ -55,7 +55,7 @@ public class DependencyRegistry {
|
||||
.putAll(StorageType.MONGODB, Dependency.MONGODB_DRIVER_CORE, Dependency.MONGODB_DRIVER_LEGACY, Dependency.MONGODB_DRIVER_SYNC, Dependency.MONGODB_DRIVER_BSON)
|
||||
.putAll(StorageType.MARIADB, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI, Dependency.MARIADB_DRIVER)
|
||||
.putAll(StorageType.MYSQL, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI, Dependency.MYSQL_DRIVER)
|
||||
.putAll(StorageType.POSTGRESQL, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI, Dependency.POSTGRESQL_DRIVER, Dependency.POSTGRESQL_DRIVER_SPY)
|
||||
.putAll(StorageType.POSTGRESQL, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI, Dependency.POSTGRESQL_DRIVER)
|
||||
.putAll(StorageType.SQLITE, Dependency.SQLITE_DRIVER)
|
||||
.putAll(StorageType.H2, Dependency.H2_DRIVER)
|
||||
.build();
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.messaging.postgres;
|
||||
|
||||
import com.impossibl.postgres.api.jdbc.PGConnection;
|
||||
import com.impossibl.postgres.api.jdbc.PGNotificationListener;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
import me.lucko.luckperms.common.storage.implementation.sql.SqlStorage;
|
||||
@ -34,12 +32,17 @@ import net.luckperms.api.messenger.IncomingMessageConsumer;
|
||||
import net.luckperms.api.messenger.Messenger;
|
||||
import net.luckperms.api.messenger.message.OutgoingMessage;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.postgresql.PGConnection;
|
||||
import org.postgresql.PGNotification;
|
||||
import org.postgresql.util.PSQLException;
|
||||
|
||||
import java.net.SocketException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* An implementation of {@link Messenger} using Postgres.
|
||||
@ -68,7 +71,7 @@ public class PostgresMessenger implements Messenger {
|
||||
|
||||
@Override
|
||||
public void sendOutgoingMessage(@NonNull OutgoingMessage outgoingMessage) {
|
||||
try (PGConnection connection = this.sqlStorage.getConnectionFactory().getConnection().unwrap(PGConnection.class)) {
|
||||
try (Connection connection = this.sqlStorage.getConnectionFactory().getConnection()) {
|
||||
try (PreparedStatement ps = connection.prepareStatement("SELECT pg_notify(?, ?)")) {
|
||||
ps.setString(1, CHANNEL);
|
||||
ps.setString(2, outgoingMessage.asEncodedString());
|
||||
@ -122,47 +125,60 @@ public class PostgresMessenger implements Messenger {
|
||||
}
|
||||
}
|
||||
|
||||
private class NotificationListener implements PGNotificationListener, AutoCloseable {
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
private final AtomicBoolean listening = new AtomicBoolean(false);
|
||||
private class NotificationListener implements AutoCloseable {
|
||||
private static final int RECEIVE_TIMEOUT_MILLIS = 1000;
|
||||
|
||||
private final AtomicBoolean open = new AtomicBoolean(true);
|
||||
private final AtomicReference<Thread> listeningThread = new AtomicReference<>();
|
||||
|
||||
public void listenAndBind() {
|
||||
try (PGConnection connection = PostgresMessenger.this.sqlStorage.getConnectionFactory().getConnection().unwrap(PGConnection.class)) {
|
||||
connection.addNotificationListener(CHANNEL, this);
|
||||
|
||||
try (Connection connection = PostgresMessenger.this.sqlStorage.getConnectionFactory().getConnection()) {
|
||||
try (Statement s = connection.createStatement()) {
|
||||
s.execute("LISTEN \"" + CHANNEL + "\"");
|
||||
}
|
||||
|
||||
this.listening.set(true);
|
||||
this.latch.await();
|
||||
PGConnection pgConnection = connection.unwrap(PGConnection.class);
|
||||
this.listeningThread.set(Thread.currentThread());
|
||||
|
||||
while (this.open.get()) {
|
||||
PGNotification[] notifications = pgConnection.getNotifications(RECEIVE_TIMEOUT_MILLIS);
|
||||
if (notifications != null) {
|
||||
for (PGNotification notification : notifications) {
|
||||
handleNotification(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PSQLException e) {
|
||||
if (!(e.getCause() instanceof SocketException && e.getCause().getMessage().equals("Socket closed"))) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
this.listening.set(false);
|
||||
this.listeningThread.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isListening() {
|
||||
return this.listening.get();
|
||||
return this.listeningThread.get() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notification(int processId, String channelName, String payload) {
|
||||
if (!CHANNEL.equals(channelName)) {
|
||||
public void handleNotification(PGNotification notification) {
|
||||
if (!CHANNEL.equals(notification.getName())) {
|
||||
return;
|
||||
}
|
||||
PostgresMessenger.this.consumer.consumeIncomingMessageAsString(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closed() {
|
||||
this.latch.countDown();
|
||||
PostgresMessenger.this.consumer.consumeIncomingMessageAsString(notification.getParameter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.latch.countDown();
|
||||
if (this.open.compareAndSet(true, false)) {
|
||||
Thread thread = this.listeningThread.get();
|
||||
if (thread != null) {
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,9 @@ public class PostgresConnectionFactory extends HikariConnectionFactory {
|
||||
|
||||
@Override
|
||||
protected void configureDatabase(HikariConfig config, String address, String port, String databaseName, String username, String password) {
|
||||
config.setDataSourceClassName("com.impossibl.postgres.jdbc.PGDataSource");
|
||||
config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
|
||||
config.addDataSourceProperty("serverName", address);
|
||||
config.addDataSourceProperty("portNumber", Integer.parseInt(port));
|
||||
config.addDataSourceProperty("portNumber", port);
|
||||
config.addDataSourceProperty("databaseName", databaseName);
|
||||
config.addDataSourceProperty("user", username);
|
||||
config.addDataSourceProperty("password", password);
|
||||
@ -63,12 +63,6 @@ public class PostgresConnectionFactory extends HikariConnectionFactory {
|
||||
// remove the default config properties which don't exist for PostgreSQL
|
||||
properties.remove("useUnicode");
|
||||
properties.remove("characterEncoding");
|
||||
|
||||
// socketTimeout -> networkTimeout
|
||||
Object socketTimeout = properties.remove("socketTimeout");
|
||||
if (socketTimeout != null) {
|
||||
properties.putIfAbsent("networkTimeout", Integer.parseInt(socketTimeout.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,7 +61,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -39,7 +39,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -29,7 +29,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -42,7 +42,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -32,7 +32,7 @@ dependencies {
|
||||
testImplementation 'redis.clients:jedis:3.5.2'
|
||||
testImplementation 'io.nats:jnats:2.16.4'
|
||||
testImplementation 'com.rabbitmq:amqp-client:5.12.0'
|
||||
testImplementation 'com.impossibl.pgjdbc-ng:pgjdbc-ng:0.8.9'
|
||||
testImplementation 'org.postgresql:postgresql:42.6.0'
|
||||
testImplementation 'com.h2database:h2:2.1.214'
|
||||
testImplementation 'mysql:mysql-connector-java:8.0.23'
|
||||
testImplementation 'org.mariadb.jdbc:mariadb-java-client:3.1.3'
|
||||
@ -60,7 +60,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
@ -36,7 +36,7 @@ shadowJar {
|
||||
relocate 'me.lucko.commodore', 'me.lucko.luckperms.lib.commodore'
|
||||
relocate 'org.mariadb.jdbc', 'me.lucko.luckperms.lib.mariadb'
|
||||
relocate 'com.mysql', 'me.lucko.luckperms.lib.mysql'
|
||||
relocate 'com.impossibl', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'org.postgresql', 'me.lucko.luckperms.lib.postgresql'
|
||||
relocate 'com.zaxxer.hikari', 'me.lucko.luckperms.lib.hikari'
|
||||
relocate 'com.mongodb', 'me.lucko.luckperms.lib.mongodb'
|
||||
relocate 'org.bson', 'me.lucko.luckperms.lib.bson'
|
||||
|
Loading…
Reference in New Issue
Block a user