Skip to content

Commit

Permalink
Update BJSL and add implementation for using MariaDB driver instead o…
Browse files Browse the repository at this point in the history
…f MySQL
  • Loading branch information
Kale-Ko committed Aug 17, 2024
1 parent cea0e51 commit 491d60f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
compileOnly "org.jetbrains:annotations:24.0.1"

runtimeOnly "com.mysql:mysql-connector-j:${project.mysql_connector_version}"
runtimeOnly "org.mariadb.jdbc:mariadb-java-client:${project.mariadb_connector_version}"
}

java {
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ org.gradle.caching=true

java_version=11

project_version=3.10.0
project_version=3.11.0
project_description=An advanced configuration library for Java with support for local files, mysql databases, and more.

bjsl_version=1.10.7
bjsl_version=1.10.8

mysql_connector_version=8.4.0
mysql_connector_version=8.4.0
mariadb_connector_version=3.4.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import org.jetbrains.annotations.Nullable;

/**
* A Structured MySQL Config for storing data on a MySQL server
* A Structured MySQL Config for storing data on a MySQL or MariaDB server
*
* @param <T> The type of the data being stored
*
* @version 3.9.0
* @version 3.11.0
* @since 1.0.0
*/
public class StructuredMySQLConfig<T> extends StructuredConfig<T> {
Expand Down Expand Up @@ -77,6 +77,13 @@ public class StructuredMySQLConfig<T> extends StructuredConfig<T> {
*/
protected final @Nullable String password;

/**
* Weather to use the MariaDB driver
*
* @since 3.11.0
*/
protected final boolean useMariadb;

/**
* The connection to the server
*
Expand Down Expand Up @@ -127,7 +134,7 @@ public class StructuredMySQLConfig<T> extends StructuredConfig<T> {
protected boolean closed = false;

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand All @@ -139,7 +146,7 @@ public class StructuredMySQLConfig<T> extends StructuredConfig<T> {
* @param processor The ObjectProcessor to use for serialization/deserialization
* @param cacheLength How long to cache the config in memory
*
* @since 2.0.0
* @since 3.11.0
*/
public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int port, @NotNull String database, @NotNull String table, @Nullable String username, @Nullable String password, @NotNull ObjectProcessor processor, long cacheLength) {
super(clazz);
Expand All @@ -155,11 +162,13 @@ public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int
this.username = username;
this.password = password;

this.useMariadb = false /*TODO In next release*/;

this.cacheLength = cacheLength;
}

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand All @@ -177,7 +186,7 @@ public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int
}

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand All @@ -194,7 +203,7 @@ public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int
}

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand All @@ -212,7 +221,7 @@ public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int
}

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand All @@ -228,7 +237,7 @@ public StructuredMySQLConfig(@NotNull Class<T> clazz, @NotNull String host, int
}

/**
* Create a new MySQLConfig
* Create a new StructuredMySQLConfig
*
* @param clazz The class of the data being stored
* @param host The host of the server
Expand Down Expand Up @@ -292,7 +301,17 @@ public void connect() throws IOException {
}
}

this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, properties);
try {
if (this.useMariadb) {
Class.forName("org.mariadb.jdbc.Driver");
} else {
Class.forName("com.mysql.cj.jdbc.Driver");
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

this.connection = DriverManager.getConnection("jdbc:" + (this.useMariadb ? "mariadb:" : "mysql:") + "//" + this.host + ":" + this.port + "/" + this.database, properties);

if (this.connection.isValid(3)) {
reconnectAttempts = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jetbrains.annotations.Nullable;

/**
* An Unstructured MySQL Config for storing data on a MySQL server
* An Unstructured MySQL Config for storing data on a MySQL or MariaDB server
*
* @version 3.9.0
* @since 3.0.0
Expand Down Expand Up @@ -64,6 +64,13 @@ public class UnstructuredMySQLConfig extends UnstructuredConfig {
*/
protected final @Nullable String password;

/**
* Weather to use the MariaDB driver
*
* @since 3.11.0
*/
protected final boolean useMariadb;

/**
* The connection to the server
*
Expand Down Expand Up @@ -93,7 +100,7 @@ public class UnstructuredMySQLConfig extends UnstructuredConfig {
protected boolean closed = false;

/**
* Create a new MySQLConfig
* Create a new UnstructuredMySQLConfig
*
* @param host The host of the server
* @param port The port of the server
Expand All @@ -116,10 +123,12 @@ public UnstructuredMySQLConfig(@NotNull String host, int port, @NotNull String d

this.username = username;
this.password = password;

this.useMariadb = false /*TODO In next release*/;
}

/**
* Create a new MySQLConfig
* Create a new UnstructuredMySQLConfig
*
* @param host The host of the server
* @param port The port of the server
Expand All @@ -135,7 +144,7 @@ public UnstructuredMySQLConfig(@NotNull String host, int port, @NotNull String d
}

/**
* Create a new MySQLConfig
* Create a new UnstructuredMySQLConfig
*
* @param host The host of the server
* @param port The port of the server
Expand All @@ -150,7 +159,7 @@ public UnstructuredMySQLConfig(@NotNull String host, int port, @NotNull String d
}

/**
* Create a new MySQLConfig
* Create a new UnstructuredMySQLConfig
*
* @param host The host of the server
* @param port The port of the server
Expand Down Expand Up @@ -352,7 +361,17 @@ public void connect() throws IOException {
}
}

this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, properties);
try {
if (this.useMariadb) {
Class.forName("org.mariadb.jdbc.Driver");
} else {
Class.forName("com.mysql.cj.jdbc.Driver");
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

this.connection = DriverManager.getConnection("jdbc:" + (this.useMariadb ? "mariadb:" : "mysql:") + "//" + this.host + ":" + this.port + "/" + this.database, properties);

if (this.connection.isValid(3)) {
reconnectAttempts = 0;
Expand Down

0 comments on commit 491d60f

Please sign in to comment.