mirror of https://github.com/PikaMug/Quests.git
70 lines
2.7 KiB
Java
70 lines
2.7 KiB
Java
/*
|
|
* Copyright (c) PikaMug and contributors
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
package me.pikamug.quests.storage.implementation.sql.connection.hikari;
|
|
|
|
import com.zaxxer.hikari.HikariConfig;
|
|
import me.pikamug.quests.storage.misc.StorageCredentials;
|
|
|
|
import java.util.Map;
|
|
import java.util.function.Function;
|
|
|
|
public class MySqlConnectionFactory extends HikariConnectionFactory {
|
|
public MySqlConnectionFactory(final StorageCredentials configuration) {
|
|
super(configuration);
|
|
}
|
|
|
|
@Override
|
|
public String getImplementationName() {
|
|
return "MySQL";
|
|
}
|
|
|
|
@Override
|
|
protected String defaultPort() {
|
|
return "3306";
|
|
}
|
|
|
|
@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.Driver");
|
|
config.setJdbcUrl("jdbc:mysql://" + address + ":" + port + "/" + databaseName);
|
|
config.setUsername(username);
|
|
config.setPassword(password);
|
|
}
|
|
|
|
@Override
|
|
protected void overrideProperties(final Map<String, String> properties) {
|
|
// https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
|
|
properties.putIfAbsent("cachePrepStmts", "true");
|
|
properties.putIfAbsent("prepStmtCacheSize", "250");
|
|
properties.putIfAbsent("prepStmtCacheSqlLimit", "2048");
|
|
properties.putIfAbsent("useServerPrepStmts", "true");
|
|
properties.putIfAbsent("useLocalSessionState", "true");
|
|
properties.putIfAbsent("rewriteBatchedStatements", "true");
|
|
properties.putIfAbsent("cacheResultSetMetadata", "true");
|
|
properties.putIfAbsent("cacheServerConfiguration", "true");
|
|
properties.putIfAbsent("elideSetAutoCommits", "true");
|
|
properties.putIfAbsent("maintainTimeStats", "false");
|
|
properties.putIfAbsent("alwaysSendSetIsolation", "false");
|
|
properties.putIfAbsent("cacheCallableStmts", "true");
|
|
|
|
// https://stackoverflow.com/a/54256150
|
|
properties.putIfAbsent("serverTimezone", "UTC");
|
|
|
|
super.overrideProperties(properties);
|
|
}
|
|
|
|
@Override
|
|
public Function<String, String> getStatementProcessor() {
|
|
return s -> s.replace('\'', '`');
|
|
}
|
|
}
|