本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setPoolName方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setPoolName方法的具体用法?Java HikariConfig.setPoolName怎么用?Java HikariConfig.setPoolName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.zaxxer.hikari.HikariConfig
的用法示例。
在下文中一共展示了HikariConfig.setPoolName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例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: 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);
}
示例4: getDataSourceFromConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static HikariDataSource getDataSourceFromConfig(
Config conf
, MetricRegistry metricRegistry
, HealthCheckRegistry healthCheckRegistry) {
HikariConfig jdbcConfig = new HikariConfig();
jdbcConfig.setPoolName(conf.getString("poolName"));
jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
jdbcConfig.setUsername(conf.getString("username"));
jdbcConfig.setPassword(conf.getString("password"));
jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));
// Add HealthCheck
jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);
// Add Metrics
jdbcConfig.setMetricRegistry(metricRegistry);
return new HikariDataSource(jdbcConfig);
}
示例5: initConnection
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void initConnection() throws Exception {
HikariConfig config = new HikariConfig();
config.setPoolName("Parties");
config.setJdbcUrl(Variables.storage_settings_mysql_url);
config.setUsername(Variables.storage_settings_mysql_username);
config.setPassword(Variables.storage_settings_mysql_password);
config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);
// Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks
hikariDataSource = new HikariDataSource(config);
}
示例6: 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);
}
示例7: testConnection
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void testConnection(String url, String username, String password) throws Exception {
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setPoolName("easyrecPool");
config.addDataSourceProperty("url", url);
HikariDataSource ds = new HikariDataSource(config);
setDataSource(ds);
sqlScriptService.setDataSource(ds);
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(ds, callback);
}
示例8: build
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
final Properties properties = new Properties();
for (final Map.Entry<String, String> property : this.properties.entrySet()) {
properties.setProperty(property.getKey(), property.getValue());
}
final HikariConfig config = new HikariConfig();
config.setMetricRegistry(metricRegistry);
if (healthCheckRegistry != null) {
config.setHealthCheckRegistry(healthCheckRegistry);
}
config.setAutoCommit(autoCommit);
config.setDataSourceProperties(properties);
if (datasourceClassName != null) {
config.setDataSourceClassName(datasourceClassName);
} else {
config.setDriverClassName(driverClass);
}
config.setMaximumPoolSize(maxSize);
minSize.ifPresent(config::setMinimumIdle);
config.setPoolName(name);
config.setUsername(user);
config.setPassword(user != null && password == null ? "" : password);
return new HikariManagedPooledDataSource(config);
}
示例9: hikariConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig hikariConfig() {
HikariConfig config = new HikariConfig();
config.setDriverClassName(driverClassName);
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setPoolName(poolName);
config.setMaximumPoolSize(20);
config.setMinimumIdle(2);
config.setIdleTimeout(TimeUnit.SECONDS.toMillis(30));
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return config;
}
示例10: 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();
}
}
示例11: HikariCPComponent
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariCPComponent(OptionMap options) {
config = new HikariConfig();
if (options.containsKey("uri")) config.setJdbcUrl(options.getString("uri"));
if (options.containsKey("username")) config.setUsername(options.getString("username"));
if (options.containsKey("password")) config.setPassword(options.getString("password"));
if (options.containsKey("autoCommit?")) config.setAutoCommit(options.getBoolean("autoCommit?"));
if (options.containsKey("connTimeout")) config.setConnectionTimeout(options.getLong("connTimeout"));
if (options.containsKey("idleTimeout")) config.setIdleTimeout(options.getLong("idleTimeout"));
if (options.containsKey("maxLifetime")) config.setMaxLifetime(options.getLong("maxLifetime"));
if (options.containsKey("maxPoolSize")) config.setMaximumPoolSize(options.getInt("maxPoolSize"));
if (options.containsKey("minIdle")) config.setMinimumIdle(options.getInt("minIdle"));
if (options.containsKey("poolName")) config.setPoolName(options.getString("uri"));
}
示例12: getCommonConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig getCommonConfig() {
final HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("defaultDatabase");
hikariConfig.setDriverClassName(driverClassName);
hikariConfig.setMaximumPoolSize(maximumPoolSize);
hikariConfig.setConnectionTimeout(TimeUnit.SECONDS.toMillis(5));
if (runtimeEnvironmentUtil.isProductionEnvironment()) {
hikariConfig.setInitializationFailFast(false);
}
return hikariConfig;
}
示例13: 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);
}
示例14: toHikariConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariConfig toHikariConfig() {
HikariConfig config = new HikariConfig();
// PG: config.setDataSourceClassName(PG_PLAIN_DS_CLASS_NAME);
config.setDataSourceClassName(MYSQL_PLAIN_DS_CLASS_NAME);
// DataSource config. recommended over jdbcUrl
// https://github.com/brettwooldridge/HikariCP#popular-datasource-class-names
// config.setJdbcUrl(String.format("jdbc:pgsql://%s:%d/%s",
// getDbHost(), getDbPort(), getDbName()));
config.setPoolName(getPoolName());
config.setUsername(getDbUser());
config.setPassword(getDbPassword());
config.setMaximumPoolSize(getMaxPoolSize());
// These below are specific to our PostgreSQL DB driver:
// https://github.com/impossibl/pgjdbc-ng#configuration
// config.addDataSourceProperty("user", getDbUser());
// config.addDataSourceProperty("password", getDbPassword());
// config.addDataSourceProperty("database", getDbName());
// config.addDataSourceProperty("port", getDbPort());
// config.addDataSourceProperty("host", getDbHost());
// PG: And these for the org.postgresql.ds.PGSimpleDataSource
// PG: config.addDataSourceProperty(PGProperty.USER.getName(), getDbUser());
// PG: config.addDataSourceProperty(PGProperty.PASSWORD.getName(), getDbPassword());
// PG: The PGSimpleDataSource class seems not to have these properties (names), therefore
// PG: below as proper hardcoded strings.
// PG: config.addDataSourceProperty(PGProperty.PG_HOST.getName(), getDbHost());
// PG: config.addDataSourceProperty(PGProperty.PG_PORT.getName(), getDbPort());
// PG: config.addDataSourceProperty(PGProperty.PG_DBNAME.getName(), getDbName());
// PG: config.addDataSourceProperty("databaseName", getDbName());
// PG: config.addDataSourceProperty("portNumber", getDbPort());
// PG: config.addDataSourceProperty("serverName", getDbHost());
config.addDataSourceProperty("url", buildMySqlDbUrl());
getDsProperties().forEach((k, v) ->
config.addDataSourceProperty(k, String.valueOf(v))
);
return config;
}
示例15: DefaultDataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private DefaultDataSource(final Properties properties) {
log.info(">>>>> Initializing DataSource....");
HikariConfig config = new HikariConfig();
ddlResources = ConfigurationHelper.getArraySystemThenEnvProperty(CONFIG_DS_DDL, DEFAULT_DS_DDL, properties);
config.setMetricRegistry(SharedMetricsRegistry.getInstance());
config.setDataSourceClassName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_CLASS, DEFAULT_DS_CLASS, properties));
// config.setDriverClassName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_CLASS, DEFAULT_DS_CLASS, properties));
config.setJdbcUrl(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_URL, DEFAULT_DS_URL, properties));
config.addDataSourceProperty("url",ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_URL, DEFAULT_DS_URL, properties));
config.addDataSourceProperty("user", ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_USER, DEFAULT_DS_USER, properties));
config.addDataSourceProperty("password", ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_PW, DEFAULT_DS_PW, properties));
config.setUsername(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_USER, DEFAULT_DS_USER, properties));
config.setPassword(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_PW, DEFAULT_DS_PW, properties));
// config.addDataSourceProperty("cachePrepStmts", "" + ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_CACHEDPS, DEFAULT_DS_CACHEDPS, properties));
// config.addDataSourceProperty("prepStmtCacheSize", "" + ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCACHEDPS, DEFAULT_DS_MAXCACHEDPS, properties));
// config.addDataSourceProperty("prepStmtCacheSqlLimit", "" + ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCACHEDPS, DEFAULT_DS_MAXCACHEDPS, properties));
config.setMaximumPoolSize(ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCONNS, DEFAULT_DS_MAXCONNS, properties));
config.setMinimumIdle(ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MINCONNS, DEFAULT_DS_MINCONNS, properties));
config.setConnectionTestQuery(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_TESTSQL, DEFAULT_DS_TESTSQL, properties));
config.setConnectionTimeout(ConfigurationHelper.getLongSystemThenEnvProperty(CONFIG_DS_CONNTIMEOUT, DEFAULT_DS_CONNTIMEOUT, properties));
config.setAutoCommit(ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_AUTOCOMMIT, DEFAULT_DS_AUTOCOMMIT, properties));
config.setRegisterMbeans(ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_MBEANS, DEFAULT_DS_MBEANS, properties));
config.setPoolName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_NAME, DEFAULT_DS_NAME, properties));
config.setThreadFactory(JMXManagedThreadFactory.newThreadFactory("HikariPool-" + config.getPoolName(), true));
final StringBuilder b = new StringBuilder("\n\t========================\n\tDataSource\n\t========================");
b.append("\n\tURL:").append(config.getJdbcUrl());
b.append("\n\tDS Class:").append(config.getDataSourceClassName());
b.append("\n\tUser:").append(config.getUsername());
b.append("\n\t========================\n");
log.info(b.toString());
schedulerObjectName = JMXHelper.objectName("com.heliosapm.streams.tsdb.listener:service=Scheduler,name=JDBCConnectionPool");
scheduler = new JMXManagedScheduler(schedulerObjectName, "JDBCConnectionPool", 2, true);
//config.setScheduledExecutorService(scheduler);
ds = new HikariDataSource(config);
sqlWorker = SQLWorker.getInstance(ds);
startServers(properties);
runDDL(properties);
log.info("<<<<< DataSource Initialized.");
}