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