From 3e846d95278523682e6d25be07694e27e5f54343 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 5 Nov 2016 21:43:48 +0000 Subject: [PATCH] Maybe fix split storage - closes #38 --- .../common/storage/SplitBacking.java | 82 ++++++------------- .../common/storage/StorageFactory.java | 24 +++--- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java index 8eb66b39a..0146011a9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java @@ -23,61 +23,33 @@ package me.lucko.luckperms.common.storage; import com.google.common.collect.ImmutableMap; -import lombok.Getter; -import lombok.Setter; import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.data.Log; 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.users.User; -import me.lucko.luckperms.common.utils.LPFuture; import java.util.Map; import java.util.Set; import java.util.UUID; -public class SplitBacking implements Datastore { - - @Getter - @Setter - private boolean acceptingLogins = false; - - private final LuckPermsPlugin plugin; - private final Map backing; +public class SplitBacking extends AbstractBacking { + private final Map backing; private final Map types; - protected SplitBacking(LuckPermsPlugin plugin, Map backing, Map types) { - this.plugin = plugin; + protected SplitBacking(LuckPermsPlugin plugin, Map backing, Map types) { + super(plugin, "Split Storage"); this.backing = ImmutableMap.copyOf(backing); 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 public void init() { boolean success = true; - backing.values().forEach(Datastore::init); - for (Datastore ds : backing.values()) { + backing.values().forEach(AbstractBacking::init); + for (AbstractBacking ds : backing.values()) { if (!ds.isAcceptingLogins()) { success = false; } @@ -88,101 +60,101 @@ public class SplitBacking implements Datastore { @Override public void shutdown() { - backing.values().forEach(Datastore::shutdown); + backing.values().forEach(AbstractBacking::shutdown); } @Override - public LPFuture logAction(LogEntry entry) { + public boolean logAction(LogEntry entry) { return backing.get(types.get("log")).logAction(entry); } @Override - public LPFuture getLog() { + public Log getLog() { return backing.get(types.get("log")).getLog(); } @Override - public LPFuture loadUser(UUID uuid, String username) { + public boolean loadUser(UUID uuid, String username) { return backing.get(types.get("user")).loadUser(uuid, username); } @Override - public LPFuture saveUser(User user) { + public boolean saveUser(User user) { return backing.get(types.get("user")).saveUser(user); } @Override - public LPFuture cleanupUsers() { + public boolean cleanupUsers() { return backing.get(types.get("user")).cleanupUsers(); } @Override - public LPFuture> getUniqueUsers() { + public Set getUniqueUsers() { return backing.get(types.get("user")).getUniqueUsers(); } @Override - public LPFuture createAndLoadGroup(String name) { + public boolean createAndLoadGroup(String name) { return backing.get(types.get("group")).createAndLoadGroup(name); } @Override - public LPFuture loadGroup(String name) { + public boolean loadGroup(String name) { return backing.get(types.get("group")).loadGroup(name); } @Override - public LPFuture loadAllGroups() { + public boolean loadAllGroups() { return backing.get(types.get("group")).loadAllGroups(); } @Override - public LPFuture saveGroup(Group group) { + public boolean saveGroup(Group group) { return backing.get(types.get("group")).saveGroup(group); } @Override - public LPFuture deleteGroup(Group group) { + public boolean deleteGroup(Group group) { return backing.get(types.get("group")).deleteGroup(group); } @Override - public LPFuture createAndLoadTrack(String name) { + public boolean createAndLoadTrack(String name) { return backing.get(types.get("track")).createAndLoadTrack(name); } @Override - public LPFuture loadTrack(String name) { + public boolean loadTrack(String name) { return backing.get(types.get("track")).loadTrack(name); } @Override - public LPFuture loadAllTracks() { + public boolean loadAllTracks() { return backing.get(types.get("track")).loadAllTracks(); } @Override - public LPFuture saveTrack(Track track) { + public boolean saveTrack(Track track) { return backing.get(types.get("track")).saveTrack(track); } @Override - public LPFuture deleteTrack(Track track) { + public boolean deleteTrack(Track track) { return backing.get(types.get("track")).deleteTrack(track); } @Override - public LPFuture saveUUIDData(String username, UUID uuid) { + public boolean saveUUIDData(String username, UUID uuid) { return backing.get(types.get("uuid")).saveUUIDData(username, uuid); } @Override - public LPFuture getUUID(String username) { + public UUID getUUID(String username) { return backing.get(types.get("uuid")).getUUID(username); } @Override - public LPFuture getName(UUID uuid) { + public String getName(UUID uuid) { return backing.get(types.get("uuid")).getName(uuid); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index 982d06dc2..fb531d0dc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -57,13 +57,13 @@ public class StorageFactory { Set neededTypes = new HashSet<>(); neededTypes.addAll(types.values()); - Map backing = new HashMap<>(); + Map backing = new HashMap<>(); 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 { String storageMethod = plugin.getConfiguration().getStorageMethod().toLowerCase(); @@ -82,19 +82,23 @@ public class StorageFactory { } 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": - return AbstractDatastore.wrap(plugin, new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())); + return new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues()); 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": - 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": - return AbstractDatastore.wrap(plugin, new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues())); + return new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues()); case "yaml": - return AbstractDatastore.wrap(plugin, new YAMLBacking(plugin, plugin.getDataFolder())); + return new YAMLBacking(plugin, plugin.getDataFolder()); default: - return AbstractDatastore.wrap(plugin, new JSONBacking(plugin, plugin.getDataFolder())); + return new JSONBacking(plugin, plugin.getDataFolder()); } } }