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


Java ComboPooledDataSource.setCheckoutTimeout方法代码示例

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


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

示例1: datasource

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Bean(name = "NextRTCDataSource", destroyMethod = "close")
public ComboPooledDataSource datasource() throws PropertyVetoException {
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setMinPoolSize(1);
    ds.setMaxPoolSize(10);
    ds.setCheckoutTimeout(30 * 60 * 100);
    ds.setMaxIdleTime(30 * 60); // 30 minutes
    ds.setMaxStatements(10);
    ds.setMaxStatementsPerConnection(10);
    ds.setAutoCommitOnClose(true);

    ds.setDriverClass(environment.getRequiredProperty("nextrtc.db.driverClassName"));
    ds.setJdbcUrl(environment.getRequiredProperty("nextrtc.db.url"));
    ds.setUser(environment.getRequiredProperty("nextrtc.db.username"));
    ds.setPassword(environment.getRequiredProperty("nextrtc.db.password"));
    return ds;
}
 
开发者ID:mslosarz,项目名称:nextrtc-videochat-with-rest,代码行数:18,代码来源:DBConfig.java

示例2: configDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static DataSource configDataSource(RepDatabase cfg)
		throws PropertyVetoException {

	ComboPooledDataSource ds = new ComboPooledDataSource();

	ds.setDriverClass(cfg.getDriverclass().trim());
	// loads the jdbc driver
	ds.setJdbcUrl(cfg.getUrl().trim());
	ds.setUser(cfg.getUsername().trim());
	ds.setPassword(cfg.getPassword().trim());
	ds.setMaxStatements(20);//
	ds.setMaxIdleTime(cfg.getMaxidletime());// 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃
	ds.setMaxPoolSize(cfg.getMaxpoolsize());// 池最大连接数
	ds.setMinPoolSize(cfg.getMinpoolsize());// 池最小连接数

	// 检查有效性
	if(StringHelper.isNotEmpty(cfg.getTestquerysql())&&cfg.getTestoeriod()!=null){
		ds.setPreferredTestQuery(cfg.getTestquerysql());
		ds.setIdleConnectionTestPeriod(cfg.getTestoeriod());// 每隔10分钟检查一次空闲连接的有效性
	}
	
	//获取连接超时
	ds.setCheckoutTimeout(10000);

	return ds;
}
 
开发者ID:leopardoooo,项目名称:cambodia,代码行数:27,代码来源:ConnContainer.java

示例3: getConnection

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public synchronized Connection getConnection(Configuration conf) throws SQLException {
  DriverConfig config = getDriverConfigfromConf(conf);
  if (!dataSourceMap.containsKey(config)) {
    ComboPooledDataSource cpds = new ComboPooledDataSource();
    try {
      cpds.setDriverClass(config.driverClass);
    } catch (PropertyVetoException e) {
      throw new IllegalArgumentException("Unable to set driver class:" + config.driverClass, e);
    }
    cpds.setJdbcUrl(config.jdbcURI);
    cpds.setProperties(config.properties);

    cpds.setMaxPoolSize(Integer.parseInt(config.getProperty(JDBC_POOL_MAX_SIZE.getPoolProperty())));
    cpds.setMaxIdleTime(Integer.parseInt(config.getProperty(JDBC_POOL_IDLE_TIME.getPoolProperty())));
    cpds.setMaxIdleTimeExcessConnections(Integer.parseInt(config.getProperty(JDBC_MAX_IDLE_TIME_EXCESS_CONNECTIONS
      .getPoolProperty())));
    cpds.setMaxStatementsPerConnection(Integer.parseInt(config.getProperty(JDBC_MAX_STATEMENTS_PER_CONNECTION
      .getPoolProperty())));
    cpds.setCheckoutTimeout(Integer.parseInt(config.getProperty(JDBC_GET_CONNECTION_TIMEOUT.getPoolProperty())));
    dataSourceMap.put(config, cpds);
    log.info("Created new datasource for config: {}", config);
  }
  return dataSourceMap.get(config).getConnection();
}
 
开发者ID:apache,项目名称:lens,代码行数:26,代码来源:DataSourceConnectionProvider.java

示例4: DAOFactory

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
protected DAOFactory(String facName, String driverClassName, String jdbcURL, String userName, String userPassword,
        int initPoolSize, int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod,
        String testQuerySQL) {

    this.facName = facName;

    ds = new ComboPooledDataSource();
    // 设置JDBC的Driver类
    try {
        ds.setDriverClass(driverClassName);
    }
    catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    }
    // 设置JDBC的URL
    ds.setJdbcUrl(jdbcURL);
    // 设置数据库的登录用户名
    ds.setUser(userName);
    // 设置数据库的登录用户密码
    ds.setPassword(userPassword);
    // 设置连接池的最大连接数
    ds.setMaxPoolSize(MaxPoolSize);
    // 设置连接池的最小连接数
    ds.setMinPoolSize(MinPoolSize);
    // 设置初始化连接数
    ds.setInitialPoolSize(initPoolSize);
    // 设置最大闲置时间
    ds.setMaxIdleTime(maxIdleTime);
    // 设置测试SQL
    ds.setPreferredTestQuery(testQuerySQL);
    // 设置闲置测试周期
    ds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
    // 增加单个连接的Statements数量
    ds.setMaxStatements(0);
    // 连接池内单个连接所拥有的最大缓存statements数
    ds.setMaxStatementsPerConnection(200);
    // 获取空闲连接超时时间
    ds.setCheckoutTimeout(10 * 1000);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:40,代码来源:DAOFactory.java

示例5: Initialize

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
/**
 * Initializes the pool.
 *DriverClass - The JDBC driver class.
 *JdbcUrl - JDBC connection url.
 *User / Password - Connection credentials.
 */
public void Initialize(String DriverClass, String JdbcUrl, String User, String Password) throws PropertyVetoException {
	final ComboPooledDataSource pool = new ComboPooledDataSource();
	setObject(pool);
	pool.setDriverClass(DriverClass);
	pool.setJdbcUrl(JdbcUrl);
	pool.setUser(User);
	pool.setPassword(Password);
	pool.setMaxStatements(150);
	pool.setMaxIdleTime(1800);
	pool.setIdleConnectionTestPeriod(600);
	pool.setCheckoutTimeout(20000);
	pool.setTestConnectionOnCheckout(true);
}
 
开发者ID:AnywhereSoftware,项目名称:B4J_Server,代码行数:20,代码来源:ConnectionPool.java

示例6: testPooling

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public void testPooling(CloudSpannerConnection original)
		throws SQLException, PropertyVetoException, InterruptedException
{
	log.info("Starting connection pooling tests");
	ComboPooledDataSource cpds = new ComboPooledDataSource();
	cpds.setDriverClass("nl.topicus.jdbc.CloudSpannerDriver");
	cpds.setJdbcUrl(original.getUrl());
	cpds.setProperties(original.getSuppliedProperties());

	cpds.setInitialPoolSize(5);
	cpds.setMinPoolSize(5);
	cpds.setAcquireIncrement(5);
	cpds.setMaxPoolSize(20);
	cpds.setCheckoutTimeout(1000);

	log.info("Connection pool created and configured. Acquiring connection from pool");
	Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());
	Connection connection = cpds.getConnection();
	Assert.assertNotNull(connection);
	Assert.assertEquals(1, cpds.getNumBusyConnectionsDefaultUser());
	connection.close();
	while (cpds.getNumBusyConnections() == 1)
	{
		Thread.sleep(100l);
	}
	Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());

	log.info("About to acquire 10 connections");
	Connection[] connections = new Connection[10];
	for (int i = 0; i < connections.length; i++)
	{
		connections[i] = cpds.getConnection();
		Assert.assertEquals(i + 1, cpds.getNumBusyConnectionsDefaultUser());
	}
	log.info("10 connections acquired, closing connections...");
	for (int i = 0; i < connections.length; i++)
	{
		connections[i].close();
	}
	log.info("10 connections closed");
	log.info("Acquiring 20 connections");
	// Check that we can get 20 connections
	connections = new Connection[20];
	for (int i = 0; i < connections.length; i++)
	{
		connections[i] = cpds.getConnection();
		connections[i].prepareStatement("SELECT 1").executeQuery();
	}
	log.info("20 connections acquired, trying to get one more");
	// Verify that we can't get a connection now
	connection = null;
	try
	{
		connection = cpds.getConnection();
	}
	catch (SQLException e)
	{
		// timeout exception
		log.info("Exception when trying to get one more connection (this is expected)");
	}
	log.info("Closing 20 connections");
	Assert.assertNull(connection);
	for (int i = 0; i < connections.length; i++)
	{
		connections[i].close();
	}
	log.info("Closing connection pool");
	cpds.close();
	log.info("Finished tests");
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:71,代码来源:ConnectionPoolingTester.java

示例7: L2DatabaseFactory

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public L2DatabaseFactory() throws SQLException
{
	try
	{
		if (Config.DATABASE_MAX_CONNECTIONS < 2)
           {
               Config.DATABASE_MAX_CONNECTIONS = 2;
               _log.warning("at least " + Config.DATABASE_MAX_CONNECTIONS + " db connections are required.");
           }

		_source = new ComboPooledDataSource();
		_source.setAutoCommitOnClose(true);

		_source.setInitialPoolSize(10);
		_source.setMinPoolSize(10);
		_source.setMaxPoolSize(Config.DATABASE_MAX_CONNECTIONS);

		_source.setAcquireRetryAttempts(0); // try to obtain connections indefinitely (0 = never quit)
		_source.setAcquireRetryDelay(500);  // 500 miliseconds wait before try to acquire connection again
		_source.setCheckoutTimeout(0);      // 0 = wait indefinitely for new connection
		// if pool is exhausted
		_source.setAcquireIncrement(5);     // if pool is exhausted, get 5 more connections at a time
		// cause there is a "long" delay on acquire connection
		// so taking more than one connection at once will make connection pooling
		// more effective.

		// this "connection_test_table" is automatically created if not already there
		_source.setAutomaticTestTable("connection_test_table");
		_source.setTestConnectionOnCheckin(false);

		// testing OnCheckin used with IdleConnectionTestPeriod is faster than  testing on checkout

		_source.setIdleConnectionTestPeriod(3600); // test idle connection every 60 sec
		_source.setMaxIdleTime(0); // 0 = idle connections never expire
		// *THANKS* to connection testing configured above
		// but I prefer to disconnect all connections not used
		// for more than 1 hour

		// enables statement caching,  there is a "semi-bug" in c3p0 0.9.0 but in 0.9.0.2 and later it's fixed
		_source.setMaxStatementsPerConnection(100);

		_source.setBreakAfterAcquireFailure(false);  // never fail if any way possible
		// setting this to true will make
		// c3p0 "crash" and refuse to work
		// till restart thus making acquire
		// errors "FATAL" ... we don't want that
		// it should be possible to recover
		_source.setDriverClass(Config.DATABASE_DRIVER);
		_source.setJdbcUrl(Config.DATABASE_URL);
		_source.setUser(Config.DATABASE_LOGIN);
		_source.setPassword(Config.DATABASE_PASSWORD);

		/* Test the connection */
		_source.getConnection().close();

		if (Config.DEBUG) _log.fine("Database Connection Working");

		if (Config.DATABASE_DRIVER.toLowerCase().contains("microsoft"))
               _providerType = ProviderType.MsSql;
           else
               _providerType = ProviderType.MySql;
	}
	catch (SQLException x)
	{
		if (Config.DEBUG) _log.fine("Database Connection FAILED");
		// rethrow the exception
		throw x;
	}
	catch (Exception e)
	{
		if (Config.DEBUG) _log.fine("Database Connection FAILED");
		throw new SQLException("could not init DB connection:"+e);
	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:75,代码来源:L2DatabaseFactory.java

示例8: createFromConfig

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private TransactionAwareDataSource createFromConfig(String instanceName, rapture.common.ConnectionInfo info) throws PropertyVetoException {

        String url = PostgresConnectionInfoConfigurer.getUrl(info);
        String user = info.getUsername();
        validateConfig(url, user);
        log.info("Host is " + url);

        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDataSourceName(createDataSourceName(instanceName));
        dataSource.setDriverClass(DRIVER_CLASS); // loads the jdbc driver
        dataSource.setJdbcUrl(url);
        dataSource.setUser(user);
        dataSource.setCheckoutTimeout(DEFAULT_CHECKOUT_TIMEOUT);
        String password = info.getPassword();
        if (!StringUtils.isBlank(password)) {
            dataSource.setPassword(password);
        } else {
            throw RaptureExceptionFactory.create("Password cannot be null!");
        }

        // pool size configuration
        dataSource.setInitialPoolSize(getOptionAsInt(info, "initialPoolSize"));
        dataSource.setMinPoolSize(getOptionAsInt(info, "minPoolSize"));
        dataSource.setMaxPoolSize(getOptionAsInt(info, "maxPoolSize"));
        dataSource.setMaxIdleTimeExcessConnections(getOptionAsInt(info, "maxIdleTimeExcessConnections"));

        // statement size configuration
        dataSource.setMaxStatements(getOptionAsInt(info, "maxStatements"));
        dataSource.setStatementCacheNumDeferredCloseThreads(getOptionAsInt(info, "statementCacheNumDeferredCloseThreads"));

        // connection testing
        dataSource.setIdleConnectionTestPeriod(getOptionAsInt(info, "idleConnectionTestPeriod"));
        boolean testConnectionOnCheckin = true;
        if(info.getOption("testConnectionOnCheckin") != null) {
            testConnectionOnCheckin = (boolean) info.getOption("testConnectionOnCheckin");
        }
        dataSource.setTestConnectionOnCheckin(testConnectionOnCheckin);

        monitor.monitor(dataSource);

        try {
            Connection connection = DriverManager.getConnection(url, user, password);
            connection.close();
        } catch (SQLException e) {
            throw RaptureExceptionFactory.create(ExceptionToString.format(e));
        }

        return new TransactionAwareDataSource(dataSource);
    }
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:50,代码来源:ConnectionCacheLoader.java

示例9: constructDbIdService

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private IdService constructDbIdService(String dbUrl, String dbName,
                                       String dbUser, String dbPassword) {
    log.info(
            "Construct Db IdService dbUrl {} dbName {} dbUser {} dbPassword {}",
            dbUrl, dbName, dbUser, dbPassword);

    ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();

    String jdbcDriver = "com.mysql.jdbc.Driver";
    try {
        comboPooledDataSource.setDriverClass(jdbcDriver);
    } catch (PropertyVetoException e) {
        log.error("Wrong JDBC driver {}", jdbcDriver);
        log.error("Wrong JDBC driver error: ", e);
        throw new IllegalStateException("Wrong JDBC driver ", e);
    }

    comboPooledDataSource.setMinPoolSize(5);
    comboPooledDataSource.setMaxPoolSize(30);
    comboPooledDataSource.setIdleConnectionTestPeriod(20);
    comboPooledDataSource.setMaxIdleTime(25);
    comboPooledDataSource.setBreakAfterAcquireFailure(false);
    comboPooledDataSource.setCheckoutTimeout(3000);
    comboPooledDataSource.setAcquireRetryAttempts(50);
    comboPooledDataSource.setAcquireRetryDelay(1000);

    String url = String
            .format("jdbc:mysql://%s/%s?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true",
                    dbUrl, dbName);

    comboPooledDataSource.setJdbcUrl(url);
    comboPooledDataSource.setUser(dbUser);
    comboPooledDataSource.setPassword(dbPassword);

    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setLazyInit(false);
    jdbcTemplate.setDataSource(comboPooledDataSource);

    DbMachineIdProvider dbMachineIdProvider = new DbMachineIdProvider();
    dbMachineIdProvider.setJdbcTemplate(jdbcTemplate);
    dbMachineIdProvider.init();

    IdServiceImpl idServiceImpl = new IdServiceImpl();
    idServiceImpl.setMachineIdProvider(dbMachineIdProvider);
    if (genMethod != -1)
        idServiceImpl.setGenMethod(genMethod);
    if (type != -1)
        idServiceImpl.setType(type);
    if (version != -1)
        idServiceImpl.setVersion(version);
    idServiceImpl.init();

    return idServiceImpl;
}
 
开发者ID:robertleepeak,项目名称:vesta-id-generator,代码行数:55,代码来源:IdServiceFactoryBean.java

示例10: createDataPool

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
protected DataSource createDataPool(PoolConfig conf) {
	if (!conf.isValid()) {
		throw new RuntimeException("数据库驱动为空或者数据库用户名或者密码或者连接字符串为空");
	}
	log.info("db config:{}", conf.toString());
	ComboPooledDataSource cpds = new ComboPooledDataSource();
	cpds.setJdbcUrl(conf.jdbcUrl);
	cpds.setUser(conf.userName);
	cpds.setPassword(conf.password);
	try {
		cpds.setDriverClass(conf.driverClass);
	} catch (PropertyVetoException e) {
		throw new RuntimeException("数据库驱动设置失败");
	}
	cpds.setPreferredTestQuery("select 1");
	cpds.setIdleConnectionTestPeriod(60);
	if (conf.initialPoolSize != null && !conf.initialPoolSize.isEmpty()) {
		cpds.setInitialPoolSize(Integer.parseInt(conf.initialPoolSize));
	}
	if (conf.acquireIncrement != null && !conf.acquireIncrement.isEmpty()) {
		cpds.setAcquireIncrement(Integer.parseInt(conf.acquireIncrement));
	}
	if (conf.maxPoolSize != null && !conf.maxPoolSize.isEmpty()) {
		cpds.setMaxPoolSize(Integer.parseInt(conf.maxPoolSize));
	}
	if (conf.minPoolSize != null && !conf.minPoolSize.isEmpty()) {
		cpds.setMinPoolSize(Integer.parseInt(conf.minPoolSize));
	}

	if (conf.checkoutTimeout != null && !conf.checkoutTimeout.isEmpty()) {
		cpds.setCheckoutTimeout(Integer.parseInt(conf.checkoutTimeout));
	}
	if (conf.maxStatements != null && !conf.maxStatements.isEmpty()) {
		cpds.setMaxStatements(Integer.parseInt(conf.maxStatements));
	}
	if (conf.maxStatementsPerConnection != null && !conf.maxStatementsPerConnection.isEmpty()) {
		cpds.setMaxStatementsPerConnection(Integer.parseInt(conf.maxStatementsPerConnection));
	}
	if (conf.maxIdleTime != null && !conf.maxIdleTime.isEmpty()) {
		cpds.setMaxIdleTime(Integer.parseInt(conf.maxIdleTime));
	}
	if (conf.unreturnedConnectionTimeout != null && !conf.unreturnedConnectionTimeout.isEmpty()) {
		cpds.setDebugUnreturnedConnectionStackTraces(true);
		cpds.setUnreturnedConnectionTimeout(Integer.parseInt(conf.unreturnedConnectionTimeout));
	} else {
		cpds.setDebugUnreturnedConnectionStackTraces(false);
	}
	return cpds;
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:50,代码来源:C3p0DataSourceWrapper.java

示例11: config

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public void config(ComboPooledDataSource ds) {
	ds.setJdbcUrl("jdbc:h2:~/test");
	ds.setPassword("");// change to your PWD
	ds.setCheckoutTimeout(2000);
}
 
开发者ID:drinkjava2,项目名称:jBeanBox,代码行数:6,代码来源:TesterBox.java

示例12: createDatasource

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public DataSource createDatasource(DatasourceConfig datasourcecfg)
		throws SQLException {
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		dataSource.setDriverClass(datasourcecfg.getDriverClass());
	} catch (PropertyVetoException e) {
		throw new SQLException(e);
	}
	dataSource.setJdbcUrl(datasourcecfg.getJdbcUrl());
	dataSource.setUser(datasourcecfg.getUsername());
	dataSource.setPassword(datasourcecfg.getPassword());
	Map props = datasourcecfg.getPoolPerperties();
	int checkoutTimeout = Utils.strToInt((String) props
			.get("checkoutTimeout"));
	if (checkoutTimeout <= 0) {
		checkoutTimeout = 5000;
	}
	dataSource.setCheckoutTimeout(checkoutTimeout);
	int initPoolSize = Utils
			.strToInt((String) props.get("initialPoolSize"));
	if (initPoolSize > 0) {
		dataSource.setInitialPoolSize(initPoolSize);
	}
	int minpoolsize = Utils.strToInt((String) props.get("minPoolSize"));
	if (minpoolsize <= 0) {
		minpoolsize = 5;
	}
	dataSource.setMinPoolSize(minpoolsize);
	int maxpoolsize = Utils.strToInt((String) props.get("maxPoolSize"));
	if (maxpoolsize <= 0) {
		maxpoolsize = 100;
	}
	dataSource.setMaxPoolSize(maxpoolsize);
	int acqInc = Utils.strToInt((String) props.get("acquireIncrement"));
	if (acqInc <= 0) {
		acqInc = 5;
	}
	dataSource.setAcquireIncrement(acqInc);
	int maxIdleTime = Utils.strToInt((String) props.get("maxIdleTime"));
	if (maxIdleTime > 0) {
		dataSource.setMaxIdleTime(maxIdleTime);
	}
	int idleConTestPeriod = Utils.strToInt((String) props
			.get("idleConnectionTestPeriod"));
	if (idleConTestPeriod > 0) {
		dataSource.setIdleConnectionTestPeriod(idleConTestPeriod);
	}
	int acqRetryAttempts = Utils.strToInt((String) props
			.get("acquireRetryAttempts"));
	if (acqRetryAttempts <= 0) {
		acqRetryAttempts = 10;
	}
	dataSource.setAcquireRetryAttempts(acqRetryAttempts);
	int acqRetryDelay = Utils.strToInt((String) props
			.get("acquireRetryDelay"));
	if (acqRetryDelay <= 0) {
		acqRetryDelay = 500;
	}
	dataSource.setAcquireRetryDelay(acqRetryDelay);
	return dataSource;
}
 
开发者ID:weeks1743,项目名称:linkprise_orm,代码行数:62,代码来源:C3p0DataSourceCreator.java

示例13: createC3p0DataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private static javax.sql.DataSource createC3p0DataSource(
		DatasourceConfig datasourcecfg) throws SQLException {
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		dataSource.setDriverClass(datasourcecfg.getDriverClass());
	} catch (PropertyVetoException e) {
		throw new SQLException(e);
	}
	dataSource.setJdbcUrl(datasourcecfg.getJdbcUrl());
	dataSource.setUser(datasourcecfg.getUsername());
	dataSource.setPassword(datasourcecfg.getPassword());
	Map props = datasourcecfg.getPoolPerperties();
	int checkoutTimeout = Utils.strToInt((String) props
			.get("checkoutTimeout"));
	if (checkoutTimeout <= 0) {
		checkoutTimeout = 5000;
	}
	dataSource.setCheckoutTimeout(checkoutTimeout);
	int initPoolSize = Utils
			.strToInt((String) props.get("initialPoolSize"));
	if (initPoolSize > 0) {
		dataSource.setInitialPoolSize(initPoolSize);
	}
	int minpoolsize = Utils.strToInt((String) props.get("minPoolSize"));
	if (minpoolsize <= 0) {
		minpoolsize = 5;
	}
	dataSource.setMinPoolSize(minpoolsize);
	int maxpoolsize = Utils.strToInt((String) props.get("maxPoolSize"));
	if (maxpoolsize <= 0) {
		maxpoolsize = 100;
	}
	dataSource.setMaxPoolSize(maxpoolsize);
	int acqInc = Utils.strToInt((String) props.get("acquireIncrement"));
	if (acqInc <= 0) {
		acqInc = 5;
	}
	dataSource.setAcquireIncrement(acqInc);
	int maxIdleTime = Utils.strToInt((String) props.get("maxIdleTime"));
	if (maxIdleTime > 0) {
		dataSource.setMaxIdleTime(maxIdleTime);
	}
	int idleConTestPeriod = Utils.strToInt((String) props
			.get("idleConnectionTestPeriod"));
	if (idleConTestPeriod > 0) {
		dataSource.setIdleConnectionTestPeriod(idleConTestPeriod);
	}
	int acqRetryAttempts = Utils.strToInt((String) props
			.get("acquireRetryAttempts"));
	if (acqRetryAttempts <= 0) {
		acqRetryAttempts = 10;
	}
	dataSource.setAcquireRetryAttempts(acqRetryAttempts);
	int acqRetryDelay = Utils.strToInt((String) props
			.get("acquireRetryDelay"));
	if (acqRetryDelay <= 0) {
		acqRetryDelay = 500;
	}
	dataSource.setAcquireRetryDelay(acqRetryDelay);
	return dataSource;
}
 
开发者ID:weeks1743,项目名称:linkprise_orm,代码行数:62,代码来源:DataSourceCreator.java

示例14: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
/**
 * Creates {@link DataSource} based on {@link CConnection} properties.
 *
 * NOTE: this method never throws exception but just logs it.
 *
 * @param connection
 * @return {@link DataSource} or <code>null</code> if it cannot be created
 */
private ComboPooledDataSource createDataSource(final CConnection connection)
{
	try
	{
		System.setProperty("com.mchange.v2.log.MLog", com.mchange.v2.log.slf4j.Slf4jMLog.class.getName());
		// System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL");
		final ComboPooledDataSource cpds = new ComboPooledDataSource();
		cpds.setDataSourceName("AdempiereDS");
		cpds.setDriverClass(DRIVER);
		// loads the jdbc driver
		cpds.setJdbcUrl(getConnectionURL(connection));
		cpds.setUser(connection.getDbUid());
		cpds.setPassword(connection.getDbPwd());
		cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
		cpds.setIdleConnectionTestPeriod(1200);
		// cpds.setTestConnectionOnCheckin(true);
		// cpds.setTestConnectionOnCheckout(true);
		cpds.setAcquireRetryAttempts(2);

		// Set checkout timeout to avoid forever locking when trying to connect to a not existing host.
		cpds.setCheckoutTimeout(SystemUtils.getSystemProperty(CONFIG_CheckoutTimeout, 20 * 1000));

		if (Ini.isClient())
		{
			cpds.setInitialPoolSize(1);
			cpds.setMinPoolSize(1);
			cpds.setMaxPoolSize(20);
			cpds.setMaxIdleTimeExcessConnections(1200);
			cpds.setMaxIdleTime(900);
			m_maxbusyconnectionsThreshold = 15;
		}
		else
		{
			cpds.setInitialPoolSize(10);
			cpds.setMinPoolSize(5);
			cpds.setMaxPoolSize(150);
			cpds.setMaxIdleTimeExcessConnections(1200);
			cpds.setMaxIdleTime(1200);
			m_maxbusyconnectionsThreshold = 120;
		}

		// the following sometimes kill active connection!
		// cpds.setUnreturnedConnectionTimeout(1200);
		// cpds.setDebugUnreturnedConnectionStackTraces(true);

		// 04006: add a customizer to set the log level for message that are send to the client
		// background: if there are too many messages sent (e.g. from a verbose and long-running DB function)
		// then the whole JVM might suffer an OutOfMemoryError
		cpds.setConnectionCustomizerClassName(DB_PostgreSQL_ConnectionCustomizer.class.getName());

		return cpds;
	}
	catch (Exception ex)
	{
		throw new DBNoConnectionException("Could not initialise C3P0 Datasource", ex);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:66,代码来源:DB_PostgreSQL.java


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