本文整理汇总了Java中org.apache.commons.dbcp.BasicDataSource.setMaxIdle方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setMaxIdle方法的具体用法?Java BasicDataSource.setMaxIdle怎么用?Java BasicDataSource.setMaxIdle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbcp.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setMaxIdle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public boolean register(JdbcVo conf) {
boolean isOk = true;
try {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(conf.getDriverClass());
bds.setUrl(conf.getUrl());
bds.setUsername(conf.getUserName());
bds.setPassword(conf.getPassword());
bds.setInitialSize(conf.getInitialSize());
bds.setMaxActive(conf.getMaxActive());
bds.setMaxIdle(conf.getMaxIdle());
bds.setMinIdle(conf.getMinIdle());
cmap.put(conf.getKey(), bds);
} catch (Exception e) {
logger.error("[db container init key " + conf.getKey() + " datasource error!]", e);
isOk = false;
}
return isOk;
}
示例2: register
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public boolean register(JdbcVo conf) {
boolean isOk = true;
try {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(conf.getDriverClass());
bds.setUrl(conf.getUrl());
bds.setUsername(conf.getUserName());
bds.setPassword(conf.getPassword());
bds.setInitialSize(conf.getInitialSize());
bds.setMaxActive(conf.getMaxActive());
bds.setMaxIdle(conf.getMaxIdle());
bds.setMinIdle(conf.getMinIdle());
cmap.put(conf.getKey(), bds);
} catch (Exception e) {
LoggerFactory.getLogger().error("[db container initThreadPool key " + conf.getKey() + " datasource error!]", e);
isOk = false;
}
return isOk;
}
示例3: getJdbcTemplate
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Provides
@Singleton
public NamedParameterJdbcTemplate getJdbcTemplate(
@Named("jdbc.driver") String driver,
@Named("jdbc.username") String username,
@Named("jdbc.password") String password,
@Named("jdbc.url") String url,
@Named("jdbc.maxActive") Integer maxActive,
@Named("jdbc.maxIdle") Integer maxIdle,
@Named("jdbc.initialSize") Integer initialSize,
@Named("jdbc.validationQuery") String validationQuery) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setUrl(url);
dataSource.setMaxActive(maxActive);
dataSource.setMaxIdle(maxIdle);
dataSource.setInitialSize(initialSize);
dataSource.setValidationQuery(validationQuery);
return new NamedParameterJdbcTemplate(dataSource);
}
示例4: createFromJdbcUrl
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driverClass.getName());
dataSource.setUrl(url);
dataSource.setUsername(credential.getUsername());
dataSource.setPassword(credential.getPassword());
// connection pool settings
dataSource.setInitialSize(numThreads);
dataSource.setMaxActive(numThreads);
// keep the connections open if possible; only close them via the removeAbandonedTimeout feature
dataSource.setMaxIdle(numThreads);
dataSource.setMinIdle(0);
dataSource.setRemoveAbandonedTimeout(300);
dataSource.setConnectionInitSqls(initSqls.castToList());
if (extraConnectionProperties != null) {
for (String key : extraConnectionProperties.stringPropertyNames()) {
dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
}
}
return dataSource;
}
示例5: getDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public static DataSource getDataSource() {
BasicDataSource ds = new BasicDataSource();
if (StringUtil.isNotEmpty(driver)) {
ds.setDriverClassName(driver);
}
if (StringUtil.isNotEmpty(url)) {
ds.setUrl(url);
}
if (StringUtil.isNotEmpty(username)) {
ds.setUsername(username);
}
if (StringUtil.isNotEmpty(password)) {
ds.setPassword(password);
}
if (maxActive != 0) {
ds.setMaxActive(maxActive);
}
if (maxIdle != 0) {
ds.setMaxIdle(maxIdle);
}
return ds;
}
示例6: _get
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource _get(String D, String username, String passwd, String url, int N) {
BasicDataSource external = new BasicDataSource();
external.setDriverClassName(D.trim());
if (!X.isEmpty(username)) {
external.setUsername(username.trim());
}
if (!X.isEmpty(passwd)) {
external.setPassword(passwd.trim());
}
external.setUrl(url.trim());
external.setMaxActive(N);
external.setDefaultAutoCommit(true);
external.setMaxIdle(N);
external.setMaxWait(MAX_WAIT_TIME);
external.setDefaultAutoCommit(true);
external.setDefaultReadOnly(false);
external.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
external.setValidationQuery(null);// VALIDATION_SQL);
external.setPoolPreparedStatements(true);
return external;
}
示例7: initDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@PostConstruct
public void initDataSource() throws Exception {
// 读取jdbc.properties配置, 加载数据源
Properties props = ResourceUtils.getResourceAsProperties("jdbc.properties");
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(JDBC_DRIVER_NAME);
ds.setUrl(ensurePropValueNotNull(props.getProperty("db.url")));
ds.setUsername(ensurePropValueNotNull(props.getProperty("db.user")));
ds.setPassword(ensurePropValueNotNull(props.getProperty("db.password")));
ds.setInitialSize(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.initialSize"))));
ds.setMaxActive(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxActive"))));
ds.setMaxIdle(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxIdle"))));
ds.setMaxWait(Long.parseLong(ensurePropValueNotNull(props.getProperty("db.maxWait"))));
ds.setPoolPreparedStatements(Boolean.parseBoolean(ensurePropValueNotNull(props
.getProperty("db.poolPreparedStatements"))));
this.jt = new JdbcTemplate();
this.jt.setDataSource(ds);
// 设置最大记录数,防止内存膨胀
this.jt.setMaxRows(MAX_ROWS);
// 设置JDBC执行超时时间
this.jt.setQueryTimeout(QUERY_TIMEOUT);
}
示例8: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public DataSource createDataSource(String url, String driverClassName, String username, String password) {
BasicDataSource ds = new SerializableBasicDataSource();
ds.setUsername(username);
ds.setPassword(password);
ds.setUrl(url);
ds.setDriverClassName(driverClassName);
ds.setMaxActive(5);
ds.setMaxIdle(2);
return ds;
}
示例9: DataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource() throws IOException, SQLException {
ds = new BasicDataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUsername("alex");
ds.setPassword("");
ds.setUrl("jdbc:postgresql://localhost/infotranspub");
// the settings below are optional -- dbcp can work with defaults
ds.setMinIdle(1);// 5
ds.setMaxActive(1); // 10
ds.setMaxIdle(1); // 20
ds.setMaxOpenPreparedStatements(1); // 180
}
示例10: setNumConnections
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private void setNumConnections(BasicDataSource ds, int initialSize, int maxActive, int maxIdle) {
ds.setInitialSize(initialSize);
ds.setMaxActive(maxActive);
ds.setMaxIdle(maxIdle);
}
示例11: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
DataMediaType dataMediaType, String encoding) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
// dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// 返回时间类型的字符串,不做时区处理
if (StringUtils.isNotEmpty(encoding)) {
if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
dbcpDs.addConnectionProperty("characterEncoding", "utf8");
dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
} else {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
}
// dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例12: doCreateDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
protected DataSource doCreateDataSource(String url) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
if (StringUtils.isNotEmpty(encoding)) {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例13: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
DataMediaType dataMediaType, String encoding) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// 返回时间类型的字符串,不做时区处理
if (StringUtils.isNotEmpty(encoding)) {
if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
dbcpDs.addConnectionProperty("characterEncoding", "utf8");
dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
} else {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
}
dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例14: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private BasicDataSource createDataSource(Map<String, String> properties, String urlPattern) {
BasicDataSource dsPool = new BasicDataSource();
dsPool.setDriverClassName(DSPropertyUtil.getPropertyStringValue("driver", properties, null, null, true));
dsPool.setUsername(DSPropertyUtil.getPropertyStringValue("username", properties, null, null, true));
dsPool.setPassword(DSPropertyUtil.getPropertyStringValue("password", properties, null, null, true));
String url = DSPropertyUtil.getPropertyStringValue("url", properties, null, null, true);
if (null != urlPattern) {
url = DSPropertyUtil.replace(url, "{}", urlPattern);
}
dsPool.setUrl(url);
dsPool.setPoolPreparedStatements(DSPropertyUtil.getPropertyBooleanValue("poolingStatements", properties, null, true, true)); // 开启池的prepared
// 池功能
dsPool.setRemoveAbandoned(DSPropertyUtil.getPropertyBooleanValue("removeAbandoned", properties, null, true, true));
dsPool.setRemoveAbandonedTimeout(DSPropertyUtil.getPropertyIntegerValue("removeAbandonedTimeout", properties, null, 1000, true));
dsPool.setLogAbandoned(DSPropertyUtil.getPropertyBooleanValue("logAbandoned", properties, null, true, true));
dsPool.setInitialSize(DSPropertyUtil.getPropertyIntegerValue("initialSize", properties, null, 2, true));
dsPool.setMaxActive(DSPropertyUtil.getPropertyIntegerValue("maxActive", properties, null, 8, true));
dsPool.setMaxIdle(DSPropertyUtil.getPropertyIntegerValue("maxIdle", properties, null, 8, true));
dsPool.setMinIdle(DSPropertyUtil.getPropertyIntegerValue("minIdle", properties, null, 0, true));
dsPool.setMaxWait(DSPropertyUtil.getPropertyIntegerValue("maxWait", properties, null, 10000, true));
dsPool.setTimeBetweenEvictionRunsMillis(DSPropertyUtil.getPropertyIntegerValue("timeBetweenEvictionRunsMillis", properties, null, -1, true));
dsPool.setTestOnBorrow(DSPropertyUtil.getPropertyBooleanValue("testOnBorrow", properties, null, false, true));
dsPool.setTestOnReturn(DSPropertyUtil.getPropertyBooleanValue("testOnReturn", properties, null, false, true));
dsPool.setTestWhileIdle(DSPropertyUtil.getPropertyBooleanValue("testWhileIdle", properties, null, false, true));
String validationQuery = DSPropertyUtil.getPropertyStringValue("validationQuery", properties, null, null, false);
if (null != validationQuery) {
dsPool.setValidationQuery(validationQuery);
}
int timeout = DSPropertyUtil.getPropertyIntegerValue("", properties, null, -1, false);
if (timeout > -1) {
dsPool.setValidationQueryTimeout(timeout);
}
dsPool.setNumTestsPerEvictionRun(DSPropertyUtil.getPropertyIntegerValue("numTestsPerEvictionRun", properties, null, 10, true));
dsPool.setMinEvictableIdleTimeMillis(DSPropertyUtil.getPropertyIntegerValue("minEvictableIdleTimeMillis", properties, null, 60000, true));
// mysql:select 1
// oracle:select 1 from dual
// sqlserver:select 1
// jtds:select 1
boolean openTest = DSPropertyUtil.getPropertyBooleanValue("openTest", properties, null, false, false);
if (openTest) {
try {
Connection conn = dsPool.getConnection();
conn.close();
log.info("test open database success.");
} catch (Exception e) {
throw new DataSourceException("test open database error: " + e.getMessage(), e);
}
}
return dsPool;
}
示例15: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private BasicDataSource createDataSource(Map<String, String> properties, Map<String, String> decryptProperties, String urlPattern) {
BasicDataSource dsPool = new BasicDataSource();
dsPool.setDriverClassName(getPropertyStringValue("driver", properties, null, null, true));
dsPool.setUsername(getPropertyStringValue("username", properties, null, null, true));
dsPool.setPassword(getPropertyStringValue("password", properties, null, null, true));
String url = getPropertyStringValue("url", properties, null, null, true);
if (null != urlPattern) {
url = StringUtils.replace(url, "{}", urlPattern);
}
dsPool.setUrl(url);
dsPool.setPoolPreparedStatements(getPropertyBooleanValue("poolingStatements", properties, null, true, true)); // 开启池的prepared statement 池功能
dsPool.setRemoveAbandoned(getPropertyBooleanValue("removeAbandoned", properties, null, true, true));
dsPool.setRemoveAbandonedTimeout(getPropertyIntegerValue("removeAbandonedTimeout", properties, null, 1000, true));
dsPool.setLogAbandoned(getPropertyBooleanValue("logAbandoned", properties, null, true, true));
dsPool.setInitialSize(getPropertyIntegerValue("initialSize", properties, null, 2, true));
dsPool.setMaxActive(getPropertyIntegerValue("maxActive", properties, null, 8, true));
dsPool.setMaxIdle(getPropertyIntegerValue("maxIdle", properties, null, 8, true));
dsPool.setMinIdle(getPropertyIntegerValue("minIdle", properties, null, 0, true));
dsPool.setMaxWait(getPropertyIntegerValue("maxWait", properties, null, 10000, true));
dsPool.setTimeBetweenEvictionRunsMillis(getPropertyIntegerValue("timeBetweenEvictionRunsMillis", properties, null, -1, true));
dsPool.setTestOnBorrow(getPropertyBooleanValue("testOnBorrow", properties, null, false, true));
dsPool.setTestOnReturn(getPropertyBooleanValue("testOnReturn", properties, null, false, true));
dsPool.setTestWhileIdle(getPropertyBooleanValue("testWhileIdle", properties, null, false, true));
String validationQuery = getPropertyStringValue("validationQuery", properties, null, null, false);
if (null != validationQuery) {
dsPool.setValidationQuery(validationQuery);
}
// dsPool.setValidationQueryTimeout(timeout);
dsPool.setNumTestsPerEvictionRun(getPropertyIntegerValue("numTestsPerEvictionRun", properties, null, 10, true));
dsPool.setMinEvictableIdleTimeMillis(getPropertyIntegerValue("minEvictableIdleTimeMillis", properties, null, 60000, true));
// mysql:select 1
// oracle:select 1 from dual
// sqlserver:select 1
// jtds:select 1
boolean openTest = getPropertyBooleanValue("openTest", properties, null, false, false);
if (openTest) {
try {
Connection conn = dsPool.getConnection();
conn.close();
log.info("test open database success.");
} catch (Exception e) {
throw new DataSourceException("test open database error: " + e.getMessage(), e);
}
}
return dsPool;
}