本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setDataSourceClassName方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setDataSourceClassName方法的具体用法?Java HikariConfig.setDataSourceClassName怎么用?Java HikariConfig.setDataSourceClassName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.zaxxer.hikari.HikariConfig
的用法示例。
在下文中一共展示了HikariConfig.setDataSourceClassName方法的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: 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);
}
示例3: 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);
}
示例4: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "shutdown")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource() {
log.debug("Configuring Datasource");
if (dataSourcePropertyResolver.getProperty("url") == null
&& dataSourcePropertyResolver.getProperty("databaseName") == null) {
log.error(
"Your database connection pool configuration is incorrect! The application"
+ " cannot start. Please check your Spring profile, current profiles are: {}",
Arrays.toString(env.getActiveProfiles()));
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) {
config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName"));
config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName"));
} else {
config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url"));
}
config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username"));
config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password"));
if (metricRegistry != null) {
config.setMetricRegistry(metricRegistry);
}
return new HikariDataSource(config);
}
示例5: appendConfigurationInfo
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
protected void appendConfigurationInfo(HikariConfig config) {
String address = this.configuration.getAddress();
String[] addressSplit = address.split(":");
address = addressSplit[0];
String port = addressSplit.length > 1 ? addressSplit[1] : "5432";
String database = this.configuration.getDatabase();
String username = this.configuration.getUsername();
String password = this.configuration.getPassword();
config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
config.addDataSourceProperty("serverName", address);
config.addDataSourceProperty("portNumber", port);
config.addDataSourceProperty("databaseName", database);
config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password);
}
示例6: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
log.debug("Configuring Heroku Datasource");
String herokuUrl = System.getenv("JDBC_DATABASE_URL");
if (herokuUrl != null) {
HikariConfig config = new HikariConfig();
//MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
}
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", herokuUrl);
return new HikariDataSource(config);
} else {
throw new ApplicationContextException("Heroku database URL is not configured, you must set $JDBC_DATABASE_URL");
}
}
示例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: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
log.debug("Configuring Datasource");
if (dataSourceProperties.getUrl() == null) {
log.error("Your database connection pool configuration is incorrect! The application" +
" cannot start. Please check your Spring profile, current profiles are: {}",
Arrays.toString(env.getActiveProfiles()));
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", dataSourceProperties.getUrl());
if (dataSourceProperties.getUsername() != null) {
config.addDataSourceProperty("user", dataSourceProperties.getUsername());
} else {
config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
}
if (dataSourceProperties.getPassword() != null) {
config.addDataSourceProperty("password", dataSourceProperties.getPassword());
} else {
config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
}
if (metricRegistry != null) {
config.setMetricRegistry(metricRegistry);
}
return new HikariDataSource(config);
}
示例9: 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);
}
示例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: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
log.debug("Configuring Heroku Datasource");
String herokuUrl = System.getenv("JDBC_DATABASE_URL");
if (herokuUrl != null) {
HikariConfig config = new HikariConfig();
//MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
}
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", herokuUrl);
return new HikariDataSource(config);
} else {
throw new ApplicationContextException("Heroku database URL is not configured, you must set $JDBC_DATABASE_URL");
}
}
示例12: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, LeagueProperties leagueProperties) {
log.debug("Configuring Datasource");
if (dataSourceProperties.getUrl() == null) {
log.error("Your database connection pool configuration is incorrect! The application" +
" cannot start. Please check your Spring profile, current profiles are: {}",
Arrays.toString(env.getActiveProfiles()));
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", dataSourceProperties.getUrl());
if (dataSourceProperties.getUsername() != null) {
config.addDataSourceProperty("user", dataSourceProperties.getUsername());
} else {
config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
}
if (dataSourceProperties.getPassword() != null) {
config.addDataSourceProperty("password", dataSourceProperties.getPassword());
} else {
config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
}
//MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
config.addDataSourceProperty("cachePrepStmts", leagueProperties.getDatasource().isCachePrepStmts());
config.addDataSourceProperty("prepStmtCacheSize", leagueProperties.getDatasource().getPrepStmtCacheSize());
config.addDataSourceProperty("prepStmtCacheSqlLimit", leagueProperties.getDatasource().getPrepStmtCacheSqlLimit());
}
if (metricRegistry != null) {
config.setMetricRegistry(metricRegistry);
}
if (healthCheckRegistry != null) {
config.setHealthCheckRegistry(healthCheckRegistry);
}
return new HikariDataSource(config);
}
示例13: appendConfigurationInfo
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
protected void appendConfigurationInfo(HikariConfig config) {
String address = this.configuration.getAddress();
String[] addressSplit = address.split(":");
address = addressSplit[0];
String port = addressSplit.length > 1 ? addressSplit[1] : "3306";
config.setDataSourceClassName(getDriverClass());
config.addDataSourceProperty("serverName", address);
config.addDataSourceProperty("port", port);
config.addDataSourceProperty("databaseName", this.configuration.getDatabase());
config.setUsername(this.configuration.getUsername());
config.setPassword(this.configuration.getPassword());
}
示例14: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
log.debug("Configuring Datasource");
if (dataSourceProperties.getUrl() == null) {
log.error("Your database connection pool configuration is incorrect! The application" +
" cannot start. Please check your Spring profile, current profiles are: {}",
Arrays.toString(env.getActiveProfiles()));
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", dataSourceProperties.getUrl());
if (dataSourceProperties.getUsername() != null) {
config.addDataSourceProperty("user", dataSourceProperties.getUsername());
} else {
config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
}
if (dataSourceProperties.getPassword() != null) {
config.addDataSourceProperty("password", dataSourceProperties.getPassword());
} else {
config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
}
//MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
}
if (metricRegistry != null) {
config.setMetricRegistry(metricRegistry);
}
return new HikariDataSource(config);
}
示例15: 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;
}