mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-22 23:51:33 +01:00
Merge branch 'mariadb' of https://github.com/HarvelsX/AuthMeReloaded into HarvelsX-mariadb
This commit is contained in:
commit
6d49d798f1
@ -167,4 +167,6 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
return DataSourceValueImpl.unknownRow();
|
||||
}
|
||||
}
|
||||
|
||||
abstract String getJdbcUrl(String host, String port, String database);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ public enum DataSourceType {
|
||||
|
||||
MYSQL,
|
||||
|
||||
MARIADB,
|
||||
|
||||
POSTGRESQL,
|
||||
|
||||
SQLITE
|
||||
|
22
src/main/java/fr/xephi/authme/datasource/MariaDB.java
Normal file
22
src/main/java/fr/xephi/authme/datasource/MariaDB.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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<>();
|
||||
|
@ -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<>();
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user