Maybe fix split storage - closes #38
This commit is contained in:
parent
981d745b74
commit
3e846d9527
@ -23,61 +23,33 @@
|
|||||||
package me.lucko.luckperms.common.storage;
|
package me.lucko.luckperms.common.storage;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.data.Log;
|
import me.lucko.luckperms.common.data.Log;
|
||||||
import me.lucko.luckperms.common.groups.Group;
|
import me.lucko.luckperms.common.groups.Group;
|
||||||
|
import me.lucko.luckperms.common.storage.backing.AbstractBacking;
|
||||||
import me.lucko.luckperms.common.tracks.Track;
|
import me.lucko.luckperms.common.tracks.Track;
|
||||||
import me.lucko.luckperms.common.users.User;
|
import me.lucko.luckperms.common.users.User;
|
||||||
import me.lucko.luckperms.common.utils.LPFuture;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SplitBacking implements Datastore {
|
public class SplitBacking extends AbstractBacking {
|
||||||
|
private final Map<String, AbstractBacking> backing;
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean acceptingLogins = false;
|
|
||||||
|
|
||||||
private final LuckPermsPlugin plugin;
|
|
||||||
private final Map<String, Datastore> backing;
|
|
||||||
private final Map<String, String> types;
|
private final Map<String, String> types;
|
||||||
|
|
||||||
protected SplitBacking(LuckPermsPlugin plugin, Map<String, Datastore> backing, Map<String, String> types) {
|
protected SplitBacking(LuckPermsPlugin plugin, Map<String, AbstractBacking> backing, Map<String, String> types) {
|
||||||
this.plugin = plugin;
|
super(plugin, "Split Storage");
|
||||||
this.backing = ImmutableMap.copyOf(backing);
|
this.backing = ImmutableMap.copyOf(backing);
|
||||||
this.types = ImmutableMap.copyOf(types);
|
this.types = ImmutableMap.copyOf(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Split Storage";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doAsync(Runnable r) {
|
|
||||||
plugin.doAsync(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doSync(Runnable r) {
|
|
||||||
plugin.doSync(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Datastore force() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
backing.values().forEach(Datastore::init);
|
backing.values().forEach(AbstractBacking::init);
|
||||||
for (Datastore ds : backing.values()) {
|
for (AbstractBacking ds : backing.values()) {
|
||||||
if (!ds.isAcceptingLogins()) {
|
if (!ds.isAcceptingLogins()) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
@ -88,101 +60,101 @@ public class SplitBacking implements Datastore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
backing.values().forEach(Datastore::shutdown);
|
backing.values().forEach(AbstractBacking::shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> logAction(LogEntry entry) {
|
public boolean logAction(LogEntry entry) {
|
||||||
return backing.get(types.get("log")).logAction(entry);
|
return backing.get(types.get("log")).logAction(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Log> getLog() {
|
public Log getLog() {
|
||||||
return backing.get(types.get("log")).getLog();
|
return backing.get(types.get("log")).getLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> loadUser(UUID uuid, String username) {
|
public boolean loadUser(UUID uuid, String username) {
|
||||||
return backing.get(types.get("user")).loadUser(uuid, username);
|
return backing.get(types.get("user")).loadUser(uuid, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> saveUser(User user) {
|
public boolean saveUser(User user) {
|
||||||
return backing.get(types.get("user")).saveUser(user);
|
return backing.get(types.get("user")).saveUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> cleanupUsers() {
|
public boolean cleanupUsers() {
|
||||||
return backing.get(types.get("user")).cleanupUsers();
|
return backing.get(types.get("user")).cleanupUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Set<UUID>> getUniqueUsers() {
|
public Set<UUID> getUniqueUsers() {
|
||||||
return backing.get(types.get("user")).getUniqueUsers();
|
return backing.get(types.get("user")).getUniqueUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> createAndLoadGroup(String name) {
|
public boolean createAndLoadGroup(String name) {
|
||||||
return backing.get(types.get("group")).createAndLoadGroup(name);
|
return backing.get(types.get("group")).createAndLoadGroup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> loadGroup(String name) {
|
public boolean loadGroup(String name) {
|
||||||
return backing.get(types.get("group")).loadGroup(name);
|
return backing.get(types.get("group")).loadGroup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> loadAllGroups() {
|
public boolean loadAllGroups() {
|
||||||
return backing.get(types.get("group")).loadAllGroups();
|
return backing.get(types.get("group")).loadAllGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> saveGroup(Group group) {
|
public boolean saveGroup(Group group) {
|
||||||
return backing.get(types.get("group")).saveGroup(group);
|
return backing.get(types.get("group")).saveGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> deleteGroup(Group group) {
|
public boolean deleteGroup(Group group) {
|
||||||
return backing.get(types.get("group")).deleteGroup(group);
|
return backing.get(types.get("group")).deleteGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> createAndLoadTrack(String name) {
|
public boolean createAndLoadTrack(String name) {
|
||||||
return backing.get(types.get("track")).createAndLoadTrack(name);
|
return backing.get(types.get("track")).createAndLoadTrack(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> loadTrack(String name) {
|
public boolean loadTrack(String name) {
|
||||||
return backing.get(types.get("track")).loadTrack(name);
|
return backing.get(types.get("track")).loadTrack(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> loadAllTracks() {
|
public boolean loadAllTracks() {
|
||||||
return backing.get(types.get("track")).loadAllTracks();
|
return backing.get(types.get("track")).loadAllTracks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> saveTrack(Track track) {
|
public boolean saveTrack(Track track) {
|
||||||
return backing.get(types.get("track")).saveTrack(track);
|
return backing.get(types.get("track")).saveTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> deleteTrack(Track track) {
|
public boolean deleteTrack(Track track) {
|
||||||
return backing.get(types.get("track")).deleteTrack(track);
|
return backing.get(types.get("track")).deleteTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<Boolean> saveUUIDData(String username, UUID uuid) {
|
public boolean saveUUIDData(String username, UUID uuid) {
|
||||||
return backing.get(types.get("uuid")).saveUUIDData(username, uuid);
|
return backing.get(types.get("uuid")).saveUUIDData(username, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<UUID> getUUID(String username) {
|
public UUID getUUID(String username) {
|
||||||
return backing.get(types.get("uuid")).getUUID(username);
|
return backing.get(types.get("uuid")).getUUID(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPFuture<String> getName(UUID uuid) {
|
public String getName(UUID uuid) {
|
||||||
return backing.get(types.get("uuid")).getName(uuid);
|
return backing.get(types.get("uuid")).getName(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,13 @@ public class StorageFactory {
|
|||||||
Set<String> neededTypes = new HashSet<>();
|
Set<String> neededTypes = new HashSet<>();
|
||||||
neededTypes.addAll(types.values());
|
neededTypes.addAll(types.values());
|
||||||
|
|
||||||
Map<String, Datastore> backing = new HashMap<>();
|
Map<String, AbstractBacking> backing = new HashMap<>();
|
||||||
|
|
||||||
for (String type : neededTypes) {
|
for (String type : neededTypes) {
|
||||||
backing.put(type, fromString(type, plugin));
|
backing.put(type, backingFromString(type, plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
datastore = new SplitBacking(plugin, backing, types);
|
datastore = AbstractDatastore.wrap(plugin, new SplitBacking(plugin, backing, types));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String storageMethod = plugin.getConfiguration().getStorageMethod().toLowerCase();
|
String storageMethod = plugin.getConfiguration().getStorageMethod().toLowerCase();
|
||||||
@ -82,19 +82,23 @@ public class StorageFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) {
|
private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) {
|
||||||
switch (storageMethod) {
|
return AbstractDatastore.wrap(plugin, backingFromString(storageMethod, plugin));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AbstractBacking backingFromString(String method, LuckPermsPlugin plugin) {
|
||||||
|
switch (method) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
return AbstractDatastore.wrap(plugin, new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues()));
|
return new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues());
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
return AbstractDatastore.wrap(plugin, new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite")));
|
return new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite"));
|
||||||
case "h2":
|
case "h2":
|
||||||
return AbstractDatastore.wrap(plugin, new H2Backing(plugin, new File(plugin.getDataFolder(), "luckperms.db")));
|
return new H2Backing(plugin, new File(plugin.getDataFolder(), "luckperms.db"));
|
||||||
case "mongodb":
|
case "mongodb":
|
||||||
return AbstractDatastore.wrap(plugin, new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues()));
|
return new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues());
|
||||||
case "yaml":
|
case "yaml":
|
||||||
return AbstractDatastore.wrap(plugin, new YAMLBacking(plugin, plugin.getDataFolder()));
|
return new YAMLBacking(plugin, plugin.getDataFolder());
|
||||||
default:
|
default:
|
||||||
return AbstractDatastore.wrap(plugin, new JSONBacking(plugin, plugin.getDataFolder()));
|
return new JSONBacking(plugin, plugin.getDataFolder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user