Fix using UTF-8 characters with MySQL - closes #129

This commit is contained in:
Luck 2017-01-22 12:19:29 +00:00
parent d39dad3287
commit c03585aeca
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 3 additions and 64 deletions

View File

@ -71,6 +71,8 @@ public class MySQLProvider extends SQLProvider {
config.addDataSourceProperty("cacheServerConfiguration", true);
config.addDataSourceProperty("elideSetAutoCommits", true);
config.addDataSourceProperty("useLocalSessionState", true);
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("useUnicode", "true");
config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10)); // 10000
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(5)); // 5000
config.setValidationTimeout(TimeUnit.SECONDS.toMillis(3)); // 3000

View File

@ -25,14 +25,10 @@ package me.lucko.luckperms.common.storage.backing.sqlprovider;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@RequiredArgsConstructor
public abstract class SQLProvider {
private static final QueryPS EMPTY_PS = preparedStatement -> {};
@Getter
private final String name;
@ -43,63 +39,4 @@ public abstract class SQLProvider {
public abstract WrappedConnection getConnection() throws SQLException;
public boolean runQuery(String query, QueryPS queryPS) {
try {
try (Connection connection = getConnection()) {
if (connection == null || connection.isClosed()) {
throw new IllegalStateException("SQL connection is null");
}
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
queryPS.onRun(preparedStatement);
preparedStatement.execute();
return true;
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean runQuery(String query, QueryPS queryPS, QueryRS queryRS) {
try {
try (Connection connection = getConnection()) {
if (connection == null || connection.isClosed()) {
throw new IllegalStateException("SQL connection is null");
}
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
queryPS.onRun(preparedStatement);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
return queryRS.onResult(resultSet);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean runQuery(String query) {
return runQuery(query, EMPTY_PS);
}
public boolean runQuery(String query, QueryRS queryRS) {
return runQuery(query, EMPTY_PS, queryRS);
}
@FunctionalInterface
public interface QueryPS {
void onRun(PreparedStatement preparedStatement) throws SQLException;
}
@FunctionalInterface
public interface QueryRS {
boolean onResult(ResultSet resultSet) throws SQLException;
}
}

View File

@ -39,7 +39,7 @@ CREATE INDEX `{prefix}players_username` ON `{prefix}players` (`username`);
CREATE TABLE `{prefix}groups` (
`name` VARCHAR(36) NOT NULL,
PRIMARY KEY (`name`)
);
) DEFAULT CHARSET = utf8;
CREATE TABLE `{prefix}actions` (
`id` INT AUTO_INCREMENT NOT NULL,