mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-08 09:27:56 +01:00
Add optional MySQL implementation, part 2. See #312
This commit is contained in:
parent
31da631295
commit
7df3da82b3
26
main/pom.xml
26
main/pom.xml
@ -132,6 +132,12 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.22</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
@ -208,7 +214,7 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
@ -218,8 +224,26 @@
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>me.*</include>
|
||||
<include>com.zaxxer:HikariCP</include>
|
||||
<include>org.slf4j:slf4j-simple</include>
|
||||
<include>org.slf4j:slf4j-api</include>
|
||||
<include>mysql</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>me.blackvein.quests.libs.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>me.blackvein.quests.libs.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.mysql</pattern>
|
||||
<shadedPattern>me.blackvein.quests.libs.mysql</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -244,6 +244,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
final Quester quester = getQuester(p.getUniqueId());
|
||||
quester.saveData();
|
||||
}
|
||||
getLogger().info("Closing storage...");
|
||||
storage.close();
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
|
@ -15,6 +15,8 @@ package me.blackvein.quests.storage.implementation.sql;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -62,6 +64,29 @@ public class SqlStorage implements StorageImplementation {
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
connectionFactory.init(plugin);
|
||||
|
||||
try (Connection c = connectionFactory.getConnection()) {
|
||||
final String createStatement = "CREATE TABLE IF NOT EXISTS `" + getTableName()
|
||||
+ "` (`uuid` VARCHAR(36) NOT NULL, "
|
||||
+ "`hasjournal` BOOL NOT NULL, "
|
||||
+ "PRIMARY KEY (`uuid`)"
|
||||
+ ") DEFAULT CHARSET = utf8mb4";
|
||||
try (Statement s = c.createStatement()) {
|
||||
try {
|
||||
s.execute(createStatement);
|
||||
} catch (final SQLException e) {
|
||||
if (e.getMessage().contains("Unknown character set")) {
|
||||
s.execute(createStatement.replace("utf8mb4", "utf8"));
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getTableName() {
|
||||
return this.statementProcessor.apply("{prefix}players");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,7 +37,7 @@ public class MySqlConnectionFactory extends HikariConnectionFactory {
|
||||
@Override
|
||||
protected void configureDatabase(final HikariConfig config, final String address, final String port,
|
||||
final String databaseName, final String username, final String password) {
|
||||
config.setDriverClassName("com.mysql.cj.jdbc.NonRegisteringDriver");
|
||||
config.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
config.setJdbcUrl("jdbc:mysql://" + address + ":" + port + "/" + databaseName);
|
||||
config.setUsername(username);
|
||||
config.setPassword(password);
|
||||
|
Loading…
Reference in New Issue
Block a user