com.zaxxer.hikari.HikariConfig Java Examples

The following examples show how to use com.zaxxer.hikari.HikariConfig. 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: TestDataConfig.java    From Spring with Apache License 2.0 7 votes vote down vote up
@Bean
public DataSource dataSource() {
    try {
        final HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName(driverClassName);
        hikariConfig.setJdbcUrl(url);
        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);

        hikariConfig.setMaximumPoolSize(5);
        hikariConfig.setConnectionTestQuery("SELECT 1");
        hikariConfig.setPoolName("springHikariCP");

        hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048");
        hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true");

        return new HikariDataSource(hikariConfig);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #2
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 7 votes vote down vote up
@Bean
public DataSource dataSource() throws SQLException {
    DatabaseUtil.createSchemaIfNeeded("postgresql", databaseAddress, dbName, dbUser, dbPassword, dbSchemaName);
    HikariConfig config = new HikariConfig();
    if (ssl && Files.exists(Paths.get(certFile))) {
        config.addDataSourceProperty("ssl", "true");
        config.addDataSourceProperty("sslfactory", "org.postgresql.ssl.SingleCertValidatingFactory");
        config.addDataSourceProperty("sslfactoryarg", "file://" + certFile);
    }
    if (nodeConfig.isNodeIdSpecified()) {
        config.addDataSourceProperty("ApplicationName", nodeConfig.getId());
    }
    config.setDriverClassName("io.opentracing.contrib.jdbc.TracingDriver");
    config.setJdbcUrl(String.format("jdbc:tracing:postgresql://%s/%s?currentSchema=%s", databaseAddress, dbName, dbSchemaName));
    config.setUsername(dbUser);
    config.setPassword(dbPassword);
    config.setMaximumPoolSize(poolSize);
    config.setMinimumIdle(minimumIdle);
    config.setConnectionTimeout(SECONDS.toMillis(connectionTimeout));
    config.setIdleTimeout(MINUTES.toMillis(idleTimeout));
    return new HikariDataSource(config);
}
 
Example #3
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean
public DataSource dataSource() throws SQLException {
    DatabaseUtil.createSchemaIfNeeded("postgresql", databaseAddress, dbName, dbUser, dbPassword, dbSchemaName);
    HikariConfig config = new HikariConfig();
    if (ssl && Files.exists(Paths.get(certFile))) {
        config.addDataSourceProperty("ssl", "true");
        config.addDataSourceProperty("sslfactory", "org.postgresql.ssl.SingleCertValidatingFactory");
        config.addDataSourceProperty("sslfactoryarg", "file://" + certFile);
    }
    if (nodeConfig.isNodeIdSpecified()) {
        config.addDataSourceProperty("ApplicationName", nodeConfig.getId());
    }
    config.setDriverClassName("io.opentracing.contrib.jdbc.TracingDriver");
    config.setJdbcUrl(String.format("jdbc:tracing:postgresql://%s/%s?currentSchema=%s", databaseAddress, dbName, dbSchemaName));
    config.setUsername(dbUser);
    config.setPassword(dbPassword);
    config.setMaximumPoolSize(poolSize);
    config.setMinimumIdle(minimumIdle);
    config.setConnectionTimeout(SECONDS.toMillis(connectionTimeout));
    config.setIdleTimeout(MINUTES.toMillis(idleTimeout));
    return new HikariDataSource(config);
}
 
Example #4
Source File: DataSourceConfig.java    From momo-cloud-permission with Apache License 2.0 6 votes vote down vote up
@Bean(name = "primaryDataSource")
    @Primary
//    @ConfigurationProperties(prefix = "spring.datasource")
    public HikariDataSource dataSource() {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName(hikariDattaSourceConfig.getDriverClassName());
        hikariConfig.setJdbcUrl(hikariDattaSourceConfig.getJdbcUrl());
        hikariConfig.setUsername(hikariDattaSourceConfig.getUsername());
        hikariConfig.setPassword(hikariDattaSourceConfig.getPassword());
        hikariConfig.setMaxLifetime(hikariDattaSourceConfig.getMaxlifetime());
        hikariConfig.setConnectionTestQuery(hikariDattaSourceConfig.getConnectionTestQuery());
        hikariConfig.setPoolName(hikariDattaSourceConfig.getPoolName());
        hikariConfig.setIdleTimeout(hikariDattaSourceConfig.getIdleTimeout());
        hikariConfig.setAutoCommit(true);
        hikariConfig.setConnectionTimeout(hikariDattaSourceConfig.getConnectionTimeout());
        hikariConfig.setMinimumIdle(hikariDattaSourceConfig.getMinimumTdle());
        hikariConfig.setMaximumPoolSize(hikariDattaSourceConfig.getMaximumPoolSize());
        hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048");
        hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true");
        return new HikariDataSource(hikariConfig);
    }
 
Example #5
Source File: PipelineMavenPluginPostgreSqlDaoIT.java    From pipeline-maven-plugin with MIT License 6 votes vote down vote up
@Override
public DataSource before_newDataSource() throws Exception {

    Class.forName("org.postgresql.Driver");

    HikariConfig config = new HikariConfig();
    String configurationFilePath = ".postgresql_config";
    InputStream propertiesInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationFilePath);

    Properties properties = new Properties();
    if (propertiesInputStream == null) {
        throw new IllegalArgumentException("Config file " + configurationFilePath + " not found in classpath");
    } else {
        try {
            properties.load(propertiesInputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    config.setJdbcUrl(Preconditions.checkNotNull(properties.getProperty("jdbc.url")));
    config.setUsername(Preconditions.checkNotNull(properties.getProperty("jdbc.username")));
    config.setPassword(Preconditions.checkNotNull(properties.getProperty("jdbc.password")));
    return new HikariDataSource(config);
}
 
Example #6
Source File: DataSourceConfig.java    From Spring with Apache License 2.0 6 votes vote down vote up
@Bean
public DataSource dataSource() {
    try {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName(driverClassName);
        hikariConfig.setJdbcUrl(url);
        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);

        hikariConfig.setMaximumPoolSize(5);
        hikariConfig.setConnectionTestQuery("SELECT 1");
        hikariConfig.setPoolName("springHikariCP");

        hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250");
        hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048");
        hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true");

        return new HikariDataSource(hikariConfig);
    } catch (Exception e) {
        return null;
    }
}
 
Example #7
Source File: DefaultJdbcComponent.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a datasource from the given jdbc config info.
 */
@SuppressWarnings("nls")
protected DataSource datasourceFromConfig(JdbcOptionsBean config) {
    Properties props = new Properties();
    props.putAll(config.getDsProperties());
    setConfigProperty(props, "jdbcUrl", config.getJdbcUrl());
    setConfigProperty(props, "username", config.getUsername());
    setConfigProperty(props, "password", config.getPassword());

    setConfigProperty(props, "connectionTimeout", config.getConnectionTimeout());
    setConfigProperty(props, "idleTimeout", config.getIdleTimeout());
    setConfigProperty(props, "maxPoolSize", config.getMaximumPoolSize());
    setConfigProperty(props, "maxLifetime", config.getMaxLifetime());
    setConfigProperty(props, "minIdle", config.getMinimumIdle());
    setConfigProperty(props, "poolName", config.getPoolName());
    setConfigProperty(props, "autoCommit", config.isAutoCommit());

    HikariConfig hikariConfig = new HikariConfig(props);
    return new HikariDataSource(hikariConfig);
}
 
Example #8
Source File: MySqlConnectionFactory.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
protected void appendProperties(HikariConfig config, 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");

    // append configurable properties
    super.appendProperties(config, properties);
}
 
Example #9
Source File: DataSourceFactory.java    From apollo with Apache License 2.0 6 votes vote down vote up
public static DataSource create(DatabaseConfiguration databaseConfiguration) {
    Properties poolProperties = new Properties();
    poolProperties.setProperty("username", databaseConfiguration.getUser());
    poolProperties.setProperty("dataSourceClassName", databaseConfiguration.getDataSourceClassName());
    poolProperties.setProperty("minimumIdle", String.valueOf(1));
    poolProperties.setProperty("maximumPoolSize", String.valueOf(50));
    poolProperties.setProperty("dataSource.serverName", databaseConfiguration.getHost());
    poolProperties.setProperty("dataSource.port", String.valueOf(databaseConfiguration.getPort()));
    poolProperties.setProperty("dataSource.databaseName", databaseConfiguration.getSchema());
    poolProperties.setProperty("poolName", "apollo");
    poolProperties.setProperty("connectionTimeout", String.valueOf(5000));
    poolProperties.setProperty("registerMbeans", "true");

    poolProperties.setProperty("password", databaseConfiguration.getPassword());
    HikariConfig hikariConfig = new HikariConfig(poolProperties);

    hikariConfig.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=UTF-8");

    logger.info("Creating connection pool with these parameters: {}, {}", poolProperties.toString(), hikariConfig.getDataSourceProperties());

    try {
        return new HikariDataSource(hikariConfig);
    } catch (Exception e) {
        throw new RuntimeException("Could not create connection pool, bailing out!", e);
    }
}
 
Example #10
Source File: PostgreConnectionFactory.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
protected void appendConfigurationInfo(HikariConfig config) {
    String address = this.configuration.getAddress();
    String[] addressSplit = address.split(":");
    address = addressSplit[0];
    String port = addressSplit.length > 1 ? addressSplit[1] : "5432";

    String database = this.configuration.getDatabase();
    String username = this.configuration.getUsername();
    String password = this.configuration.getPassword();

    config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
    config.addDataSourceProperty("serverName", address);
    config.addDataSourceProperty("portNumber", port);
    config.addDataSourceProperty("databaseName", database);
    config.addDataSourceProperty("user", username);
    config.addDataSourceProperty("password", password);
}
 
Example #11
Source File: MyBatisDataStore.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Supplies the populated Hikari configuration for this store.
 */
private HikariConfig configureHikari(final String storeName, final Map<String, String> attributes) {
  Properties properties = new Properties();
  properties.put("poolName", storeName);
  properties.putAll(attributes);

  if (attributes.get(JDBC_URL).startsWith("jdbc:postgresql")) {
    properties.put("driverClassName", "org.postgresql.Driver");
    // workaround https://github.com/pgjdbc/pgjdbc/issues/265
    properties.put("dataSource.stringtype", "unspecified");
  }

  // Parse and unflatten advanced attributes
  Object advanced = properties.remove(ADVANCED);
  if (advanced instanceof String) {
    TO_MAP.split((String) advanced).forEach(properties::putIfAbsent);
  }

  // Hikari doesn't like blank schemas in its config
  if (isBlank(properties.getProperty(SCHEMA))) {
    properties.remove(SCHEMA);
  }

  return new HikariConfig(properties);
}
 
Example #12
Source File: DatabaseConfiguration.java    From ScoreboardStats with MIT License 6 votes vote down vote up
/**
 * Loads the configuration
 */
public void loadConfiguration() {
    serverConfig = new HikariConfig();

    Path file = plugin.getDataFolder().toPath().resolve("sql.yml");
    //Check if the file exists. If so load the settings form there
    if (Files.notExists(file)) {
        //Create a new configuration based on the default settings form bukkit.yml
        plugin.saveResource("sql.yml", false);
    }

    FileConfiguration sqlConfig = YamlConfiguration.loadConfiguration(file.toFile());

    ConfigurationSection sqlSettingSection = sqlConfig.getConfigurationSection("SQL-Settings");
    serverConfig.setUsername(sqlSettingSection.getString("Username"));
    serverConfig.setPassword(sqlSettingSection.getString("Password"));
    serverConfig.setDriverClassName(sqlSettingSection.getString("Driver"));
    serverConfig.setJdbcUrl(replaceUrlString(sqlSettingSection.getString("Url")));
    if (serverConfig.getDriverClassName().contains("sqlite")) {
        serverConfig.setConnectionTestQuery("SELECT 1");
    }

    tablePrefix = sqlSettingSection.getString("tablePrefix", "");
}
 
Example #13
Source File: HammockDataSource.java    From hammock with Apache License 2.0 6 votes vote down vote up
private DataSource createDelegate(DataSourceDefinition dataSourceDefinition) {
    HikariConfig config = new HikariConfig();
    if (dataSourceDefinition.url() != null) {
        config.setJdbcUrl(dataSourceDefinition.url());
    }
    if (dataSourceDefinition.user() != null) {
        config.setUsername(dataSourceDefinition.user());
        config.setPassword(dataSourceDefinition.password());
    }
    if (dataSourceDefinition.maxPoolSize() > 0) {
        config.setMaximumPoolSize(dataSourceDefinition.maxPoolSize());
    }
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return wrap(new HikariDataSource(config));
}
 
Example #14
Source File: Connections.java    From glowroot with Apache License 2.0 6 votes vote down vote up
static HikariDataSource createHikariCpDataSource() throws AssertionError {
    if (Connections.class.getClassLoader() instanceof IsolatedWeavingClassLoader) {
        try {
            Class.forName("com.zaxxer.hikari.proxy.JavassistProxyFactory");
            throw new AssertionError("Old HikariCP versions define proxies using"
                    + " ClassLoader.defineClass() which is final so IsolatedWeavingClassLoader"
                    + " cannot override and weave them, must use JavaagentContainer");
        } catch (ClassNotFoundException e) {
        }
    }
    HikariConfig config = new HikariConfig();
    config.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    config.setJdbcUrl("jdbc:hsqldb:mem:test");
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return new HikariDataSource(config);
}
 
Example #15
Source File: PostgreSqlIntegrationTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void initializeConnectionAndTable() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.setConnectionTestQuery("VALUES 1");
    config.addDataSourceProperty("URL", "jdbc:h2:mem:test;ignorecase=true");
    config.addDataSourceProperty("user", "sa");
    config.addDataSourceProperty("password", "sa");
    HikariDataSource ds = new HikariDataSource(config);
    Connection connection = ds.getConnection();

    try (Statement st = connection.createStatement()) {
        st.execute("DROP TABLE IF EXISTS authme");
        st.execute(sqlInitialize);
    }
    hikariSource = ds;
}
 
Example #16
Source File: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public JooqContext getJooqContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getDatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example #17
Source File: MySqlIntegrationTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void initializeConnectionAndTable() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.setConnectionTestQuery("VALUES 1");
    // Note "ignorecase=true": H2 does not support `COLLATE NOCASE` for case-insensitive equals queries.
    // MySQL is by default case-insensitive so this is OK to make as an assumption.
    config.addDataSourceProperty("URL", "jdbc:h2:mem:test;ignorecase=true");
    config.addDataSourceProperty("user", "sa");
    config.addDataSourceProperty("password", "sa");
    HikariDataSource ds = new HikariDataSource(config);
    Connection connection = ds.getConnection();

    try (Statement st = connection.createStatement()) {
        st.execute("DROP TABLE IF EXISTS authme");
        st.execute(sqlInitialize);
    }
    hikariSource = ds;
}
 
Example #18
Source File: HikariDataSourceFactory.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * Create datasource.
 * 
 * @return
 */
protected DataSource createDataSource(String driver, String jdbcUrl, String username, String password, int maxConnections) {
	hasTextOf(driver, "driver");
	hasTextOf(jdbcUrl, "jdbcUrl");
	hasTextOf(username, "username");
	hasTextOf(password, "password");

	// props.put("dataSource.logWriter", new PrintWriter(System.out));
	HikariConfig config = new HikariConfig();
	config.setDriverClassName(driver);
	config.setJdbcUrl(jdbcUrl);
	config.setUsername(username);
	config.setPassword(password);
	config.setMaximumPoolSize(maxConnections);
	config.setMinimumIdle((int) (maxConnections * 0.1f));
	DataSource datasource = new HikariDataSource(config);
	log.info(format("Creating datasource: %s of jdbcUrl: %s", datasource, jdbcUrl));
	return datasource;
}
 
Example #19
Source File: LoginSecurityConverterTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
private Connection initializeMySqlTable() throws IOException, SQLException {
    File sqlInitFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "datasource/converter/loginsecurity.sql");
    String initStatement = new String(Files.readAllBytes(sqlInitFile.toPath()));

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.setConnectionTestQuery("VALUES 1");
    config.addDataSourceProperty("URL", "jdbc:h2:mem:test");
    config.addDataSourceProperty("user", "sa");
    config.addDataSourceProperty("password", "sa");
    HikariDataSource ds = new HikariDataSource(config);
    Connection connection = ds.getConnection();

    try (Statement st = connection.createStatement()) {
        st.execute("DROP TABLE IF EXISTS authme");
        st.execute(initStatement);
    }
    return connection;
}
 
Example #20
Source File: DbUtil.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
private static DataSource createDataSource() {
    HikariConfig hikariDataSourceConfig = new HikariConfig();
    hikariDataSourceConfig.setJdbcUrl(DATABASE_URL);
    hikariDataSourceConfig.setDriverClassName(DRIVER_CLASS_NAME);
    hikariDataSourceConfig.setAutoCommit(false);
    return new HikariDataSource(hikariDataSourceConfig);
}
 
Example #21
Source File: SqlConnectionPool.java    From luna with MIT License 5 votes vote down vote up
/**
 * Creates a new connection pool.
 *
 * @return The new pool.
 * @throws SQLException If the pool cannot be created.
 */
public SqlConnectionPool build() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl("jdbc:mysql://" + HOST + ":" + PORT + "/" + database + "");
    config.setUsername(USERNAME);
    config.setPassword(PASSWORD);
    config.setPoolName(poolName);
    return new SqlConnectionPool(new HikariDataSource(config));
}
 
Example #22
Source File: HikariConfigFactory.java    From registry with Apache License 2.0 5 votes vote down vote up
private static HikariConfig oracleConfig(Map<String, Object> dbProperties) {
    Map<String, Object> propsCopy = new HashMap<>(dbProperties);
    propsCopy.remove(Constants.DataSource.CONNECTION_PROPERTIES);
    HikariConfig hikariConfig = mysqlConfig(propsCopy);
    if (dbProperties.containsKey(Constants.DataSource.CONNECTION_PROPERTIES)) {
        Properties properties = new Properties();
        properties.putAll((Map<?, ?>) dbProperties.get(Constants.DataSource.CONNECTION_PROPERTIES));
        hikariConfig.addDataSourceProperty("connectionProperties", properties);
    }

    return hikariConfig;
}
 
Example #23
Source File: RepositoryFactoryImpl.java    From datashare with GNU Affero General Public License v3.0 5 votes vote down vote up
DataSource createDatasource() {
    HikariConfig config = new HikariConfig();
    String dataSourceUrl = getDataSourceUrl();
    config.setJdbcUrl(dataSourceUrl);
    if (dataSourceUrl.contains("sqlite")) {
        config.setDriverClassName("org.sqlite.JDBC");
    }
    return new HikariDataSource(config);
}
 
Example #24
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected static HikariDataSource connect() {
  HikariConfig hikariConfig = new HikariConfig();
  hikariConfig.setJdbcUrl(getJdbcUrl());
  hikariConfig.setUsername("root");
  hikariConfig.setPassword(MYSQL_PASSWORD);
  hikariConfig.addDataSourceProperty("useSSL", false);
  hikariConfig.setAutoCommit(false);
  return new HikariDataSource(hikariConfig);
}
 
Example #25
Source File: HikariConnectionFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
protected void appendConfigurationInfo(HikariConfig config) {
    String address = this.configuration.getAddress();
    String[] addressSplit = address.split(":");
    address = addressSplit[0];
    String port = addressSplit.length > 1 ? addressSplit[1] : "3306";

    config.setDataSourceClassName(getDriverClass());
    config.addDataSourceProperty("serverName", address);
    config.addDataSourceProperty("port", port);
    config.addDataSourceProperty("databaseName", this.configuration.getDatabase());
    config.setUsername(this.configuration.getUsername());
    config.setPassword(this.configuration.getPassword());
}
 
Example #26
Source File: AbstractHsqldbJPAConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource actualDataSource() {
    Properties driverProperties = new Properties();
    driverProperties.setProperty("url", jdbcUrl);
    driverProperties.setProperty("user", jdbcUser);
    driverProperties.setProperty("password", jdbcPassword);

    Properties properties = new Properties();
    properties.put("dataSourceClassName", dataSourceClassName);
    properties.put("dataSourceProperties", driverProperties);
    //properties.setProperty("minimumPoolSize", String.valueOf(1));
    properties.setProperty("maximumPoolSize", String.valueOf(3));
    properties.setProperty("connectionTimeout", String.valueOf(5000));
    return new HikariDataSource(new HikariConfig(properties));
}
 
Example #27
Source File: DataSourceConfiguration.java    From Agent-Benchmarks with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public DataSource getDataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
    config.setUsername("root");
    config.setPassword("root");
    config.setMaximumPoolSize(500);
    config.setMinimumIdle(10);
    return new HikariDataSource(config);
}
 
Example #28
Source File: DatabaseManager.java    From factions-top with MIT License 5 votes vote down vote up
public static DatabaseManager create(HikariConfig hikariConfig, IdentityCache identityCache) throws SQLException {
    // Create the datasource.
    HikariDataSource dataSource = new HikariDataSource(hikariConfig);

    // Create the database manager.
    DatabaseManager manager = new DatabaseManager(dataSource, identityCache);

    // Initialize the database.
    Connection connection = dataSource.getConnection();
    manager.init(connection);
    connection.close();

    // Return the new database manager.
    return manager;
}
 
Example #29
Source File: DataSourceProvider.java    From digdag with Apache License 2.0 5 votes vote down vote up
private void createPooledDataSource()
{
    String url = DatabaseConfig.buildJdbcUrl(config);

    HikariConfig hikari = new HikariConfig();
    hikari.setJdbcUrl(url);
    hikari.setDriverClassName(DatabaseMigrator.getDriverClassName(config.getType()));
    hikari.setDataSourceProperties(DatabaseConfig.buildJdbcProperties(config));

    hikari.setConnectionTimeout(config.getConnectionTimeout() * 1000);
    hikari.setIdleTimeout(config.getIdleTimeout() * 1000);
    hikari.setValidationTimeout(config.getValidationTimeout() * 1000);
    hikari.setMaximumPoolSize(config.getMaximumPoolSize());
    hikari.setMinimumIdle(config.getMinimumPoolSize());
    hikari.setRegisterMbeans(config.getEnableJMX());
    hikari.setLeakDetectionThreshold(config.getLeakDetectionThreshold());

    // Here should not set connectionTestQuery (that overrides isValid) because
    // ThreadLocalTransactionManager.commit assumes that Connection.isValid returns
    // false when an error happened during a transaction.

    logger.debug("Using database URL {}", hikari.getJdbcUrl());

    HikariDataSource ds = new HikariDataSource(hikari);
    this.ds = ds;
    this.closer = ds;
}
 
Example #30
Source File: MysqlConnection.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DataSource dataSource() {
  String className = Driver.class.getName();
  HikariConfig config = toConfig();
  config.setDriverClassName(className);
  // A value less than zero will not bypass any connection attempt and validation during startup,
  // and therefore the pool will start immediately
  config.setInitializationFailTimeout(-1);
  return new HikariDataSource(config);
}