mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Fix loading of shaded SQL drivers
This commit is contained in:
3 files changed
+48
-18
No files matched your search
+2
-13
@@ -24,9 +24,7 @@ import com.google.inject.MembersInjector;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import java.sql.Driver;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.ServiceLoader;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
@@ -45,6 +43,7 @@ import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
|||||||
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
||||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
|
import net.draycia.carbon.common.util.SQLDrivers;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -155,8 +154,7 @@ public final class MySQLUserManager extends DatabaseUserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MySQLUserManager create() {
|
public MySQLUserManager create() {
|
||||||
ServiceLoader.load(Driver.class).stream()
|
SQLDrivers.loadFrom(this.getClass().getClassLoader());
|
||||||
.forEach(provider -> forceInit(provider.type()));
|
|
||||||
|
|
||||||
final HikariConfig hikariConfig = new HikariConfig();
|
final HikariConfig hikariConfig = new HikariConfig();
|
||||||
hikariConfig.setMaximumPoolSize(20);
|
hikariConfig.setMaximumPoolSize(20);
|
||||||
@@ -193,13 +191,4 @@ public final class MySQLUserManager extends DatabaseUserManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Class<T> forceInit(final Class<T> klass) {
|
|
||||||
try {
|
|
||||||
Class.forName(klass.getName(), true, klass.getClassLoader());
|
|
||||||
} catch (final ClassNotFoundException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
return klass;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-5
@@ -42,6 +42,7 @@ import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
|||||||
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
||||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
|
import net.draycia.carbon.common.util.SQLDrivers;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -156,12 +157,8 @@ public final class PostgreSQLUserManager extends DatabaseUserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PostgreSQLUserManager create() {
|
public PostgreSQLUserManager create() {
|
||||||
try {
|
SQLDrivers.loadFrom(this.getClass().getClassLoader());
|
||||||
Class.forName("org.postgresql.Driver");
|
|
||||||
PluginRegister.REGISTERED_PLUGINS.add(new PostgreSQLDatabaseType());
|
PluginRegister.REGISTERED_PLUGINS.add(new PostgreSQLDatabaseType());
|
||||||
} catch (final ClassNotFoundException exception) {
|
|
||||||
throw new RuntimeException("Could not find required class", exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
final HikariConfig hikariConfig = new HikariConfig();
|
final HikariConfig hikariConfig = new HikariConfig();
|
||||||
hikariConfig.setMaximumPoolSize(20);
|
hikariConfig.setMaximumPoolSize(20);
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* CarbonChat
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Josua Parks (Vicarious)
|
||||||
|
* Contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.draycia.carbon.common.util;
|
||||||
|
|
||||||
|
import java.sql.Driver;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
public final class SQLDrivers {
|
||||||
|
|
||||||
|
private SQLDrivers() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadFrom(final ClassLoader loader) {
|
||||||
|
ServiceLoader.load(Driver.class, loader).stream()
|
||||||
|
.forEach(provider -> forceInit(provider.type()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Class<T> forceInit(final Class<T> klass) {
|
||||||
|
try {
|
||||||
|
Class.forName(klass.getName(), true, klass.getClassLoader());
|
||||||
|
} catch (final ClassNotFoundException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
return klass;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user