Skip to content

Commit

Permalink
update Hikari and DataSource classes (resolves #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Apr 30, 2021
1 parent 7209ced commit f4492e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.3.1
- update Hikari and DataSource classes

## 3.3.0
- Removed hardcoded parts in additional lore for shop items
- the default items were adapted to include the previously hardcoded lines
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>gamebox</artifactId>
<name>GameBox</name>
<packaging>jar</packaging>
<version>3.3.0</version>
<version>3.3.1</version>
<description>Collection of inventory games</description>
<url>https://gamebox.nikl.me</url>

Expand Down Expand Up @@ -53,7 +53,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.3</version>
<configuration>
<artifactSet>
<includes>
Expand Down Expand Up @@ -217,7 +217,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.3.1</version>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
<!-- SLF4J -->
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/me/nikl/gamebox/data/database/MysqlDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -64,7 +66,7 @@ public MysqlDB(GameBox plugin) {
@Override
public boolean load() {
hikari = new HikariDataSource();
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
hikari.setDataSourceClassName(this.getFirstClassName(Arrays.asList("com.mysql.cj.jdbc.MysqlDataSource", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource", "org.mariadb.jdbc.MariaDbDataSource")).get());
hikari.addDataSourceProperty("serverName", host);
hikari.addDataSourceProperty("port", port);
hikari.addDataSourceProperty("databaseName", database);
Expand Down Expand Up @@ -557,4 +559,17 @@ public List<String> getHighScoreColumnsBeginningWith(String beginningOfColumnNam
public HikariDataSource getHikariDataSource() {
return this.hikari;
}

private Optional<String> getFirstClassName(List<String> classNames) {
for (String name : classNames) {
try {
Class.forName(name);
} catch (ClassNotFoundException e) {
continue;
}

return Optional.of(name);
}
return Optional.empty();
}
}

0 comments on commit f4492e2

Please sign in to comment.