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


Java HikariDataSource类代码示例

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


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

示例1: Database

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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: setupPool

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例3: testHikariType

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@Test
public void testHikariType() throws SQLException {
	DataSource ds = DataSourceBuilder.create().build(
			DataSourceConfigProperties.builder("pooling2").withPropertySource("test_build.properties").build());
	assertNotNull(ds);

	assertEquals(HikariDataSource.class, ds.getClass());
	assertEquals("jdbc:h2:mem:testdb", ((HikariDataSource) ds).getJdbcUrl());
	assertEquals("sa", ((HikariDataSource) ds).getUsername());

	assertEquals(2, ((HikariDataSource) ds).getMinimumIdle());
	assertEquals(7, ((HikariDataSource) ds).getMaximumPoolSize());

	assertEquals(1234L, ((HikariDataSource) ds).getConnectionTimeout());

	assertEquals(DatabasePlatform.H2.getDriverClassName(), ((HikariDataSource) ds).getDriverClassName());

	assertEquals(DatabasePlatform.H2.getValidationQuery(), ((HikariDataSource) ds).getConnectionTestQuery());

	try (Connection c = ds.getConnection()) {
		assertNotNull(c);
	}
}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:24,代码来源:TestDataSourceBuilder.java

示例4: dataSource

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@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);
}
 
开发者ID:RizkiMufrizal,项目名称:Spring-OAuth2-Custom,代码行数:19,代码来源:DataSourceConfiguration.java

示例5: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例6: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例7: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例8: dataSource

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例9: dataSource

import com.zaxxer.hikari.HikariDataSource; //导入依赖的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

示例10: testDecoratedHikariSpecificPropertiesIsSet

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@Test
public void testDecoratedHikariSpecificPropertiesIsSet() throws Exception {
    EnvironmentTestUtils.addEnvironment(context,
            "spring.datasource.type:" + HikariDataSource.class.getName(),
            "spring.datasource.hikari.catalog:test_catalog");
    context.register(DataSourceAutoConfiguration.class,
            DataSourceDecoratorAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    context.refresh();
    DataSource dataSource = context.getBean(DataSource.class);
    assertThat(dataSource).isNotNull();
    assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
    DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
    assertThat(realDataSource).isInstanceOf(HikariDataSource.class);
    assertThat(((HikariDataSource) realDataSource).getCatalog()).isEqualTo("test_catalog");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:DataSourceDecoratorAutoConfigurationTests.java

示例11: getLastUrlForLastTime

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
public static String getLastUrlForLastTime() {
    String urlForLastTime = null;
    final HikariDataSource mysqlDataSource = DataSource.getMysqlDataSource();
    //从第二张数据表中取出已有所有论文相关指标页面链接
    try (final Connection connection = mysqlDataSource.getConnection()) {
        try (final PreparedStatement preparedStatement = connection.prepareStatement("SELECT URL FROM NT_PAPERS LIMIT 1")) {
            try (ResultSet results = preparedStatement.executeQuery()) {
                while (results.next()) {
                    urlForLastTime = results.getString("URL");
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return urlForLastTime;
}
 
开发者ID:HongChutang,项目名称:NTPaprEng,代码行数:18,代码来源:Helper.java

示例12: testDecoratingHikariDataSourceWithDefaultStrategies

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithDefaultStrategies() throws Exception {
    EnvironmentTestUtils.addEnvironment(context,
            "spring.datasource.type:" + HikariDataSource.class.getName());
    context.register(DataSourceAutoConfiguration.class,
            DataSourceDecoratorAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    context.refresh();

    DataSource dataSource = context.getBean(DataSource.class);
    assertDataSourceOfType(dataSource, HikariDataSource.class);
    FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
    IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
            findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
    assertThat(strategy1).isNotNull();
    assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 15);
    assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 500);

    RetryConnectionAcquiringStrategy strategy2 =
            findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
    assertThat(strategy2).isNotNull();
    assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 2);
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:24,代码来源:FlexyPoolConfigurationTests.java

示例13: testDecoratingHikariDataSourceWithCustomPropertyStrategies

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithCustomPropertyStrategies() throws Exception {
    EnvironmentTestUtils.addEnvironment(context,
            "spring.datasource.type:" + HikariDataSource.class.getName(),
            "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.max-overflow-pool-size:15",
            "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.timeout-millis:500",
            "decorator.datasource.flexy-pool.acquiring-strategy.retry.attempts:5");
    context.register(DataSourceAutoConfiguration.class,
            DataSourceDecoratorAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            HikariConfiguration.class);
    context.refresh();

    DataSource dataSource = context.getBean(DataSource.class);
    FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
    IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
            findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
    assertThat(strategy1).isNotNull();
    assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35);
    assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000);

    RetryConnectionAcquiringStrategy strategy2 =
            findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
    assertThat(strategy2).isNotNull();
    assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5);
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:27,代码来源:FlexyPoolConfigurationTests.java

示例14: createBean

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
private void createBean(ConfigurableListableBeanFactory configurableListableBeanFactory,
    String prefixName, JdbcProperties jdbcProperties) {
  String jdbcUrl = jdbcProperties.getJdbcUrl();
  checkArgument(!Strings.isNullOrEmpty(jdbcUrl), prefixName + " url is null or empty");
  log.info("prefixName is {}, jdbc properties is {}", prefixName, jdbcProperties);

  HikariDataSource hikariDataSource = createHikariDataSource(jdbcProperties);
  DataSourceSpy dataSource = new DataSourceSpy(hikariDataSource);

  DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
  AnnotationTransactionAspect.aspectOf().setTransactionManager(transactionManager);

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

  register(configurableListableBeanFactory, dataSource, prefixName + "DataSource",
      prefixName + "Ds");
  register(configurableListableBeanFactory, jdbcTemplate, prefixName + "JdbcTemplate",
      prefixName + "Jt");
  register(configurableListableBeanFactory, transactionManager, prefixName + "TransactionManager",
      prefixName + "Tx");
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:22,代码来源:LocDataSourceAutoConfiguration.java

示例15: testDataSource

import com.zaxxer.hikari.HikariDataSource; //导入依赖的package包/类
@Test
public void testDataSource() throws SQLException {

	assertNotNull(dataSource);

	assertTrue(dataSource instanceof HikariDataSource);

	try (Connection c = dataSource.getConnection()) {
		assertNotNull(c);

		try (ResultSet rs = c.createStatement().executeQuery("select str from testx where key=1")) {
			rs.next();
			assertEquals("One", rs.getString(1));
		}
	}

}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:18,代码来源:TestEnableDataSourceDataContext.java


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