From 4124994b83fd17366a7f3f4e3385e30dab97a798 Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 30 Mar 2023 15:19:23 +0300 Subject: [PATCH] Support selecting sql driver at connection time & update dependencies --- pom.xml | 8 ++++---- .../com/btk5h/skriptdb/skript/ExprDataSource.java | 15 +++++++++++---- src/main/resources/plugin.yml | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 2adc114..78da008 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.btk5h skript-db - 1.3.9 + 1.4.0 jar @@ -28,7 +28,7 @@ sk89q - http://maven.sk89q.com/repo + https://maven.sk89q.com/repo @@ -100,14 +100,14 @@ org.mariadb.jdbc mariadb-java-client - 3.0.9 + 3.1.2 compile org.postgresql postgresql - 42.5.1 + 42.6.0 compile diff --git a/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java b/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java index 081e738..945db22 100644 --- a/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java +++ b/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java @@ -22,7 +22,7 @@ import java.util.Map; * * @name Data Source * @index -1 - * @pattern [the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%]" + * @pattern [the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%] [[(using|with)] [a] driver %-string%]" * @return datasource * @example set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false" * @since 0.1.0 @@ -33,11 +33,12 @@ public class ExprDataSource extends SimpleExpression { static { Skript.registerExpression(ExprDataSource.class, HikariDataSource.class, ExpressionType.COMBINED, "[the] data(base|[ ]source) [(of|at)] %string% " + - "[with [a] [max[imum]] [connection] life[ ]time of %-timespan%]"); + "[with [a] [max[imum]] [connection] life[ ]time of %-timespan%] " + "[[(using|with)] [a] driver %-string%]"); } private Expression url; private Expression maxLifetime; + private Expression driver; @Override protected HikariDataSource[] get(Event e) { @@ -56,12 +57,17 @@ public class ExprDataSource extends SimpleExpression { HikariDataSource ds = new HikariDataSource(); ds.setMaximumPoolSize(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10)); + // 30 minutes by default ds.setMaxLifetime(SkriptDB.getInstance().getConfig().getInt("max-connection-lifetime", 1800000)); - //allow specifying of own sql driver class name - if (!SkriptDB.getInstance().getConfig().getString("sql-driver-class-name", "default").equals("default")) { + + // Allow specifying of own sql driver class name + if (driver != null && driver.getSingle(e) != null) { + ds.setDriverClassName(driver.getSingle(e)); + } else if (!SkriptDB.getInstance().getConfig().getString("sql-driver-class-name", "default").equals("default")) { ds.setDriverClassName(SkriptDB.getInstance().getConfig().getString("sql-driver-class-name")); } + ds.setJdbcUrl(jdbcUrl); if (maxLifetime != null) { @@ -98,6 +104,7 @@ public class ExprDataSource extends SimpleExpression { SkriptParser.ParseResult parseResult) { url = (Expression) exprs[0]; maxLifetime = (Expression) exprs[1]; + driver = (Expression) exprs[2]; return true; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 045ac98..36f4ade 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: skript-db -version: 1.3.9 +version: 1.4.0 main: com.btk5h.skriptdb.SkriptDB depend: [Skript] authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL]