本文整理匯總了Java中com.alibaba.druid.pool.DruidDataSource.setValidationQueryTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java DruidDataSource.setValidationQueryTimeout方法的具體用法?Java DruidDataSource.setValidationQueryTimeout怎麽用?Java DruidDataSource.setValidationQueryTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.druid.pool.DruidDataSource
的用法示例。
在下文中一共展示了DruidDataSource.setValidationQueryTimeout方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configDruid
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
private void configDruid(DruidDataSource dataSource, DruidProperties properties) {
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
if (properties.getInitialSize() > 0) {
dataSource.setInitialSize(properties.getInitialSize());
}
if (properties.getMinIdle() > 0) {
dataSource.setMinIdle(properties.getMinIdle());
}
if (properties.getMaxActive() > 0) {
dataSource.setMaxActive(properties.getMaxActive());
}
if (properties.getMaxWait() > 0 ){
dataSource.setMaxWait(properties.getMaxWait());
}
if (properties.getTimeBetweenEvictionRunsMillis() > 0l){
dataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis());
}
if (properties.getMaxPoolPreparedStatementPerConnectionSize() > 0 ){
dataSource.setMaxPoolPreparedStatementPerConnectionSize(properties.getMaxPoolPreparedStatementPerConnectionSize());
}
if (properties.getValidationQueryTimeout() > 0 ){
dataSource.setValidationQueryTimeout(properties.getValidationQueryTimeout());
}
if (properties.getMinEvictableIdleTimeMillis() > 0l){
dataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis());
}
dataSource.setValidationQuery(properties.getValidationQuery());
dataSource.setTestOnReturn(properties.getTestOnReturn());
dataSource.setTestOnBorrow(properties.isTestOnBorrow());
dataSource.setTestWhileIdle(properties.getTestWhileIdle());
dataSource.setPoolPreparedStatements(properties.getPoolPreparedStatements());
dataSource.setConnectProperties(properties.getConnectionProperties());
try {
dataSource.setFilters(properties.getFilters());
} catch (SQLException e) {
throw new IllegalArgumentException("please check your spring.datasource.druid.filters property.", e);
}
}
示例2: initialize
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
public void initialize() throws SQLException{
if (this.url == null) {
throw new SQLException("DBPool could not be created: DB URL cannot be null");
}
if (this.driver == null) {
throw new SQLException("DBPool driver could not be created: DB driver class name cannot be null!");
}
if (this.maxConnections < 0) {
throw new SQLException("DBPool maxConnectins could not be created: Max connections must be greater than zero!");
}
datasource = new DruidDataSource();
try{
datasource.setDriverClassName(this.driver);
} catch (Exception e) {
logger.error("Problem setting driver class name on datasource: {}" + e.getMessage(), e);
}
datasource.setUrl(this.url);
datasource.setUsername(this.user);
datasource.setPassword(this.password);
datasource.setMaxActive(this.maxConnections);
datasource.setMinIdle(1);
datasource.setMaxWait(0);
datasource.setMaxPoolPreparedStatementPerConnectionSize(this.DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION);
if (this.validationQuery != null) {
datasource.setValidationQuery(this.validationQuery);
if(!this.validateOnCheckout)
datasource.setTestOnReturn(true);
else
datasource.setTestOnBorrow(true);
datasource.setValidationQueryTimeout(this.idleConnectionValidationSeconds);
}
}
示例3: createDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
public DruidDataSource createDataSource() throws SQLException {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(driverClassName);
dataSource.setConnectProperties(connectProperties);
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
dataSource.setMaxActive(maxActive);
dataSource.setMaxWait(maxWait);
dataSource.setFilters(filters);
dataSource.setDefaultAutoCommit(defaultAutoCommit);
dataSource.setTimeBetweenConnectErrorMillis(timeBetweenConnectErrorMillis);
dataSource.setValidationQuery(validationQuery);
dataSource.setValidationQueryTimeout(validationQueryTimeout);
dataSource.setTestWhileIdle(testWhileIdle);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnReturn(testOnReturn);
dataSource.setPoolPreparedStatements(poolPreparedStatements);
dataSource.setClearFiltersEnable(clearFiltersEnable);
dataSource.setDefaultReadOnly(defaultReadOnly);
dataSource.setAsyncCloseConnectionEnable(asyncCloseConnectionEnable);
dataSource.setConnectionErrorRetryAttempts(connectionErrorRetryAttempts);
dataSource.setBreakAfterAcquireFailure(breakAfterAcquireFailure);
dataSource.setDupCloseLogEnable(dupCloseLogEnable);
dataSource.setEnable(enable);
dataSource.setLogAbandoned(logAbandoned);
dataSource.setLogDifferentThread(logDifferentThread);
dataSource.setLoginTimeout(loginTimeout);
dataSource.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
dataSource.setQueryTimeout(queryTimeout);
dataSource.setFailFast(failFast);
dataSource.setMaxCreateTaskCount(maxCreateTaskCount);
dataSource.setRemoveAbandoned(removeAbandoned);
dataSource.setRemoveAbandonedTimeoutMillis(removeAbandonedTimeoutMillis);
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
dataSource.setNotFullTimeoutRetryCount(notFullTimeoutRetryCount);
dataSource.setTimeBetweenLogStatsMillis(timeBetweenLogStatsMillis);
return dataSource;
}