Wrap column names into class

- Load column names for data sources centrally
- Remove no longer used settings in legacy Settings
This commit is contained in:
ljacqu
2016-02-14 13:25:16 +01:00
parent 6e2528278a
commit 5dc1598f6e
10 changed files with 313 additions and 342 deletions
@@ -1,6 +1,7 @@
package fr.xephi.authme.converter;
/**
* Common supertype for AuthMe converters.
*/
public interface Converter extends Runnable {
}
@@ -26,7 +26,7 @@ public class ForceFlatToSqlite {
public DataSource run() {
try {
DataSource sqlite = new SQLite();
DataSource sqlite = new SQLite(settings);
for (PlayerAuth auth : database.getAllAuths()) {
auth.setRealName("Player");
sqlite.saveAuth(auth);
@@ -36,9 +36,7 @@ public class ForceFlatToSqlite {
ConsoleLogger.info("Database successfully converted to sqlite!");
return sqlite;
} catch (SQLException | ClassNotFoundException e) {
ConsoleLogger.showError("An error occurred while trying to convert flatfile to sqlite: "
+ StringUtils.formatException(e));
ConsoleLogger.writeStackTrace(e);
ConsoleLogger.logException("Could not convert from Flatfile to SQLite:", e);
}
return null;
}
@@ -1,5 +1,6 @@
package fr.xephi.authme.converter;
import fr.xephi.authme.settings.NewSetting;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
@@ -11,29 +12,31 @@ import fr.xephi.authme.output.MessageKey;
public class SqliteToSql implements Converter {
private AuthMe plugin;
private CommandSender sender;
private final AuthMe plugin;
private final CommandSender sender;
private final NewSetting settings;
public SqliteToSql(AuthMe plugin, CommandSender sender) {
this.plugin = plugin;
this.sender = sender;
}
public SqliteToSql(AuthMe plugin, CommandSender sender, NewSetting settings) {
this.plugin = plugin;
this.sender = sender;
this.settings = settings;
}
@Override
public void run() {
if (plugin.getDataSource().getType() != DataSourceType.MYSQL) {
sender.sendMessage("Please config your mySQL connection and re-run this command");
return;
}
try {
SQLite data = new SQLite();
for (PlayerAuth auth : data.getAllAuths()) {
plugin.getDataSource().saveAuth(auth);
}
} catch (Exception e) {
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR));
ConsoleLogger.showError(e.getMessage());
}
}
@Override
public void run() {
if (plugin.getDataSource().getType() != DataSourceType.MYSQL) {
sender.sendMessage("Please configure your mySQL connection and re-run this command");
return;
}
try {
SQLite data = new SQLite(settings);
for (PlayerAuth auth : data.getAllAuths()) {
plugin.getDataSource().saveAuth(auth);
}
} catch (Exception e) {
plugin.getMessages().send(sender, MessageKey.ERROR);
ConsoleLogger.logException("Problem during SQLite to SQL conversion:", e);
}
}
}
@@ -4,8 +4,10 @@ import de.luricos.bukkit.xAuth.database.DatabaseTables;
import de.luricos.bukkit.xAuth.utils.xAuthLog;
import de.luricos.bukkit.xAuth.xAuth;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.util.CollectionUtils;
import org.bukkit.command.CommandSender;
import java.io.File;
@@ -22,12 +24,6 @@ class xAuthToFlat {
private final DataSource database;
private final CommandSender sender;
/**
* Constructor for xAuthToFlat.
*
* @param instance AuthMe
* @param sender CommandSender
*/
public xAuthToFlat(AuthMe instance, CommandSender sender) {
this.instance = instance;
this.database = instance.getDataSource();
@@ -39,12 +35,13 @@ class xAuthToFlat {
sender.sendMessage("[AuthMe] xAuth plugin not found");
return false;
}
if (!(new File(instance.getDataFolder().getParent() + File.separator + "xAuth" + File.separator + "xAuth.h2.db").exists())) {
File xAuthDb = new File(instance.getDataFolder().getParent(), "xAuth" + File.separator + "xAuth.h2.db");
if (!xAuthDb.exists()) {
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
}
List<Integer> players = getXAuthPlayers();
if (players == null || players.isEmpty()) {
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
if (CollectionUtils.isEmpty(players)) {
sender.sendMessage("[AuthMe] Error while importing xAuthPlayers: did not find any players");
return false;
}
sender.sendMessage("[AuthMe] Starting import...");
@@ -59,7 +56,9 @@ class xAuthToFlat {
}
sender.sendMessage("[AuthMe] Successfully converted from xAuth database");
} catch (Exception e) {
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
sender.sendMessage("[AuthMe] An error has occurred while importing the xAuth database."
+ " The import may have succeeded partially.");
ConsoleLogger.logException("Error during xAuth database import", e);
}
return true;
}