Support selecting sql driver at connection time & update dependencies

This commit is contained in:
Govindas 2023-03-30 15:19:23 +03:00
parent cf61d7589b
commit 4124994b83
3 changed files with 16 additions and 9 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.btk5h</groupId> <groupId>com.btk5h</groupId>
<artifactId>skript-db</artifactId> <artifactId>skript-db</artifactId>
<version>1.3.9</version> <version>1.4.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<repositories> <repositories>
@ -28,7 +28,7 @@
</repository> </repository>
<repository> <repository>
<id>sk89q</id> <id>sk89q</id>
<url>http://maven.sk89q.com/repo</url> <url>https://maven.sk89q.com/repo</url>
</repository> </repository>
</repositories> </repositories>
@ -100,14 +100,14 @@
<dependency> <dependency>
<groupId>org.mariadb.jdbc</groupId> <groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId> <artifactId>mariadb-java-client</artifactId>
<version>3.0.9</version> <version>3.1.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.5.1</version> <version>42.6.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>

View File

@ -22,7 +22,7 @@ import java.util.Map;
* *
* @name Data Source * @name Data Source
* @index -1 * @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 * @return datasource
* @example set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false" * @example set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
* @since 0.1.0 * @since 0.1.0
@ -33,11 +33,12 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
static { static {
Skript.registerExpression(ExprDataSource.class, HikariDataSource.class, Skript.registerExpression(ExprDataSource.class, HikariDataSource.class,
ExpressionType.COMBINED, "[the] data(base|[ ]source) [(of|at)] %string% " + 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<String> url; private Expression<String> url;
private Expression<Timespan> maxLifetime; private Expression<Timespan> maxLifetime;
private Expression<String> driver;
@Override @Override
protected HikariDataSource[] get(Event e) { protected HikariDataSource[] get(Event e) {
@ -56,12 +57,17 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
HikariDataSource ds = new HikariDataSource(); HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10)); ds.setMaximumPoolSize(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10));
// 30 minutes by default // 30 minutes by default
ds.setMaxLifetime(SkriptDB.getInstance().getConfig().getInt("max-connection-lifetime", 1800000)); 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.setDriverClassName(SkriptDB.getInstance().getConfig().getString("sql-driver-class-name"));
} }
ds.setJdbcUrl(jdbcUrl); ds.setJdbcUrl(jdbcUrl);
if (maxLifetime != null) { if (maxLifetime != null) {
@ -98,6 +104,7 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
SkriptParser.ParseResult parseResult) { SkriptParser.ParseResult parseResult) {
url = (Expression<String>) exprs[0]; url = (Expression<String>) exprs[0];
maxLifetime = (Expression<Timespan>) exprs[1]; maxLifetime = (Expression<Timespan>) exprs[1];
driver = (Expression<String>) exprs[2];
return true; return true;
} }
} }

View File

@ -1,5 +1,5 @@
name: skript-db name: skript-db
version: 1.3.9 version: 1.4.0
main: com.btk5h.skriptdb.SkriptDB main: com.btk5h.skriptdb.SkriptDB
depend: [Skript] depend: [Skript]
authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL] authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL]