mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Add a means to provide a custom Storage dao implementation (#590)
This commit is contained in:
parent
4858e59b70
commit
0eba5f1cbc
@ -50,6 +50,7 @@ public class DependencyRegistry {
|
||||
.put(StorageType.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
|
||||
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
|
||||
.put(StorageType.CUSTOM, ImmutableList.of())
|
||||
.build();
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
@ -42,6 +42,7 @@ import me.lucko.luckperms.common.storage.dao.sql.connection.file.SQLiteConnectio
|
||||
import me.lucko.luckperms.common.storage.dao.sql.connection.hikari.MariaDbConnectionFactory;
|
||||
import me.lucko.luckperms.common.storage.dao.sql.connection.hikari.MySqlConnectionFactory;
|
||||
import me.lucko.luckperms.common.storage.dao.sql.connection.hikari.PostgreConnectionFactory;
|
||||
import me.lucko.luckperms.common.storage.provider.StorageProviders;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.io.File;
|
||||
@ -121,6 +122,8 @@ public class StorageFactory {
|
||||
|
||||
private AbstractDao makeDao(StorageType method) {
|
||||
switch (method) {
|
||||
case CUSTOM:
|
||||
return StorageProviders.getProvider().provide(this.plugin);
|
||||
case MARIADB:
|
||||
return new SqlDao(
|
||||
this.plugin,
|
||||
|
@ -39,7 +39,8 @@ public enum StorageType {
|
||||
MYSQL("MySQL", "mysql"),
|
||||
POSTGRESQL("PostgreSQL", "postgresql"),
|
||||
SQLITE("SQLite", "sqlite"),
|
||||
H2("H2", "h2");
|
||||
H2("H2", "h2"),
|
||||
CUSTOM("Custom", "custom");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.storage.provider;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.storage.dao.AbstractDao;
|
||||
|
||||
/**
|
||||
* A storage provider
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface StorageProvider {
|
||||
|
||||
AbstractDao provide(LuckPermsPlugin plugin);
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.storage.provider;
|
||||
|
||||
public final class StorageProviders {
|
||||
private static StorageProvider provider = null;
|
||||
|
||||
public static void register(StorageProvider provider) {
|
||||
StorageProviders.provider = provider;
|
||||
}
|
||||
|
||||
public static StorageProvider getProvider() {
|
||||
if (provider == null) {
|
||||
throw new IllegalStateException("Provider not present.");
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
private StorageProviders() {}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user