diff options
author | Petr Ilin <hevav@hevav.dev> | 2022-12-24 20:19:03 +0300 |
---|---|---|
committer | Petr Ilin <hevav@hevav.dev> | 2022-12-24 20:19:03 +0300 |
commit | 06f2a95f5d8c4eb6cd13656cd6dbb0322c4f3cdc (patch) | |
tree | 5e1588441e1390b695146ebc4ff99c2c9a09557e /src/main/java/net/elytrium/limboauth/LimboAuth.java | |
parent | 8ff7f25c006dd367e1b35e1d13e105900b7c3d60 (diff) | |
download | LimboAuth-06f2a95f5d8c4eb6cd13656cd6dbb0322c4f3cdc.tar.gz LimboAuth-06f2a95f5d8c4eb6cd13656cd6dbb0322c4f3cdc.tar.bz2 LimboAuth-06f2a95f5d8c4eb6cd13656cd6dbb0322c4f3cdc.zip |
H2 v1->v2 migration, external database libraries
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/LimboAuth.java')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/LimboAuth.java | 49 |
1 files changed, 12 insertions, 37 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index a42322a..46b0864 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -26,8 +26,8 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.dao.GenericRawResults; import com.j256.ormlite.db.DatabaseType; import com.j256.ormlite.field.FieldType; -import com.j256.ormlite.jdbc.JdbcPooledConnectionSource; import com.j256.ormlite.stmt.QueryBuilder; +import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableInfo; import com.j256.ormlite.table.TableUtils; import com.velocitypowered.api.command.CommandManager; @@ -90,6 +90,7 @@ import net.elytrium.limboauth.command.LimboAuthCommand; import net.elytrium.limboauth.command.PremiumCommand; import net.elytrium.limboauth.command.TotpCommand; import net.elytrium.limboauth.command.UnregisterCommand; +import net.elytrium.limboauth.dependencies.DatabaseLibrary; import net.elytrium.limboauth.event.AuthPluginReloadEvent; import net.elytrium.limboauth.event.PreAuthorizationEvent; import net.elytrium.limboauth.event.PreEvent; @@ -158,7 +159,7 @@ public class LimboAuth { private ScheduledTask purgeCacheTask; private ScheduledTask purgePremiumCacheTask; - private JdbcPooledConnectionSource connectionSource; + private ConnectionSource connectionSource; private Dao<RegisteredPlayer, String> playerDao; private Pattern nicknameValidationPattern; private Limbo authServer; @@ -267,29 +268,14 @@ public class LimboAuth { this.cachedAuthChecks.clear(); Settings.DATABASE dbConfig = Settings.IMP.DATABASE; - switch (dbConfig.STORAGE_TYPE.toLowerCase(Locale.ROOT)) { - case "h2": { - this.connectionSource = new JdbcPooledConnectionSource("jdbc:h2:" + this.dataDirectoryFile.getAbsoluteFile() + "/limboauth"); - break; - } - case "mysql": { - this.connectionSource = new JdbcPooledConnectionSource( - "jdbc:mysql://" + dbConfig.HOSTNAME + "/" + dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS, dbConfig.USER, dbConfig.PASSWORD - ); - break; - } - case "postgresql": { - this.connectionSource = new JdbcPooledConnectionSource( - "jdbc:postgresql://" + dbConfig.HOSTNAME + "/" + dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS, dbConfig.USER, dbConfig.PASSWORD - ); - break; - } - default: { - LOGGER.error("Wrong database type."); - this.server.shutdown(); - return; - } - } + DatabaseLibrary databaseLibrary = DatabaseLibrary.valueOf(dbConfig.STORAGE_TYPE.toUpperCase(Locale.ROOT)); + this.connectionSource = databaseLibrary.connectToORM( + this.dataDirectoryFile.toPath().toAbsolutePath(), + dbConfig.HOSTNAME, + dbConfig.DATABASE + dbConfig.CONNECTION_PARAMETERS, + dbConfig.USER, + dbConfig.PASSWORD + ); this.nicknameValidationPattern = Pattern.compile(Settings.IMP.MAIN.ALLOWED_NICKNAME_REGEX); @@ -789,7 +775,7 @@ public class LimboAuth { return this.server; } - public JdbcPooledConnectionSource getConnectionSource() { + public ConnectionSource getConnectionSource() { return this.connectionSource; } @@ -797,17 +783,6 @@ public class LimboAuth { return this.playerDao; } - static { - // requireNonNull prevents the shade plugin from excluding the drivers in minimized jar. - Objects.requireNonNull(com.mysql.cj.jdbc.Driver.class); - Objects.requireNonNull(com.mysql.cj.conf.url.SingleConnectionUrl.class); - - Objects.requireNonNull(org.h2.Driver.class); - Objects.requireNonNull(org.h2.engine.Engine.class); - - Objects.requireNonNull(org.postgresql.Driver.class); - } - private static void setLogger(Logger logger) { LOGGER = logger; } |