#450 Port usages of Settings#set(), #setValue() to NewSettings

This commit is contained in:
ljacqu
2016-01-30 15:12:26 +01:00
parent 724296e02b
commit 059175f14e
5 changed files with 73 additions and 76 deletions
@@ -4,32 +4,41 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.SQLite;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.util.StringUtils;
import java.sql.SQLException;
/**
* Mandatory migration from the deprecated flat file datasource to SQLite.
*/
public class ForceFlatToSqlite {
private final DataSource data;
private final DataSource database;
private final NewSetting settings;
public ForceFlatToSqlite(DataSource data) {
this.data = data;
public ForceFlatToSqlite(DataSource database, NewSetting settings) {
this.database = database;
this.settings = settings;
}
public DataSource run() {
DataSource sqlite = null;
try {
sqlite = new SQLite();
for (PlayerAuth auth : data.getAllAuths()) {
DataSource sqlite = new SQLite();
for (PlayerAuth auth : database.getAllAuths()) {
auth.setRealName("Player");
sqlite.saveAuth(auth);
}
Settings.setValue("DataSource.backend", "sqlite");
ConsoleLogger.info("Database successfully converted to sqlite !");
} catch (Exception e) {
ConsoleLogger.showError("An error occurred while trying to convert flatfile to sqlite ...");
return null;
settings.setProperty(DatabaseSettings.BACKEND, DataSource.DataSourceType.SQLITE);
settings.save();
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);
}
return sqlite;
return null;
}
}