Merge branch 'mariadb' of https://github.com/HarvelsX/AuthMeReloaded into HarvelsX-mariadb

This commit is contained in:
Gabriele C 2022-07-28 17:46:57 +02:00
commit 6d49d798f1
7 changed files with 49 additions and 4 deletions

View File

@ -167,4 +167,6 @@ public abstract class AbstractSqlDataSource implements DataSource {
return DataSourceValueImpl.unknownRow();
}
}
abstract String getJdbcUrl(String host, String port, String database);
}

View File

@ -7,6 +7,8 @@ public enum DataSourceType {
MYSQL,
MARIADB,
POSTGRESQL,
SQLITE

View File

@ -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;
}
}

View File

@ -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);
@ -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<String> getRecordsToPurge(long until) {
Set<String> list = new HashSet<>();

View File

@ -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<String> getRecordsToPurge(long until) {
Set<String> list = new HashSet<>();

View File

@ -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 {

View File

@ -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<DataSource> {
case MYSQL:
dataSource = new MySQL(settings, mySqlExtensionsFactory);
break;
case MARIADB:
dataSource = new MariaDB(settings, mySqlExtensionsFactory);
break;
case POSTGRESQL:
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
break;