mirror of https://github.com/PikaMug/Quests.git
73 lines
3.0 KiB
Java
73 lines
3.0 KiB
Java
/*
|
|
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
package me.blackvein.quests.storage.implementation.sql.connection.hikari;
|
|
|
|
import java.util.Map;
|
|
import java.util.function.Function;
|
|
|
|
import com.zaxxer.hikari.HikariConfig;
|
|
|
|
import me.blackvein.quests.storage.misc.StorageCredentials;
|
|
|
|
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('\'', '`');
|
|
}
|
|
}
|