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


Java HikariConfig.setConnectionTestQuery方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: ExtensionHikariConnectionContext

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

示例6: 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);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:18,代码来源:DatabaseTest.java

示例7: 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);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:27,代码来源:DatabaseTest.java

示例8: start

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void start() {
	HikariConfig config = new HikariConfig();
	config.setJdbcUrl(this.conURL);
	config.setUsername(this.username);
	config.setPassword(this.password);
	config.setDriverClassName(this.driverName);
	config.setMaximumPoolSize(max);
	config.setMinimumIdle(min);
	if (this.testSql != null && this.testSql.trim().length() > 0) {
		config.setConnectionTestQuery(testSql);
	}
	config.setPoolName("HikariCPPool[" + username + "]");
	config.addDataSourceProperty("cachePrepStmts", AppProperties.get("HikariCPPool_cachePrepStmts", "true"));
	config.addDataSourceProperty("prepStmtCacheSize", AppProperties.get("HikariCPPool_prepStmtCacheSize", "250"));
	config.addDataSourceProperty("prepStmtCacheSqlLimit",
			AppProperties.get("HikariCPPool_prepStmtCacheSqlLimit", "2048"));
	config.setConnectionTimeout(AppProperties.getAsInt("HikariCPPool_connectionTimeout", 30000));
	config.setIdleTimeout(AppProperties.getAsInt("HikariCPPool_idleTimeout", 600000));
	config.setMaxLifetime(AppProperties.getAsInt("HikariCPPool_maxLifetime", 1800000));
	// HikariDataSource ds = new HikariDataSource(config);
	// this.datasource=ds.getDataSource();
	this.datasource = new HikariDataSource(config);
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:25,代码来源:HikariCPPool.java

示例9: getDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariDataSource getDataSource(String jdbcUrl, int poolSize) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(jdbcUrl);
    hikariConfig.setConnectionTestQuery("SELECT 1");
    hikariConfig.setMinimumIdle(1);
    hikariConfig.setMaximumPoolSize(poolSize);

    return new HikariDataSource(hikariConfig);
}
 
开发者ID:testcontainers,项目名称:testcontainers-java-module-mariadb,代码行数:10,代码来源:JDBCDriverTest.java

示例10: get

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public DataSource get() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(baseConfig.getJdbcUrl());
    config.setUsername(baseConfig.getUsername());
    config.setPassword(baseConfig.getPassword());
    config.setMinimumIdle(baseConfig.getMinimumIdle());
    config.setMaximumPoolSize(baseConfig.getMaximumPoolSize());
    config.setConnectionTestQuery(baseConfig.getConnectionTestQuery());
    config.setIdleTimeout(baseConfig.getIdleTimeout());
    config.setConnectionTimeout(baseConfig.getConnectionTimeout());

    return new HikariDataSource(config);
}
 
开发者ID:Twister915,项目名称:pl,代码行数:15,代码来源:ConfiguredDataSourceProvider.java

示例11: initialize

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
/**
 * Called in onEnable, initializes the pool and configures it and opens the first connection to spawn the pool.
 */
public static void initialize(Plugin plugin, GlobalConfig globalConfig) {
    try {
        DB.plugin = plugin;
        timingManager = TimingManager.of(plugin);
        HikariConfig config = new HikariConfig();
        config.setPoolName("VGL-Client");

        config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
        config.addDataSourceProperty("url", globalConfig.persistence.url);
        config.addDataSourceProperty("user", globalConfig.persistence.user);
        config.addDataSourceProperty("password", globalConfig.persistence.pass);
        config.addDataSourceProperty("cachePrepStmts", true);
        config.addDataSourceProperty("prepStmtCacheSize", 250);
        config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
        config.addDataSourceProperty("useServerPrepStmts", true);
        config.addDataSourceProperty("cacheCallableStmts", true);
        config.addDataSourceProperty("cacheResultSetMetadata", true);
        config.addDataSourceProperty("cacheServerConfiguration", true);
        config.addDataSourceProperty("useLocalSessionState", true);
        config.addDataSourceProperty("elideSetAutoCommits", true);
        config.addDataSourceProperty("alwaysSendSetIsolation", false);

        config.setConnectionTestQuery("SELECT 1");
        config.setInitializationFailFast(true);
        config.setMinimumIdle(3);
        config.setMaximumPoolSize(5);

        pooledDataSource = new HikariDataSource(config);
        pooledDataSource.setTransactionIsolation("TRANSACTION_READ_COMMITTED");

        Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new AsyncDbQueue(), 0, 1);

        log.info("Started database pool to " + globalConfig.persistence.url);
    } catch (Exception ex) {
        pooledDataSource = null;
        log.severe("Error creating database pool");
        ex.printStackTrace();
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:43,代码来源:DB.java

示例12: setupPool

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void setupPool() {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setUsername(username);
    config.setPassword(password);
    config.setMinimumIdle(minimumIdle);
    config.setMaximumPoolSize(poolSize);
    config.setConnectionTimeout(connectionTimeout);
    config.setConnectionTestQuery(testQuery);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    dataSource = new HikariDataSource(config);
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:16,代码来源:ConnectionPoolManager.java

示例13: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public DataSource dataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName(driverClassName());
    config.setJdbcUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.setMinimumIdle(minIdle);
    config.setMaximumPoolSize(maxPoolSize);
    if (validation) {
        config.setConnectionTestQuery(validationQuery());
    }
    config.setDataSourceProperties(props);
    return new HikariDataSource(config);
}
 
开发者ID:jkazama,项目名称:sample-boot-micro,代码行数:15,代码来源:OrmDataSourceProperties.java

示例14: SQLite

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public SQLite(Jecon jecon) {
	this.config = jecon.getConfigStruct();

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

	HikariConfig hikariConfig = new HikariConfig();
	hikariConfig.setDriverClassName("org.sqlite.JDBC");
	hikariConfig.setConnectionTestQuery("/* Jecon */SELECT 1");

	super.setup(jecon, hikariConfig);
}
 
开发者ID:HimaJyun,项目名称:Jecon,代码行数:12,代码来源:SQLite.java

示例15: init

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void init() {
    HikariConfig config = new HikariConfig();
    config.setPoolName("luckperms");

    appendConfigurationInfo(config);
    appendProperties(config, this.configuration);

    config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
    config.setMinimumIdle(this.configuration.getMinIdleConnections());
    config.setMaxLifetime(this.configuration.getMaxLifetime());
    config.setConnectionTimeout(this.configuration.getConnectionTimeout());

    // 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

    // The drivers are really old in some of the older Spigot binaries, so Connection#isValid doesn't work.
    config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1");

    try {
        // don't perform any initial connection validation - we subsequently call #getConnection
        // to setup the schema anyways
        config.setInitializationFailTimeout(-1);
    } catch (NoSuchMethodError e) {
        //noinspection deprecation
        config.setInitializationFailFast(false);
    }


    this.hikari = new HikariDataSource(config);
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:32,代码来源:HikariConnectionFactory.java


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