From ed4200b23f82216c77873f72bc04b9119e48552d Mon Sep 17 00:00:00 2001 From: HarvelsX <90945793+HarvelsX@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:12:44 +0300 Subject: [PATCH 1/2] Fix column check: https://github.com/AuthMe/AuthMeReloaded/issues/2543; --- src/main/java/fr/xephi/authme/datasource/MySQL.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 465084a11..5eb188788 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -299,7 +299,7 @@ public class MySQL extends AbstractSqlDataSource { } private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException { - try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) { + try (ResultSet rs = metaData.getColumns(database, null, tableName, columnName)) { return !rs.next(); } } @@ -348,6 +348,11 @@ public class MySQL extends AbstractSqlDataSource { return false; } + @Override + String getJdbcUrl(String host, String port, String database) { + return "jdbc:mysql://" + host + ":" + port + "/" + database; + } + @Override public Set getRecordsToPurge(long until) { Set list = new HashSet<>(); From a9898fd806a37413691dc89c05153cf30040c30d Mon Sep 17 00:00:00 2001 From: HarvelsX <90945793+HarvelsX@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:13:46 +0300 Subject: [PATCH 2/2] Add support MariaDB driver: https://github.com/AuthMe/AuthMeReloaded/issues/2556; --- .../datasource/AbstractSqlDataSource.java | 2 ++ .../authme/datasource/DataSourceType.java | 2 ++ .../fr/xephi/authme/datasource/MariaDB.java | 22 +++++++++++++++++++ .../fr/xephi/authme/datasource/MySQL.java | 2 +- .../datasource/PostgreSqlDataSource.java | 7 +++++- .../fr/xephi/authme/datasource/SQLite.java | 7 +++++- .../initialization/DataSourceProvider.java | 4 ++++ 7 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/datasource/MariaDB.java diff --git a/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java b/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java index 067851684..6c12a1710 100644 --- a/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java @@ -167,4 +167,6 @@ public abstract class AbstractSqlDataSource implements DataSource { return DataSourceValueImpl.unknownRow(); } } + + abstract String getJdbcUrl(String host, String port, String database); } diff --git a/src/main/java/fr/xephi/authme/datasource/DataSourceType.java b/src/main/java/fr/xephi/authme/datasource/DataSourceType.java index d9969ac95..841542a51 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSourceType.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSourceType.java @@ -7,6 +7,8 @@ public enum DataSourceType { MYSQL, + MARIADB, + POSTGRESQL, SQLITE diff --git a/src/main/java/fr/xephi/authme/datasource/MariaDB.java b/src/main/java/fr/xephi/authme/datasource/MariaDB.java new file mode 100644 index 000000000..e6e26c1ce --- /dev/null +++ b/src/main/java/fr/xephi/authme/datasource/MariaDB.java @@ -0,0 +1,22 @@ +package fr.xephi.authme.datasource; + +import fr.xephi.authme.datasource.mysqlextensions.MySqlExtensionsFactory; +import fr.xephi.authme.settings.Settings; + +import java.sql.SQLException; + +public class MariaDB extends MySQL { + public MariaDB(Settings settings, MySqlExtensionsFactory extensionsFactory) throws SQLException { + super(settings, extensionsFactory); + } + + @Override + String getJdbcUrl(String host, String port, String database) { + return "jdbc:mariadb://" + host + ":" + port + "/" + database; + } + + @Override + public DataSourceType getType() { + return DataSourceType.MARIADB; + } +} diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 5eb188788..2f524704e 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -134,7 +134,7 @@ public class MySQL extends AbstractSqlDataSource { ds.setMaxLifetime(maxLifetime * 1000L); // Database URL - ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); + ds.setJdbcUrl(this.getJdbcUrl(this.host, this.port, this.database)); // Auth ds.setUsername(this.username); diff --git a/src/main/java/fr/xephi/authme/datasource/PostgreSqlDataSource.java b/src/main/java/fr/xephi/authme/datasource/PostgreSqlDataSource.java index b0186f4b7..070c719a5 100644 --- a/src/main/java/fr/xephi/authme/datasource/PostgreSqlDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/PostgreSqlDataSource.java @@ -119,7 +119,7 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource { // Database URL ds.setDriverClassName("org.postgresql.Driver"); - ds.setJdbcUrl("jdbc:postgresql://" + this.host + ":" + this.port + "/" + this.database); + ds.setJdbcUrl(this.getJdbcUrl(this.host, this.port, this.database)); // Auth ds.setUsername(this.username); @@ -306,6 +306,11 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource { return false; } + @Override + String getJdbcUrl(String host, String port, String database) { + return "jdbc:postgresql://" + host + ":" + port + "/" + database; + } + @Override public Set getRecordsToPurge(long until) { Set list = new HashSet<>(); diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 24b8b9462..966508082 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -88,7 +88,7 @@ public class SQLite extends AbstractSqlDataSource { } logger.debug("SQLite driver loaded"); - this.con = DriverManager.getConnection("jdbc:sqlite:" + this.dataFolder + File.separator + database + ".db"); + this.con = DriverManager.getConnection(this.getJdbcUrl(this.dataFolder.getAbsolutePath(), "", this.database)); this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings); } @@ -405,6 +405,11 @@ public class SQLite extends AbstractSqlDataSource { + currentTimestamp + ", to all " + updatedRows + " rows"); } + @Override + String getJdbcUrl(String dataPath, String ignored, String database) { + return "jdbc:sqlite:" + dataPath + File.separator + database + ".db"; + } + private static void close(Connection con) { if (con != null) { try { diff --git a/src/main/java/fr/xephi/authme/initialization/DataSourceProvider.java b/src/main/java/fr/xephi/authme/initialization/DataSourceProvider.java index 857a795a9..de5eea463 100644 --- a/src/main/java/fr/xephi/authme/initialization/DataSourceProvider.java +++ b/src/main/java/fr/xephi/authme/initialization/DataSourceProvider.java @@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; +import fr.xephi.authme.datasource.MariaDB; import fr.xephi.authme.datasource.MySQL; import fr.xephi.authme.datasource.PostgreSqlDataSource; import fr.xephi.authme.datasource.SQLite; @@ -66,6 +67,9 @@ public class DataSourceProvider implements Provider { case MYSQL: dataSource = new MySQL(settings, mySqlExtensionsFactory); break; + case MARIADB: + dataSource = new MariaDB(settings, mySqlExtensionsFactory); + break; case POSTGRESQL: dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory); break;