Java 类com.zaxxer.hikari.HikariConfig 实例源码

项目:helper    文件:HikariWrapper.java   
public HikariWrapper(@Nonnull DatabaseCredentials credentials) {
    HikariConfig config = new HikariConfig();

    config.setMaximumPoolSize(25);

    config.setPoolName("helper-sql-" + COUNTER.getAndIncrement());
    config.setDataSourceClassName("org.mariadb.jdbc.MySQLDataSource");
    config.addDataSourceProperty("serverName", credentials.getAddress());
    config.addDataSourceProperty("port", credentials.getPort());
    config.addDataSourceProperty("databaseName", credentials.getDatabase());
    config.setUsername(credentials.getUsername());
    config.setPassword(credentials.getPassword());

    // hack for the mariadb driver
    config.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8");

    // We will wait for 15 seconds to get a connection from the pool.
    // Default is 30, but it shouldn't be taking that long.
    config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000

    // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
    config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000

    hikari = new HikariDataSource(config);
}
项目:SqlSauce    文件:DatabaseConnection.java   
@Nonnull
public static HikariConfig getDefaultHikariConfig() {
    final HikariConfig hikariConfig = new HikariConfig();

    //more database connections don't help with performance, so use a default value based on available cores
    //http://www.dailymotion.com/video/x2s8uec_oltp-performance-concurrent-mid-tier-connections_tech
    hikariConfig.setMaximumPoolSize(Math.max(Runtime.getRuntime().availableProcessors(), 4));

    //timeout the validation query (will be done automatically through Connection.isValid())
    hikariConfig.setValidationTimeout(3000);
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setAutoCommit(false);

    hikariConfig.setDriverClassName("org.postgresql.Driver");

    return hikariConfig;
}
项目:amv-access-api-poc    文件:DatabaseConfig.java   
@Bean
public HikariConfig hikariConfig() {
    log.info("Creating HikariConfig with:\n* username: {}\n* jdbcUrl: {}", databaseProperties.getUsername(), databaseProperties.getUrl());

    HikariConfig config = new HikariConfig();
    config.setDriverClassName(databaseProperties.getDriverClassName());
    config.setJdbcUrl(databaseProperties.getUrl());
    config.setUsername(databaseProperties.getUsername());
    config.setPassword(databaseProperties.getPassword());
    config.setMaximumPoolSize(databaseProperties.getMaximumPoolSize());
    config.setIdleTimeout(databaseProperties.getIdleTimeout());
    config.setConnectionTestQuery(databaseProperties.getConnectionTestQuery());
    config.setPoolName(databaseProperties.getPoolName());
    config.setMetricsTrackerFactory(prometheusMetricsTrackerFactory());

    config.setDataSourceProperties(dataSourceProperties());

    return config;
}
项目:PetBlocks    文件:DatabaseIT.java   
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
项目:PetBlocks    文件:DatabaseIT.java   
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
项目:PetBlocks    文件:ExtensionHikariConnectionContext.java   
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userNames
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
项目:devops-cstack    文件:DatabaseConfiguration.java   
@Bean
public DataSource dataSource() {
    logger.debug("Configuring Datasource");
    String databaseUrl = String.format("jdbc:mysql://%s:%s/%s?%s",
            databaseHostname, databasePort, databaseSchema, databaseOptions);
    logger.info("database.url:" + databaseUrl);
    logger.info("database.user:" + databaseUser);
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("url", databaseUrl);
    config.addDataSourceProperty("user", databaseUser);
    config.setInitializationFailFast(false);
    config.setIdleTimeout(60000);
    String forcePassword = System.getenv("MYSQL_ROOT_PASSWORD");
    // coming from environnment host
    if (forcePassword != null) {
        logger.info("Force the mysql password from host env");
        databasePassword = forcePassword;
    }
    logger.info("URL : " + databaseUrl + " password : " + databasePassword);
    config.addDataSourceProperty("password", databasePassword);
    return new HikariDataSource(config);
}
项目:devops-cstack    文件:DatabaseConfigurationTest.java   
@Bean
public DataSource dataSource() {
    logger.debug("Configuring Datasource");
    String databaseUrl = String.format("jdbc:mysql://%s:%s/%s?%s",
            databaseHostname, databasePort, databaseSchema, databaseOptions);
    logger.debug("database.url:" + databaseUrl);
    logger.debug("database.user:" + databaseUser);
    HikariConfig config = new HikariConfig();

    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("url", databaseUrl);
    config.addDataSourceProperty("user", databaseUser);
    config.addDataSourceProperty("password", databasePassword);
    // config.setAutoCommit(false);
    return new HikariDataSource(config);
}
项目:jboot    文件:HikariDataSourceFactory.java   
@Override
public DataSource createDataSource(DataSourceConfig dataSourceConfig) {

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(dataSourceConfig.getUrl());
    hikariConfig.setUsername(dataSourceConfig.getUser());
    hikariConfig.setPassword(dataSourceConfig.getPassword());
    hikariConfig.addDataSourceProperty("cachePrepStmts", dataSourceConfig.isCachePrepStmts());
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", dataSourceConfig.getPrepStmtCacheSize());
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", dataSourceConfig.getPrepStmtCacheSqlLimit());

    hikariConfig.setDriverClassName(dataSourceConfig.getDriverClassName());
    hikariConfig.setPoolName(dataSourceConfig.getPoolName());


    if (dataSourceConfig.getConnectionInitSql() != null) {
        hikariConfig.setConnectionInitSql(dataSourceConfig.getConnectionInitSql());
    }


    hikariConfig.setMaximumPoolSize(dataSourceConfig.getMaximumPoolSize());

    return new HikariDataSource(hikariConfig);
}
项目:message-broker    文件:RdbmsCoordinationStrategyTest.java   
@BeforeClass
public void setUp() throws SQLException {
    Connection connection = DriverManager.getConnection(databaseUrl + ";create=true");
    Statement statement = connection.createStatement();
    statement.executeUpdate(CREATE_MB_COORDINATOR_HEARTBEAT_TABLE);
    statement.executeUpdate(CREATE_MB_NODE_HEARTBEAT_TABLE);
    connection.close();

    Map<String, String> rdbmsCoordinationOptions = new HashMap<>();
    rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.NODE_IDENTIFIER, nodeOneId);
    rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.HEARTBEAT_INTERVAL, "5000");
    rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.COORDINATOR_ENTRY_CREATION_WAIT_TIME, "3000");

    HikariConfig hikariDatasourceConfig = new HikariConfig();
    hikariDatasourceConfig.setJdbcUrl(databaseUrl);
    hikariDatasourceConfig.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    hikariDatasourceConfig.setAutoCommit(false);
    DataSource datasource = new HikariDataSource(hikariDatasourceConfig);

    RdbmsCoordinationDaoImpl rdbmsCoordinationDaoImpl = new RdbmsCoordinationDaoImpl(datasource);
    rdbmsCoordinationStrategy =
            new RdbmsCoordinationStrategy(rdbmsCoordinationDaoImpl, rdbmsCoordinationOptions);
    rdbmsCoordinationStrategy.start();
}
项目:storm-clickhouse    文件:HikariCPConnectionProviderExt.java   
@Override
public synchronized void prepare() {
    if(dataSource == null) {
        Properties properties = new Properties();
        properties.putAll(configMap);
        HikariConfig config = new HikariConfigExt(properties);
        if(properties.containsKey("dataSource.url")) {
            LOG.info("DataSource Url: " + properties.getProperty("dataSource.url"));
        }
        else if (config.getJdbcUrl() != null) {
            LOG.info("JDBC Url: " + config.getJdbcUrl());
        }
        this.dataSource = new HikariDataSource(config);
        this.dataSource.setAutoCommit(false);
    }
}
项目:Stats4    文件:MySQLThreadPool.java   
private MySQLThreadPool(FileConfiguration config) {
    HikariConfig poolConf = new HikariConfig();
    poolConf.setJdbcUrl("jdbc:mysql://"
            + config.getString("mysql.host", "localhost")
            + ":"
            + config.getInt("mysql.port", 3306)
            + "/"
            + config.getString("mysql.database", "Stats4")
            + config.getString("mysql.extra-opts", ""));
    poolConf.setUsername(config.getString("mysql.username"));
    poolConf.setPassword(config.getString("mysql.password"));
    poolConf.addDataSourceProperty("cachePrepStmts", true);
    poolConf.addDataSourceProperty("prepStmtCacheSize", "256");
    poolConf.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    poolConf.addDataSourceProperty("useServerPrepStmts", true);
    poolConf.addDataSourceProperty("useLocalSessionState", true);
    poolConf.addDataSourceProperty("useLocalTransactionState", true);
    poolConf.addDataSourceProperty("rewriteBatchedStatements", true);
    poolConf.addDataSourceProperty("cacheResultSetMetadata", true);
    poolConf.addDataSourceProperty("cacheServerConfiguration", true);
    poolConf.addDataSourceProperty("elideSetAutoCommits", true);
    //      poolConf.addDataSourceProperty("maintainTimeStats", false);

    this.dataSource = new HikariDataSource(poolConf);
}
项目:Pxls    文件:Database.java   
public Database() {
    try {
        Class.forName("org.mariadb.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(App.getConfig().getString("database.url"));
    config.setUsername(App.getConfig().getString("database.user"));
    config.setPassword(App.getConfig().getString("database.pass"));
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("allowMultiQueries", "true");
    config.setMaximumPoolSize(200); // this is plenty, the websocket uses 32

    dbi = new DBI(new HikariDataSource(config));


    getHandle().createPixelsTable();
    getHandle().createUsersTable();
    getHandle().createSessionsTable();
    getHandle().createAdminLogTable();
    getHandle().createReportsTable();
}
项目:Spring-OAuth2-Custom    文件:DataSourceConfiguration.java   
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
    dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
    dataSourceConfig.setUsername(environment.getRequiredProperty("spring.datasource.username"));
    dataSourceConfig.setPassword(environment.getRequiredProperty("spring.datasource.password"));
    dataSourceConfig.setMaximumPoolSize(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maximumPoolSize")));
    dataSourceConfig.setMinimumIdle(Integer.parseInt(environment.getRequiredProperty("spring.datasource.minimumIdle")));
    dataSourceConfig.setMaxLifetime(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maxLifetime")));
    dataSourceConfig.setConnectionTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.connectionTimeout")));
    dataSourceConfig.setIdleTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.idleTimeout")));
    dataSourceConfig.addDataSourceProperty("poolName", environment.getRequiredProperty("spring.datasource.poolName"));
    dataSourceConfig.addDataSourceProperty("cachePrepStmts", "true");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return new HikariDataSource(dataSourceConfig);
}
项目:BlockBall    文件:ExtensionHikariConnectionContext.java   
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userName
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
项目:BlockBall    文件:DatabaseTest.java   
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
项目:BlockBall    文件:DatabaseTest.java   
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }

        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
项目:queries    文件:SampleQueries.java   
@Before
public void setUp() {

    HikariConfig config = new HikariConfig("/com/jaregu/queries/example/hikari.properties");
    DataSource ds = new HikariDataSource(config);
    db = new Database(ds);

    // db = createLocalOracleDb(); // createLocalMariaDb();

    source = QueriesSource.ofResource("com/jaregu/queries/example/sample-queries.sql");
    queries = Queries.of(source);
    rq = queries.relativeTo(source.getId());

    // oracle.jdbc.driver.OracleDriver aa = new OracleDriver();

    if (!initialized) {
        createDummyTable();
        insertDummyData();
        initialized = true;
    }
}
项目:ZorahPractice    文件:ConnectionPoolManager.java   
private void setupPool() {
    HikariConfig config = new HikariConfig();

    config.setJdbcUrl("jdbc:mysql://" + this.credentials.getHostname() + ":" + this.credentials.getPort() + "/" + this.credentials.getDatabaseName());
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setUsername(this.credentials.getUsername());
    config.setPassword(this.credentials.getPassword());
    config.setMinimumIdle(this.minimumConnections);
    config.setMaximumPoolSize(this.maximumConnections);
    config.setConnectionTimeout(this.connectionTimeout);

    try {
        this.dataSource = new HikariDataSource(config);
    }
    catch (Exception e) {
        Bukkit.getLogger().severe("[ZorahPractice] - Unable to establish MySQL connection, plugin disabled.");
        Bukkit.getServer().getPluginManager().disablePlugin(PracticePlugin.getInstance());
    }
}
项目:StubbornJava    文件:ConnectionPool.java   
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
项目:k-framework    文件:MybatisAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
    HikariConfig configuration = new HikariConfig();
    configuration.setJdbcUrl(url);
    configuration.setUsername(username);
    configuration.setPassword(password);
    configuration.setAutoCommit(false);
    configuration.setMaximumPoolSize(maxPoolSize);
    configuration.setConnectionTimeout(connectionTimeout);
    configuration.setMaxLifetime(maxLifetime);
    Properties properties = new Properties();
    properties.setProperty("cachePrepStmts", cachePrepStmts);
    properties.setProperty("prepStmtCacheSize", prepStmtCacheSize);
    properties.setProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit);
    properties.setProperty("useServerPrepStmts", useServerPrepStmts);
    configuration.setDataSourceProperties(properties);
    configuration.setConnectionInitSql("SET NAMES " + connectionCharacter);
    return new HikariDataSource(configuration);
}
项目:XIVStats-Gatherer-Java    文件:SpringConfiguration.java   
@Bean(destroyMethod = "close") // Should happen anyway, but worth calling out
@Primary
public HikariDataSource dataSource() throws ParserConfigurationException, IOException, SAXException, ParseException {
    ApplicationConfig appConfig = applicationConfig();

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:" + appConfig.getDbUrl() + "/" + appConfig.getDbName());
    hikariConfig.setUsername(appConfig.getDbUser());
    hikariConfig.setPassword(appConfig.getDbPassword());
    hikariConfig.setMaximumPoolSize(appConfig.getThreadLimit());
    hikariConfig.setInitializationFailTimeout(30000);
    if(appConfig.isDbIgnoreSSLWarn()) {
        hikariConfig.addDataSourceProperty("useSSL", false);
    }

    return new HikariDataSource(hikariConfig);
}
项目:todo-spring-angular    文件:DatabaseConfiguration.java   
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    log.debug("Configuring Datasource");
    if (dataSourcePropertyResolver.getProperty("url") == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));
        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
    hikariConfig.setJdbcUrl(dataSourcePropertyResolver.getProperty("url"));
    hikariConfig.setUsername(dataSourcePropertyResolver.getProperty("username"));
    hikariConfig.setPassword(dataSourcePropertyResolver.getProperty("password"));
    return new HikariDataSource(hikariConfig);
}
项目:todo-list    文件:LocalMySqlServer.java   
private static DataSource createDataSource(String[] args) {
    final HikariConfig config = new HikariConfig();

    final String dbName = args[0];
    final String username = args[1];
    final String password = args[2];

    log().info("Start `DataSource` creation. The following parameters will be used:");
    final String dbUrl = format(DB_URL_FORMAT, getDbUrlPrefix(), dbName);
    config.setJdbcUrl(dbUrl);
    log().info("JDBC URL: {}", dbUrl);

    config.setUsername(username);
    log().info("Username: {}", username);

    config.setPassword(password);
    log().info("Password: {}", password);

    final DataSource dataSource = new HikariDataSource(config);
    return dataSource;
}
项目:todo-list    文件:LocalCloudSqlServer.java   
private static DataSource createDataSource(String[] args) {
    final HikariConfig config = new HikariConfig();

    final String instanceConnectionName = args[0];
    final String dbName = args[1];
    final String username = args[2];
    final String password = args[3];

    log().info("Start `DataSource` creation. The following parameters will be used:");
    final String dbUrl = format(DB_URL_FORMAT, getDbUrlPrefix(), dbName, instanceConnectionName);
    config.setJdbcUrl(dbUrl);
    log().info("JDBC URL: {}", dbUrl);

    config.setUsername(username);
    log().info("Username: {}", username);

    config.setPassword(password);
    log().info("Password: {}", password);

    final DataSource dataSource = new HikariDataSource(config);
    return dataSource;
}
项目:todo-list    文件:ComputeCloudSqlServer.java   
private static DataSource createDataSource() {
    final HikariConfig config = new HikariConfig();

    final String instanceConnectionName = properties.getProperty("db.instance");
    final String dbName = properties.getProperty("db.name");
    final String username = properties.getProperty("db.username");
    final String password = properties.getProperty("db.password");

    log().info("Start `DataSource` creation. The following parameters will be used:");
    final String dbUrl = format(DB_URL_FORMAT, getDbUrlPrefix(), dbName, instanceConnectionName);
    config.setJdbcUrl(dbUrl);
    log().info("JDBC URL: {}", dbUrl);

    config.setUsername(username);
    log().info("Username: {}", username);

    config.setPassword(password);
    log().info("Password: {}", password);

    final DataSource dataSource = new HikariDataSource(config);
    return dataSource;
}
项目:todo-list    文件:AbstractIntegrationTest.java   
private DataSource createDataSource() {
    final HikariConfig config = new HikariConfig();

    final String prefix = DB_CONFIG_PROPERTIES.getProperty("db.prefix");
    final String dbName = DB_CONFIG_PROPERTIES.getProperty("db.name");
    final String username = DB_CONFIG_PROPERTIES.getProperty("db.username");
    final String password = DB_CONFIG_PROPERTIES.getProperty("db.password");
    final String host = DB_CONFIG_PROPERTIES.getProperty("db.host");
    final String port = DB_CONFIG_PROPERTIES.getProperty("db.port");

    LOGGER.info("Start `DataSource` creation. The following parameters will be used:");
    final String dbUrl = format(DB_URL_FORMAT, prefix, host, port, dbName);
    config.setJdbcUrl(dbUrl);
    LOGGER.info("JDBC URL: {}", dbUrl);

    config.setUsername(username);
    LOGGER.info("Username: {}", username);

    config.setPassword(password);
    LOGGER.info("Password: {}", password);

    final DataSource dataSource = new HikariDataSource(config);
    return dataSource;
}
项目:beige-software    文件:FactoryAppBeansH2.java   
/**
 * <p>Get DataSource in lazy mode.</p>
 * @return DataSource - DataSource
 * @throws Exception - an exception
 */
@Override
public final synchronized DataSource lazyGetDataSource() throws Exception {
  String beanName = getDataSourceName();
  HikariDataSource dataSource =
    (HikariDataSource) getBeansMap().get(beanName);
  if (dataSource == null) {
    Properties props = new Properties();
    props.setProperty("dataSourceClassName", "org.h2.jdbcx.JdbcDataSource");
    props.setProperty("dataSource.user", getDatabaseUser());
    props.setProperty("dataSource.password", getDatabasePassword());
    props.setProperty("dataSource.Url", getDatabaseName());
    HikariConfig config = new HikariConfig(props);
    dataSource = new HikariDataSource(config);
    getBeansMap().put(beanName, dataSource);
    lazyGetLogger().info(null, FactoryAppBeansH2.class, beanName
      + " has been created.");
  }
  return dataSource;
}
项目:beige-software    文件:FactoryAppBeansMysql.java   
/**
 * <p>Get DataSource in lazy mode.</p>
 * @return DataSource - DataSource
 * @throws Exception - an exception
 */
@Override
public final synchronized DataSource lazyGetDataSource() throws Exception {
  String beanName = getDataSourceName();
  HikariDataSource dataSource =
    (HikariDataSource) getBeansMap().get(beanName);
  if (dataSource == null) {
    Properties props = new Properties();
    props.setProperty("dataSourceClassName",
      "com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    props.setProperty("dataSource.user", getDatabaseUser());
    props.setProperty("dataSource.password", getDatabasePassword());
    props.setProperty("dataSource.url", getDatabaseName());
    HikariConfig config = new HikariConfig(props);
    dataSource = new HikariDataSource(config);
    getBeansMap().put(beanName, dataSource);
    lazyGetLogger().info(null, FactoryAppBeansMysql.class, beanName
      + " has been created.");
  }
  return dataSource;
}
项目:beige-software    文件:FactoryAppBeansPostgresql.java   
/**
 * <p>Get DataSource in lazy mode.</p>
 * @return DataSource - DataSource
 * @throws Exception - an exception
 */
@Override
public final synchronized DataSource lazyGetDataSource() throws Exception {
  String beanName = getDataSourceName();
  HikariDataSource dataSource =
    (HikariDataSource) getBeansMap().get(beanName);
  if (dataSource == null) {
    Properties props = new Properties();
    props.setProperty("dataSourceClassName",
      "org.postgresql.ds.PGSimpleDataSource");
    props.setProperty("dataSource.user", getDatabaseUser());
    props.setProperty("dataSource.password", getDatabasePassword());
    props.setProperty("dataSource.databaseName", getDatabaseName());
    HikariConfig config = new HikariConfig(props);
    dataSource = new HikariDataSource(config);
    getBeansMap().put(beanName, dataSource);
    lazyGetLogger().info(null, FactoryAppBeansPostgresql.class, beanName
      + " has been created.");
  }
  return dataSource;
}
项目:Jecon    文件:MySQL.java   
public MySQL(Jecon jecon) {
    super.config = jecon.getConfigStruct();

    jecon.getLogger().info("Connect to MySQL.");

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");

    // for Performance
    hikariConfig.addDataSourceProperty("cacheServerConfiguration", "true");
    hikariConfig.addDataSourceProperty("alwaysSendSetIsolation", "false");
    hikariConfig.addDataSourceProperty("useLocalSessionState", "true");
    hikariConfig.addDataSourceProperty("elideSetAutoCommits", "true");
    hikariConfig.addDataSourceProperty("maintainTimeStats", "false");
    hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

    super.setup(jecon, hikariConfig);
}
项目:Jecon    文件:Database.java   
protected void setup(Jecon jecon, HikariConfig hikariConfig) {
    this.jecon = jecon;
    if (config == null) {
        config = jecon.getConfigStruct();
    }
    this.prefix = config.getDbConfig().prefix;

    hikariConfig.setJdbcUrl(config.getDbConfig().url);
    hikariConfig.setInitializationFailFast(true);
    hikariConfig.setAutoCommit(true);
    hikariConfig.setConnectionInitSql("/* Jecon */SELECT 1");

    if (config.getDbConfig().poolSize > 0) {
        hikariConfig.setMaximumPoolSize(config.getDbConfig().poolSize);
    }
    if (config.getDbConfig().timeout > 0) {
        hikariConfig.setIdleTimeout(config.getDbConfig().timeout);
    }

    hikariConfig.setDataSourceProperties(config.getDbConfig().propaties);

    // HikariDataSourceをインスタンス化
    this.hikariDc = new HikariDataSource(hikariConfig);

    this.createTable();
}
项目:Parties    文件:MySQLData.java   
private void initConnection() throws Exception {
    HikariConfig config = new HikariConfig();
    config.setPoolName("Parties");
    config.setJdbcUrl(Variables.storage_settings_mysql_url);
    config.setUsername(Variables.storage_settings_mysql_username);
    config.setPassword(Variables.storage_settings_mysql_password);
    config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
    config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
    config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
    config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);

    // Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
    config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
    config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
    config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
    config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
    config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks

    hikariDataSource = new HikariDataSource(config);
}
项目:jVoid    文件:MetadataDatabase.java   
/**
 *
 */
@Inject
public void startup() {
    if (ds != null && !ds.isClosed()) {
        return;
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(configuration.dbUrl());
    config.setUsername(configuration.dbUsername());
    config.setPassword(configuration.dbPassword());
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

    ds = new HikariDataSource(config);

    initializeDatabase();
}
项目:steve-plugsurfing    文件:BeanConfiguration.java   
/**
 * https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
 */
private void initDataSource() {
    MysqlDataSource ds = new MysqlDataSource();

    // set standard params
    ds.setServerName(CONFIG.getDb().getIp());
    ds.setPort(CONFIG.getDb().getPort());
    ds.setDatabaseName(CONFIG.getDb().getSchema());
    ds.setUser(CONFIG.getDb().getUserName());
    ds.setPassword(CONFIG.getDb().getPassword());

    // set non-standard params
    ds.getModifiableProperty(PropertyDefinitions.PNAME_cachePrepStmts).setValue(true);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSize).setValue(250);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSqlLimit).setValue(2048);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_characterEncoding).setValue("utf8");
    ds.getModifiableProperty(PropertyDefinitions.PNAME_serverTimezone).setValue("UTC");

    HikariConfig hc = new HikariConfig();
    hc.setDataSource(ds);

    dataSource = new HikariDataSource(hc);
}
项目:JOOQ    文件:HikariCpImpl.java   
public HikariCpImpl() {
    Properties properties = new Properties();
    properties.setProperty("dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    properties.setProperty("dataSource.serverName", "127.0.0.1");
    properties.setProperty("dataSource.portNumber", "3306");
    properties.setProperty("dataSource.databaseName", "study");
    properties.setProperty("dataSource.user", "root");
    properties.setProperty("dataSource.password", "zhilaiadmin");
    properties.setProperty("dataSource.encoding", "UTF-8");
    properties.setProperty("maximumPoolSize", "100");
    HikariConfig config = new HikariConfig(properties);
    config.setConnectionTimeout(30 * 1000);
    config.setIdleTimeout(60 * 1000);
    config.setMaxLifetime(60 * 1000);
    config.setMinimumIdle(50);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "1000");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    ds = new HikariDataSource(config);
}
项目:LuckPerms    文件:MySqlConnectionFactory.java   
@Override
protected void appendProperties(HikariConfig config, StorageCredentials credentials) {
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("alwaysSendSetIsolation", "false");
    config.addDataSourceProperty("cacheServerConfiguration", "true");
    config.addDataSourceProperty("elideSetAutoCommits", "true");
    config.addDataSourceProperty("useLocalSessionState", "true");

    config.addDataSourceProperty("useServerPrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("cacheCallableStmts", "true");

    // append configurable properties
    super.appendProperties(config, credentials);
}
项目:LuckPerms    文件:PostgreConnectionFactory.java   
@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);
}
项目:protox-webapp-archetype    文件:DataSourceFactory.java   
@Override
public DataSource provide() {
    LOGGER.debug("{}", this);
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(jdbcUrl);
    config.setUsername(username);
    config.setPassword(password);
    config.setAutoCommit(autoCommit);
    config.setMaximumPoolSize(maximumPoolSize);
    config.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

    HikariDataSource dataSource = new HikariDataSource(config);
    LOGGER.debug("provide DataSource {}", dataSource);

    return dataSource;
}
项目:LrestServer    文件:DatabasePool.java   
public boolean getStoragePooling()
{
    try
    {
        this.databaseConfiguration = new HikariConfig();
        this.databaseConfiguration.setMaximumPoolSize(20);
        this.databaseConfiguration.setDriverClassName("com.mysql.jdbc.Driver");
        //this.databaseConfiguration.setJdbcUrl("jdbc:mysql://192.168.2.16:3306/testdb?user=root&password=123456");
        this.databaseConfiguration.setJdbcUrl(Config.mysql_jdbcurl);
        this.databaseConfiguration.setUsername(Config.mysql_user);
        this.databaseConfiguration.setPassword(Config.mysql_password);
        this.databaseConfiguration.setAutoCommit(true);
        this.databaseConfiguration.setMaxLifetime(120000000L);
        this.databaseConfiguration.setConnectionTestQuery("SELECT 1");
        this.databaseConfiguration.setPoolName("ychlrestserver");
        this.database = new HikariDataSource(this.databaseConfiguration);

    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
    return true;
}