本文整理汇总了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();
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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));
}
}
}