Add missing "MARIADB" datasource backend to the configuration file, remove "mySQLDriverClassName" property as it is no longer needed.

This commit is contained in:
Gabriele C
2022-07-28 18:11:57 +02:00
parent 6d49d798f1
commit 24d03aa1e2
5 changed files with 25 additions and 31 deletions
@@ -15,6 +15,11 @@ public class MariaDB extends MySQL {
return "jdbc:mariadb://" + host + ":" + port + "/" + database;
}
@Override
protected String getDriverClassName() {
return "org.mariadb.jdbc.Driver";
}
@Override
public DataSourceType getType() {
return DataSourceType.MARIADB;
@@ -44,7 +44,6 @@ public class MySQL extends AbstractSqlDataSource {
private String port;
private String username;
private String password;
private String className;
private String database;
private String tableName;
private int poolSize;
@@ -90,6 +89,15 @@ public class MySQL extends AbstractSqlDataSource {
setParameters(settings, extensionsFactory);
}
/**
* Returns the path of the Driver class to use when connecting to the database.
*
* @return the dotted path of the SQL driver class to be used
*/
protected String getDriverClassName() {
return "com.mysql.cj.jdbc.Driver";
}
/**
* Retrieves various settings.
*
@@ -101,14 +109,6 @@ public class MySQL extends AbstractSqlDataSource {
this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT);
this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME);
this.password = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD);
this.className = settings.getProperty(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME);
try {
Class.forName(this.className);
} catch (ClassNotFoundException e) {
this.className = DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getDefaultValue();
logger.info("Driver class '" + this.className + "' not found! Falling back to the built-in MySQL driver ("
+ this.className + ")");
}
this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS);
@@ -141,7 +141,7 @@ public class MySQL extends AbstractSqlDataSource {
ds.setPassword(this.password);
// Driver
ds.setDriverClassName(this.className);
ds.setDriverClassName(this.getDriverClassName());
// Request mysql over SSL
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
@@ -6,6 +6,7 @@ import ch.jalu.configme.properties.Property;
import ch.jalu.configme.properties.convertresult.PropertyValue;
import ch.jalu.configme.resource.PropertyReader;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSourceType;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.output.LogLevel;
@@ -65,10 +66,10 @@ public class SettingsMigrationService extends PlainMigrationService {
configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*");
changes = true;
}
String driverClass = reader.getString(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getPath());
if ("com.mysql.jdbc.Driver".equals(driverClass) || "com.mysql.cj.jdbc.Driver".equals(driverClass)) {
configurationData.setValue(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME,
DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getDefaultValue());
String driverClass = reader.getString("DataSource.mySQLDriverClassName");
if ("fr.xephi.authme.libs.org.mariadb.jdbc.Driver".equals(driverClass)) {
configurationData.setValue(DatabaseSettings.BACKEND, DataSourceType.MARIADB);
changes = true;
}
@@ -100,7 +101,7 @@ public class SettingsMigrationService extends PlainMigrationService {
"settings.restrictions.keepCollisionsDisabled", "settings.forceCommands", "settings.forceCommandsAsConsole",
"settings.forceRegisterCommands", "settings.forceRegisterCommandsAsConsole",
"settings.sessions.sessionExpireOnIpChange", "settings.restrictions.otherAccountsCmd",
"settings.restrictions.otherAccountsCmdThreshold"};
"settings.restrictions.otherAccountsCmdThreshold, DataSource.mySQLDriverClassName"};
for (String deprecatedPath : deprecatedProperties) {
if (reader.contains(deprecatedPath)) {
return true;
@@ -10,7 +10,7 @@ import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
public final class DatabaseSettings implements SettingsHolder {
@Comment({"What type of database do you want to use?",
"Valid values: SQLITE, MYSQL, POSTGRESQL"})
"Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL"})
public static final Property<DataSourceType> BACKEND =
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
@@ -49,13 +49,6 @@ public final class DatabaseSettings implements SettingsHolder {
@Comment("Password to connect to the MySQL database")
public static final Property<String> MYSQL_PASSWORD =
newProperty("DataSource.mySQLPassword", "12345");
@Comment({"Driver Name of the MySQL database.",
"Built-in drivers:",
" MySQL: 'fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver'",
" MariaDB: 'fr.xephi.authme.libs.org.mariadb.jdbc.Driver'"})
public static final Property<String> MYSQL_DRIVER_CLASS_NAME =
newProperty("DataSource.mySQLDriverClassName", "fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver");
@Comment("Database Name, use with converters or as SQLITE database name")
public static final Property<String> MYSQL_DATABASE =