当前位置: 首页>>代码示例>>Java>>正文


Java DruidDataSource.setValidationQuery方法代码示例

本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSource.setValidationQuery方法的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSource.setValidationQuery方法的具体用法?Java DruidDataSource.setValidationQuery怎么用?Java DruidDataSource.setValidationQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.druid.pool.DruidDataSource的用法示例。


在下文中一共展示了DruidDataSource.setValidationQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mafMasterDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name = ConfigConstant.NAME_DS_MASTER)
@Primary
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_MASTER)
public DataSource mafMasterDataSource() {
    logger.info("----- MAFIA master data source INIT -----");
    DruidDataSource ds = new DruidDataSource();
    try {
        ds.setFilters(env.getProperty("ds.filters"));
    } catch (SQLException e) {
        logger.warn("Data source set filters ERROR:", e);
    }
    ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
    ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
    ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
    ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
    ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
    ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
    ds.setValidationQuery(env.getProperty("ds.validationQuery"));
    ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
    ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
    ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
    ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
    ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
    return ds;
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:26,代码来源:DsMasterConfig.java

示例2: logDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource logDataSource() throws SQLException, DESException {
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setDriverClassName(dbConfigProperties.getDriveClass());
    druidDataSource.setUrl(dbConfigProperties.getLogUrl());
    druidDataSource.setUsername(dbConfigProperties.getLogUsername());
    druidDataSource.setPassword(dbConfigProperties.getLogPassword());
    druidDataSource.setInitialSize(dbConfigProperties.getInitialSize());
    druidDataSource.setMinIdle(dbConfigProperties.getMinIdle());
    druidDataSource.setMaxActive(dbConfigProperties.getMaxActive());
    druidDataSource.setMaxWait(dbConfigProperties.getMaxWait());
    druidDataSource.setTimeBetweenEvictionRunsMillis(dbConfigProperties.getTimeBetweenEvictionRunsMillis());
    druidDataSource.setMinEvictableIdleTimeMillis(dbConfigProperties.getMinEvictableIdleTimeMillis());
    druidDataSource.setValidationQuery(dbConfigProperties.getValidationQuery());
    druidDataSource.setTestWhileIdle(dbConfigProperties.getTestWhileIdle());
    druidDataSource.setTestOnBorrow(dbConfigProperties.getTestOnBorrow());
    druidDataSource.setTestOnReturn(dbConfigProperties.getTestOnReturn());
    druidDataSource.setPoolPreparedStatements(dbConfigProperties.getPoolPreparedStatements());
    druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(dbConfigProperties.getMaxPoolPreparedStatementPerConnectionSize());
    druidDataSource.setFilters(dbConfigProperties.getFilters());
    return druidDataSource;
}
 
开发者ID:DomKing,项目名称:busi-support,代码行数:23,代码来源:LogDatabaseConfig.java

示例3: userDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
/**
 * 使用@Primary注解主数据源
 */
@Bean(name = "userDataSource")
@Primary
public DataSource userDataSource() {
	DruidDataSource dataSource = new DruidDataSource();
	dataSource.setDriverClassName(driverClass);
	dataSource.setUrl(url);
	dataSource.setUsername(user);
	dataSource.setPassword(password);
	//configuration
	dataSource.setInitialSize(initialSize);
	dataSource.setMinIdle(minIdle);
	dataSource.setMaxActive(maxActive);
	dataSource.setMaxWait(maxWait);
	dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
	dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
	dataSource.setValidationQuery(validationQuery);
	dataSource.setTestWhileIdle(testWhileIdle);
	dataSource.setTestOnBorrow(testOnBorrow);
	dataSource.setTestOnReturn(testOnReturn);
	dataSource.setPoolPreparedStatements(poolPreparedStatements);
	dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
	return dataSource;
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:27,代码来源:UserDataSourceConfig.java

示例4: studentDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name = "studentDataSource")
public DataSource studentDataSource() {
	DruidDataSource dataSource = new DruidDataSource();
	dataSource.setUrl(studentUrl);
	dataSource.setUsername(studentUser);
	dataSource.setPassword(studentPassword);
	dataSource.setDriverClassName(studentDriverClass);
	//configuration
	dataSource.setInitialSize(initialSize);
	dataSource.setMinIdle(minIdle);
	dataSource.setMaxActive(maxActive);
	dataSource.setMaxWait(maxWait);
	dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
	dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
	dataSource.setValidationQuery(validationQuery);
	dataSource.setTestWhileIdle(testWhileIdle);
	dataSource.setTestOnBorrow(testOnBorrow);
	dataSource.setTestOnReturn(testOnReturn);
	dataSource.setPoolPreparedStatements(poolPreparedStatements);
	dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
	return dataSource;
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:23,代码来源:StudentDataSourceConfig.java

示例5: init

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
/**
 * 初始化操作
 *
 * @param modelName 模块名称
 * @param txConfig  配置信息
 */
@Override
public void init(String modelName, TccConfig txConfig) {
    dataSource = new DruidDataSource();
    final TccDbConfig tccDbConfig = txConfig.getTccDbConfig();
    dataSource.setUrl(tccDbConfig.getUrl());
    dataSource.setDriverClassName(tccDbConfig.getDriverClassName());
    dataSource.setUsername(tccDbConfig.getUsername());
    dataSource.setPassword(tccDbConfig.getPassword());
    dataSource.setInitialSize(tccDbConfig.getInitialSize());
    dataSource.setMaxActive(tccDbConfig.getMaxActive());
    dataSource.setMinIdle(tccDbConfig.getMinIdle());
    dataSource.setMaxWait(tccDbConfig.getMaxWait());
    dataSource.setValidationQuery(tccDbConfig.getValidationQuery());
    dataSource.setTestOnBorrow(tccDbConfig.getTestOnBorrow());
    dataSource.setTestOnReturn(tccDbConfig.getTestOnReturn());
    dataSource.setTestWhileIdle(tccDbConfig.getTestWhileIdle());
    dataSource.setPoolPreparedStatements(tccDbConfig.getPoolPreparedStatements());
    dataSource.setMaxPoolPreparedStatementPerConnectionSize(tccDbConfig.getMaxPoolPreparedStatementPerConnectionSize());
    this.tableName = RepositoryPathUtils.buildDbTableName(modelName);
    executeUpdate(SqlHelper.buildCreateTableSql(tccDbConfig.getDriverClassName(), tableName));
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:28,代码来源:JdbcCoordinatorRepository.java

示例6: createDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
protected DataSource createDataSource() throws SQLException {
  // special
  DruidDataSource datasource = new DruidDataSource();
  datasource.setUrl(commonProperties.getUrl());
  datasource.setUsername(commonProperties.getUsername());
  datasource.setPassword(commonProperties.getPassword());
  // common
  datasource.setDriverClassName(commonProperties.getDriverClassName());
  datasource.setInitialSize(commonProperties.getInitialSize());
  datasource.setMinIdle(commonProperties.getMinIdle());
  datasource.setMaxActive(commonProperties.getMaxActive());
  datasource.setMaxWait(commonProperties.getMaxWait());
  datasource
      .setTimeBetweenEvictionRunsMillis(commonProperties.getTimeBetweenEvictionRunsMillis());
  datasource.setMinEvictableIdleTimeMillis(commonProperties.getMinEvictableIdleTimeMillis());
  datasource.setValidationQuery(commonProperties.getValidationQuery());
  datasource.setTestWhileIdle(commonProperties.isTestWhileIdle());
  datasource.setTestOnBorrow(commonProperties.isTestOnBorrow());
  datasource.setTestOnReturn(commonProperties.isTestOnReturn());
  datasource.setPoolPreparedStatements(commonProperties.isPoolPreparedStatements());
  datasource.setMaxPoolPreparedStatementPerConnectionSize(
      commonProperties.getMaxPoolPreparedStatementPerConnectionSize());
  datasource.setFilters(commonProperties.getFilters());
  datasource.setConnectionProperties(commonProperties.getConnectionProperties());
  return datasource;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:27,代码来源:SingleDataSourceConfig.java

示例7: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean     //声明其为Bean实例  
@Primary  //在同样的DataSource中,首先使用被标注的DataSource  
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();

    datasource.setUrl(this.dbUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);

    //configuration  
    datasource.setInitialSize(initialSize);
    datasource.setMinIdle(minIdle);
    datasource.setMaxActive(maxActive);
    datasource.setMaxWait(maxWait);
    datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    datasource.setValidationQuery(validationQuery);
    datasource.setTestWhileIdle(testWhileIdle);
    datasource.setTestOnBorrow(testOnBorrow);
    datasource.setTestOnReturn(testOnReturn);
    datasource.setPoolPreparedStatements(poolPreparedStatements);
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
        logger.error("druid configuration initialization filter", e);
    }
    datasource.setConnectionProperties(connectionProperties);

    return datasource;
}
 
开发者ID:wooui,项目名称:springboot-training,代码行数:33,代码来源:DruidDBConfig.java

示例8: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(initMethod="init",destroyMethod="close")
public DataSource dataSource(){
    DruidDataSource ds = new DruidDataSource();
    ds.setUrl(config.getUrl());
    ds.setUsername(config.getUsername());
    ds.setPassword(config.getPassword());
    ds.setInitialSize(ds.getInitialSize());
    ds.setMinIdle(config.getMinIdle());
    ds.setMaxActive(config.getMaxActive());
    ds.setMaxWait(config.getMaxWait());
    ds.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis()); // 关闭检测间隔 毫秒
    ds.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis()); // 一个连接的最小生存时间
    ds.setValidationQuery("SELECT 'x'");
    ds.setTestWhileIdle(config.isTestWhileIdle());
    ds.setTestOnBorrow(config.isTestOnBorrow());
    ds.setTestOnReturn(config.isTestOnReturn());
    ds.setPoolPreparedStatements(config.isPoolPreparedStatements());
    ds.setMaxPoolPreparedStatementPerConnectionSize(config.getMaxPoolPreparedStatementPerConnectionSize());
    ds.setRemoveAbandoned(config.isRemoveAbandoned());
    ds.setRemoveAbandonedTimeout(config.getRemoveAbandonedTimeout());
    ds.setLogAbandoned(config.isLogAbandoned());
    ds.setTimeBetweenLogStatsMillis(config.getTimeBetweenLogStatsMillis());
    ds.setPhyTimeoutMillis(config.getPhyTimeoutMillis());
    ds.setMaxEvictableIdleTimeMillis(config.getMaxEvictableIdleTimeMillis());
    ds.setDbType("mysql");
    try {
        ds.setFilters("stat,slf4j");
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return ds ; 
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:33,代码来源:DatabaseConfig.java

示例9: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource() throws SQLException {
    if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) {
        System.out.println("Your database connection pool configuration is incorrect!"
                + " Please check your Spring profile, current profiles are:"
                + Arrays.toString(environment.getActiveProfiles()));
        throw new ApplicationContextException(
                "Database connection pool is not configured correctly");
    }
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
    druidDataSource.setUrl(propertyResolver.getProperty("url"));
    druidDataSource.setUsername(propertyResolver.getProperty("username"));
    druidDataSource.setPassword(propertyResolver.getProperty("password"));
    druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
    druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
    druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
    druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait")));
    druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis")));
    druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
    druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery"));
    druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle")));
    druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow")));
    druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn")));
    druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements")));
    druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize")));
    druidDataSource.setFilters(propertyResolver.getProperty("filters"));
    return druidDataSource;
}
 
开发者ID:jmdhappy,项目名称:xxpay-master,代码行数:30,代码来源:DruidDataSourceConfig.java

示例10: clusterDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name = "clusterDataSource")
public DataSource clusterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setName("cluster");
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    // 配置初始化大小、最小、最大
    dataSource.setInitialSize(0);
    dataSource.setMinIdle(0);
    dataSource.setMaxActive(10);
    // 配置获取连接等待超时的时间
    dataSource.setMaxWait(15000);
    // 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
    dataSource.setTimeBetweenEvictionRunsMillis(60000);
    // 配置一个连接在池中最小生存的时间,一个小时
    dataSource.setMinEvictableIdleTimeMillis(3600000);
    dataSource.setTestWhileIdle(true);
    // 这里建议配置为TRUE,防止取到的连接不可用
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(false);
    // 这里配置提交方式,默认就是TRUE,可以不用配置
    dataSource.setDefaultAutoCommit(true);
    // 验证连接有效与否的SQL,不同的数据配置不同
    dataSource.setValidationQuery("SELECT 1");
    return dataSource;
}
 
开发者ID:zheng-zy,项目名称:springboot-mybatis-druid-mutil-datasource,代码行数:29,代码来源:ClusterDataSourceConfig.java

示例11: masterDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setName("master");
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    // 配置初始化大小、最小、最大
    dataSource.setInitialSize(0);
    dataSource.setMinIdle(0);
    dataSource.setMaxActive(10);
    // 配置获取连接等待超时的时间
    dataSource.setMaxWait(15000);
    // 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
    dataSource.setTimeBetweenEvictionRunsMillis(60000);
    // 配置一个连接在池中最小生存的时间,一个小时
    dataSource.setMinEvictableIdleTimeMillis(3600000);
    dataSource.setTestWhileIdle(true);
    // 这里建议配置为TRUE,防止取到的连接不可用
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(false);
    // 这里配置提交方式,默认就是TRUE,可以不用配置
    dataSource.setDefaultAutoCommit(true);
    // 验证连接有效与否的SQL,不同的数据配置不同
    dataSource.setValidationQuery("SELECT 1");
    return dataSource;
}
 
开发者ID:zheng-zy,项目名称:springboot-mybatis-druid-mutil-datasource,代码行数:30,代码来源:MasterDataSourceConfig.java

示例12: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean     //声明其为Bean实例  
public DataSource dataSource(){  
    DruidDataSource datasource = new DruidDataSource();  
    datasource.setUrl(dbUrl);  
    datasource.setUsername(username);  
    datasource.setPassword(password);  
    datasource.setDriverClassName(driverClassName);  
	  
    //configuration  
    datasource.setInitialSize(initialSize);  
    datasource.setMinIdle(minIdle);  
    datasource.setMaxActive(maxActive);  
    datasource.setMaxWait(maxWait);  
    datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);  
    datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);  
    datasource.setValidationQuery(validationQuery);  
    datasource.setTestWhileIdle(testWhileIdle);  
    datasource.setTestOnBorrow(testOnBorrow);  
    datasource.setTestOnReturn(testOnReturn);  
    datasource.setPoolPreparedStatements(poolPreparedStatements);  
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);  
    datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);  
    try {  
        datasource.setFilters(filters);  
    } catch (SQLException e) {  
        System.err.println("druid configuration initialization filter: "+ e);  
    }  
    datasource.setConnectionProperties(connectionProperties);  
    return datasource;  
}
 
开发者ID:ranji1221,项目名称:lemcloud,代码行数:31,代码来源:DruidConfig.java

示例13: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean     //声明其为Bean实例
@Primary  //在同样的DataSource中,首先使用被标注的DataSource
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(url);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);

    //configuration
    datasource.setInitialSize(initialSize);
    datasource.setMinIdle(minIdle);
    datasource.setMaxActive(maxActive);
    datasource.setMaxWait(maxWait);
    datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    datasource.setValidationQuery(validationQuery);
    datasource.setTestWhileIdle(testWhileIdle);
    datasource.setTestOnBorrow(testOnBorrow);
    datasource.setTestOnReturn(testOnReturn);
    datasource.setPoolPreparedStatements(poolPreparedStatements);
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
    	logger.error("druid configuration initialization filter: {}",e);
    }
    datasource.setConnectionProperties(connectionProperties);
    return datasource;
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:31,代码来源:DruidConfiguration.java

示例14: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean
@Primary
public DataSource dataSource() {
  DruidDataSource datasource = new DruidDataSource();
  datasource.setUrl(this.dbUrl);
  datasource.setUsername(username);
  datasource.setPassword(password);
  datasource.setDriverClassName(driverClassName);
  // configuration
  datasource.setInitialSize(initialSize);
  datasource.setMinIdle(minIdle);
  datasource.setMaxActive(maxActive);
  datasource.setMaxWait(maxWait);
  datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
  datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
  datasource.setValidationQuery(validationQuery);
  datasource.setTestWhileIdle(testWhileIdle);
  datasource.setTestOnBorrow(testOnBorrow);
  datasource.setTestOnReturn(testOnReturn);
  datasource.setPoolPreparedStatements(poolPreparedStatements);
  datasource
      .setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
  try {
    datasource.setFilters(filters);
  } catch (SQLException e) {
    logger.error("druid configuration initialization filter", e);
  }
  datasource.setConnectionProperties(connectionProperties);

  return datasource;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:32,代码来源:DataSourceConfiguration.java

示例15: init

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
public void init() throws Exception{  
    System.out.println("**************init"); 
    MicroMetaDao dao=MicroMetaDao.getInstance();
    String sql="select * from nh_micro_dbconf";
    List<Map<String,Object>> infoList=dao.queryObjJoinByCondition(sql);
    for(Map<String,Object> row:infoList){
    	String metaKey=(String) row.get("meta_key");
    	String dataSourceClassName=(String) row.get("datasource_classname");
    	String dbUser=(String) row.get("db_user");
    	String dbPassWord=(String) row.get("db_password");
    	if(dbPassWord.startsWith("nhjm-")){
    		String temp=dbPassWord.substring(5);
    		dbPassWord=DESUtil.decrypt(temp);
    	}
    	String dbUrl=(String) row.get("db_url");
    	DruidDataSource ds=new DruidDataSource();
    	ds.setUsername(dbUser);
    	ds.setPassword(dbPassWord);
    	ds.setUrl(dbUrl);
    	ds.setFilters("stat");
    	ds.setMaxActive(10);
    	ds.setInitialSize(1);
    	ds.setMaxWait(60000);
    	ds.setMinIdle(1);
    	ds.setTimeBetweenEvictionRunsMillis(60000);
    	ds.setMinEvictableIdleTimeMillis(60000);
    	ds.setValidationQuery("SELECT 'x'");
    	ds.setTestWhileIdle(true);
    	ds.setTestOnBorrow(false);
    	ds.setTestOnReturn(false);
    	ds.setPoolPreparedStatements(true);
    	ds.setMaxPoolPreparedStatementPerConnectionSize(10);
    	ds.setDriverClassName(dataSourceClassName);
    	ds.init();
    	JdbcTemplate jdbcTemplate=new JdbcTemplate();
    	jdbcTemplate.setDataSource(ds);
    	MicroDbHolder.getDbHolder().put(metaKey, jdbcTemplate);
    }
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:40,代码来源:MicroDSInit.java


注:本文中的com.alibaba.druid.pool.DruidDataSource.setValidationQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。