Add a means to provide a custom Storage dao implementation (#590)

This commit is contained in:
Luck 2018-01-22 23:21:47 +00:00
parent 4858e59b70
commit 0eba5f1cbc
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 90 additions and 1 deletions

View File

@ -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.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER)) .put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER)) .put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
.put(StorageType.CUSTOM, ImmutableList.of())
.build(); .build();
private final LuckPermsPlugin plugin; private final LuckPermsPlugin plugin;

View File

@ -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.MariaDbConnectionFactory;
import me.lucko.luckperms.common.storage.dao.sql.connection.hikari.MySqlConnectionFactory; 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.dao.sql.connection.hikari.PostgreConnectionFactory;
import me.lucko.luckperms.common.storage.provider.StorageProviders;
import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.io.File; import java.io.File;
@ -121,6 +122,8 @@ public class StorageFactory {
private AbstractDao makeDao(StorageType method) { private AbstractDao makeDao(StorageType method) {
switch (method) { switch (method) {
case CUSTOM:
return StorageProviders.getProvider().provide(this.plugin);
case MARIADB: case MARIADB:
return new SqlDao( return new SqlDao(
this.plugin, this.plugin,

View File

@ -39,7 +39,8 @@ public enum StorageType {
MYSQL("MySQL", "mysql"), MYSQL("MySQL", "mysql"),
POSTGRESQL("PostgreSQL", "postgresql"), POSTGRESQL("PostgreSQL", "postgresql"),
SQLITE("SQLite", "sqlite"), SQLITE("SQLite", "sqlite"),
H2("H2", "h2"); H2("H2", "h2"),
CUSTOM("Custom", "custom");
private final String name; private final String name;

View File

@ -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);
}

View File

@ -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() {}
}