Skip to content

Commit

Permalink
Add support MariaDB driver: AuthMe#2556;
Browse files Browse the repository at this point in the history
  • Loading branch information
HarvelsX committed Jul 25, 2022
1 parent ed4200b commit a9898fd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,6 @@ public DataSourceValue<String> getEmail(String user) {
return DataSourceValueImpl.unknownRow();
}
}

abstract String getJdbcUrl(String host, String port, String database);
}
2 changes: 2 additions & 0 deletions src/main/java/fr/xephi/authme/datasource/DataSourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum DataSourceType {

MYSQL,

MARIADB,

POSTGRESQL,

SQLITE
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/fr/xephi/authme/datasource/MariaDB.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/fr/xephi/authme/datasource/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void setConnectionArguments() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void setConnectionArguments() {

// 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);
Expand Down Expand Up @@ -306,6 +306,11 @@ public boolean saveAuth(PlayerAuth auth) {
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<>();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/fr/xephi/authme/datasource/SQLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void connect() throws SQLException {
}

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

Expand Down Expand Up @@ -405,6 +405,11 @@ private void addRegistrationDateColumn(Statement st) throws SQLException {
+ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -66,6 +67,9 @@ private DataSource createDataSource() throws SQLException {
case MYSQL:
dataSource = new MySQL(settings, mySqlExtensionsFactory);
break;
case MARIADB:
dataSource = new MariaDB(settings, mySqlExtensionsFactory);
break;
case POSTGRESQL:
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
break;
Expand Down

0 comments on commit a9898fd

Please sign in to comment.