Maybe fix split storage - closes #38

This commit is contained in:
Luck 2016-11-05 21:43:48 +00:00
parent 981d745b74
commit 3e846d9527
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 41 additions and 65 deletions

View File

@ -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<String, Datastore> backing;
public class SplitBacking extends AbstractBacking {
private final Map<String, AbstractBacking> backing;
private final Map<String, String> types;
protected SplitBacking(LuckPermsPlugin plugin, Map<String, Datastore> backing, Map<String, String> types) {
this.plugin = plugin;
protected SplitBacking(LuckPermsPlugin plugin, Map<String, AbstractBacking> backing, Map<String, String> 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<Boolean> logAction(LogEntry entry) {
public boolean logAction(LogEntry entry) {
return backing.get(types.get("log")).logAction(entry);
}
@Override
public LPFuture<Log> getLog() {
public Log getLog() {
return backing.get(types.get("log")).getLog();
}
@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);
}
@Override
public LPFuture<Boolean> saveUser(User user) {
public boolean saveUser(User user) {
return backing.get(types.get("user")).saveUser(user);
}
@Override
public LPFuture<Boolean> cleanupUsers() {
public boolean cleanupUsers() {
return backing.get(types.get("user")).cleanupUsers();
}
@Override
public LPFuture<Set<UUID>> getUniqueUsers() {
public Set<UUID> getUniqueUsers() {
return backing.get(types.get("user")).getUniqueUsers();
}
@Override
public LPFuture<Boolean> createAndLoadGroup(String name) {
public boolean createAndLoadGroup(String name) {
return backing.get(types.get("group")).createAndLoadGroup(name);
}
@Override
public LPFuture<Boolean> loadGroup(String name) {
public boolean loadGroup(String name) {
return backing.get(types.get("group")).loadGroup(name);
}
@Override
public LPFuture<Boolean> loadAllGroups() {
public boolean loadAllGroups() {
return backing.get(types.get("group")).loadAllGroups();
}
@Override
public LPFuture<Boolean> saveGroup(Group group) {
public boolean saveGroup(Group group) {
return backing.get(types.get("group")).saveGroup(group);
}
@Override
public LPFuture<Boolean> deleteGroup(Group group) {
public boolean deleteGroup(Group group) {
return backing.get(types.get("group")).deleteGroup(group);
}
@Override
public LPFuture<Boolean> createAndLoadTrack(String name) {
public boolean createAndLoadTrack(String name) {
return backing.get(types.get("track")).createAndLoadTrack(name);
}
@Override
public LPFuture<Boolean> loadTrack(String name) {
public boolean loadTrack(String name) {
return backing.get(types.get("track")).loadTrack(name);
}
@Override
public LPFuture<Boolean> loadAllTracks() {
public boolean loadAllTracks() {
return backing.get(types.get("track")).loadAllTracks();
}
@Override
public LPFuture<Boolean> saveTrack(Track track) {
public boolean saveTrack(Track track) {
return backing.get(types.get("track")).saveTrack(track);
}
@Override
public LPFuture<Boolean> deleteTrack(Track track) {
public boolean deleteTrack(Track track) {
return backing.get(types.get("track")).deleteTrack(track);
}
@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);
}
@Override
public LPFuture<UUID> getUUID(String username) {
public UUID getUUID(String username) {
return backing.get(types.get("uuid")).getUUID(username);
}
@Override
public LPFuture<String> getName(UUID uuid) {
public String getName(UUID uuid) {
return backing.get(types.get("uuid")).getName(uuid);
}
}

View File

@ -57,13 +57,13 @@ public class StorageFactory {
Set<String> neededTypes = new HashSet<>();
neededTypes.addAll(types.values());
Map<String, Datastore> backing = new HashMap<>();
Map<String, AbstractBacking> 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());
}
}
}