当前位置: 首页>>代码示例>>Java>>正文


Java HikariConfig类代码示例

本文整理汇总了Java中com.zaxxer.hikari.HikariConfig的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig类的具体用法?Java HikariConfig怎么用?Java HikariConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HikariConfig类属于com.zaxxer.hikari包,在下文中一共展示了HikariConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Database

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
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();
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:27,代码来源:Database.java

示例2: hikariConfig

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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;
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:20,代码来源:DatabaseConfig.java

示例3: HikariWrapper

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
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);
}
 
开发者ID:lucko,项目名称:helper,代码行数:26,代码来源:HikariWrapper.java

示例4: getDefaultHikariConfig

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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;
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:18,代码来源:DatabaseConnection.java

示例5: setupPool

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
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());
    }
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:20,代码来源:ConnectionPoolManager.java

示例6: MySQL

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
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);
}
 
开发者ID:HimaJyun,项目名称:Jecon,代码行数:21,代码来源:MySQL.java

示例7: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:18,代码来源:DatabaseIT.java

示例8: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:26,代码来源:DatabaseIT.java

示例9: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:29,代码来源:ExtensionHikariConnectionContext.java

示例10: dataSource

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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);
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:24,代码来源:DatabaseConfiguration.java

示例11: dataSource

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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);
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:DatabaseConfigurationTest.java

示例12: createDataSource

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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);
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:25,代码来源:HikariDataSourceFactory.java

示例13: setUp

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:25,代码来源:RdbmsCoordinationStrategyTest.java

示例14: prepare

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:neur0nus,项目名称:storm-clickhouse,代码行数:17,代码来源:HikariCPConnectionProviderExt.java

示例15: MySQLThreadPool

import com.zaxxer.hikari.HikariConfig; //导入依赖的package包/类
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);
}
 
开发者ID:Lolmewn,项目名称:Stats4,代码行数:26,代码来源:MySQLThreadPool.java


注:本文中的com.zaxxer.hikari.HikariConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。