
br.com.objectos.db.mysql.MysqlVendor Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014-2015 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.db.mysql;
import br.com.objectos.db.core.DatabaseConfig;
import br.com.objectos.db.core.Vendor;
import com.zaxxer.hikari.HikariConfig;
/**
* @author [email protected] (Marcio Endo)
*/
final class MysqlVendor extends Vendor {
private static final MysqlVendor INSTANCE = new MysqlVendor();
private MysqlVendor() {
}
public static MysqlVendor get() {
return INSTANCE;
}
@Override
protected String catalogName(String dbName) {
return dbName;
}
@Override
protected void configure(DatabaseConfig config, HikariConfig hk) {
hk.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
hk.addDataSourceProperty("url", url(config));
hk.addDataSourceProperty("user", config.user());
hk.addDataSourceProperty("password", config.password());
hk.setInitializationFailFast(false);
hk.setMinimumIdle(0);
hk.setMaximumPoolSize(50);
hk.addDataSourceProperty("cachePrepStmts", true);
hk.addDataSourceProperty("prepStmtCacheSize", 250);
hk.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
hk.addDataSourceProperty("rewriteBatchedStatements", true);
hk.addDataSourceProperty("useServerPrepStmts", true);
}
@Override
protected String driverClassName() {
return "com.mysql.jdbc.Driver";
}
@Override
protected String urlFormat() {
return "jdbc:mysql://%s:%d";
}
private String url(DatabaseConfig config) {
String server = config.server();
int port = config.port();
String db = config.db();
return String.format("jdbc:mysql://%s:%d/%s", server, port, db);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy