com.zaxxer.hikari.pool.HikariPool Java Examples

The following examples show how to use com.zaxxer.hikari.pool.HikariPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetriableDataSource.java    From Patterdale with Apache License 2.0 5 votes vote down vote up
public static HikariDataSource retriableDataSource(Callable<HikariDataSource> dataSource,
                                                   RuntimeParameters runtimeParams,
                                                   DatabaseDefinition databaseDefinition,
                                                   Logger logger) {
    RetryPolicy retryPolicy = new RetryPolicy()
            .retryOn(HikariPool.PoolInitializationException.class)
            .withDelay(runtimeParams.connectionRetryDelayInSeconds(), SECONDS)
            .withMaxRetries(runtimeParams.maxConnectionRetries());

    return Failsafe.with(retryPolicy)
            .onRetry((result, failure, context) -> logRetry(runtimeParams, databaseDefinition, logger))
            .onFailedAttempt((result, failure, context) -> logFailedAttempt(databaseDefinition, logger))
            .onRetriesExceeded(throwable -> logRetriesExceeded(databaseDefinition, logger))
            .get(dataSource);
}
 
Example #2
Source File: MySQLDB.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Setups the {@link HikariDataSource}
 */
@Override
public void setupDataSource() {
    try {
        loadMySQLDriver();

        HikariConfig hikariConfig = new HikariConfig();

        String host = config.get(DatabaseSettings.MYSQL_HOST);
        String port = config.get(DatabaseSettings.MYSQL_PORT);
        String database = config.get(DatabaseSettings.MYSQL_DATABASE);
        String launchOptions = config.get(DatabaseSettings.MYSQL_LAUNCH_OPTIONS);
        // REGEX: match "?", match "word=word&" *-times, match "word=word"
        if (launchOptions.isEmpty() || !launchOptions.matches("\\?((\\w*=\\w*)&)*(\\w*=\\w*)")) {
            launchOptions = "?rewriteBatchedStatements=true&useSSL=false";
            logger.error(locale.getString(PluginLang.DB_MYSQL_LAUNCH_OPTIONS_FAIL, launchOptions));
        }
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database + launchOptions);

        String username = config.get(DatabaseSettings.MYSQL_USER);
        String password = config.get(DatabaseSettings.MYSQL_PASS);

        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);
        hikariConfig.addDataSourceProperty("connectionInitSql", "set time_zone = '+00:00'");

        hikariConfig.setPoolName("Plan Connection Pool-" + increment);
        increment();

        hikariConfig.setAutoCommit(true);
        hikariConfig.setMaximumPoolSize(8);
        hikariConfig.setMaxLifetime(TimeUnit.MINUTES.toMillis(25L));
        hikariConfig.setLeakDetectionThreshold(TimeUnit.MINUTES.toMillis(10L));

        this.dataSource = new HikariDataSource(hikariConfig);
    } catch (HikariPool.PoolInitializationException e) {
        throw new DBInitException("Failed to set-up HikariCP Datasource: " + e.getMessage(), e);
    }
}