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


Java BasicDataSource.setInitialSize方法代码示例

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


在下文中一共展示了BasicDataSource.setInitialSize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:20,代码来源:DataSourceContainer.java

示例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;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:20,代码来源:DataSourceContainer.java

示例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);
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:25,代码来源:WayfGuiceModule.java

示例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;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:26,代码来源:JdbcDataSourceFactory.java

示例5: 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);
}
 
开发者ID:lysu,项目名称:diamond,代码行数:24,代码来源:PersistService.java

示例6: basicDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
 * @return datasource
 */
private BasicDataSource basicDataSource() {
    final BasicDataSource dataSource = new BasicDataSource();

    // Driver
    dataSource.setDriverClassName(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));

    // Pool
    dataSource.setInitialSize(Integer.parseInt(environment.getRequiredProperty(PROPERTY_NAME_POOL_INITIAL_SIZE)));
    dataSource.setMaxActive(Integer.parseInt(environment.getRequiredProperty(PROPERTY_NAME_POOL_MAX_ACTIVE)));

    return dataSource;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:16,代码来源:RepositoryConfiguratie.java

示例7: dataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Bean(name = "inmemoryDataSource")
@Primary
public DataSource dataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(HSQL_JDBC_URL_TEMPLATE);
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setInitialSize(3);
    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    return ds;
}
 
开发者ID:siteadmin,项目名称:CCDA-Score-CARD,代码行数:12,代码来源:PersistanceConfiguration.java

示例8: 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);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:6,代码来源:DataSourceConfig.java

示例9: 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;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:51,代码来源:DataSourceCreator.java

示例10: 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;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:44,代码来源:MediaPushDataSource.java

示例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;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:51,代码来源:DBDataSourceService.java

示例12: 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;
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:60,代码来源:DBCPDataSourceCreater.java

示例13: 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;
}
 
开发者ID:xsonorg,项目名称:tangyuan,代码行数:57,代码来源:DBCPDataSourceCreater.java


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