當前位置: 首頁>>代碼示例>>Java>>正文


Java ComboPooledDataSource.setAcquireRetryAttempts方法代碼示例

本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setAcquireRetryAttempts方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.setAcquireRetryAttempts方法的具體用法?Java ComboPooledDataSource.setAcquireRetryAttempts怎麽用?Java ComboPooledDataSource.setAcquireRetryAttempts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mchange.v2.c3p0.ComboPooledDataSource的用法示例。


在下文中一共展示了ComboPooledDataSource.setAcquireRetryAttempts方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrap

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public DataSource wrap(ReportDataSource rptDs) {
    try {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass(rptDs.getDriverClass());
        dataSource.setJdbcUrl(rptDs.getJdbcUrl());
        dataSource.setUser(rptDs.getUser());
        dataSource.setPassword(rptDs.getPassword());
        dataSource.setInitialPoolSize(MapUtils.getInteger(rptDs.getOptions(), "initialPoolSize", 3));
        dataSource.setMinPoolSize(MapUtils.getInteger(rptDs.getOptions(), "minPoolSize", 1));
        dataSource.setMaxPoolSize(MapUtils.getInteger(rptDs.getOptions(), "maxPoolSize", 20));
        dataSource.setMaxStatements(MapUtils.getInteger(rptDs.getOptions(), "maxStatements", 50));
        dataSource.setMaxIdleTime(MapUtils.getInteger(rptDs.getOptions(), "maxIdleTime", 1800));
        dataSource.setAcquireIncrement(MapUtils.getInteger(rptDs.getOptions(), "acquireIncrement", 3));
        dataSource.setAcquireRetryAttempts(MapUtils.getInteger(rptDs.getOptions(), "acquireRetryAttempts", 30));
        dataSource.setIdleConnectionTestPeriod(
            MapUtils.getInteger(rptDs.getOptions(), "idleConnectionTestPeriod", 60));
        dataSource.setBreakAfterAcquireFailure(
            MapUtils.getBoolean(rptDs.getOptions(), "breakAfterAcquireFailure", false));
        dataSource.setTestConnectionOnCheckout(
            MapUtils.getBoolean(rptDs.getOptions(), "testConnectionOnCheckout", false));
        return dataSource;
    } catch (Exception ex) {
        throw new RuntimeException("C3p0DataSourcePool Create Error", ex);
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:27,代碼來源:C3p0DataSourcePool.java

示例2: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "oracle.jdbc.driver.OracleDriver";
	}

	logger.info("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);
	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new OracleProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:31,代碼來源:OracleProxyDataSource.java

示例3: configure

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void configure(ComboPooledDataSource ds) {
  ds.setMinPoolSize(poolSize);
  ds.setInitialPoolSize(poolSize);
  ds.setMaxPoolSize(poolSize * 3);
  ds.setAcquireIncrement(aquireInc);
  ds.setMaxIdleTime(maxIdle);
  ds.setMaxConnectionAge(maxAge);
  ds.setMaxStatementsPerConnection(maxStmts);
  ds.setAcquireRetryAttempts(retry);
  ds.setAcquireRetryDelay(retryDelay);
}
 
開發者ID:vvergnolle,項目名稱:vas,代碼行數:13,代碼來源:AddressModule.java

示例4: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "org.gjt.mm.mysql.Driver";
	}

	System.err.println("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);
	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new ProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard-data,代碼行數:31,代碼來源:ProxyDataSource.java

示例5: 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

示例6: init

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static void init(Datasources datasources) {
    if (datasources == null) {
        log.error("Datasources are not set (or misconfigured)");
        return;
    }
    log.debug("Adding shutdown hook (closing connections)...");
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            DataSource.closeAllConnections();
        }
    });
    log.debug("Initializing data source connection pools...");
    Iterator<Datasource> it = datasources.getDatasources().iterator();
    while (it.hasNext()) {
        Datasource datasource = it.next();
        Integer maxPoolSize = datasource.getMaxPollSize();
        log.debug("Max Pool Size:" + maxPoolSize + " for datasource: " + datasource.getName());
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setJdbcUrl(datasource.getUrl());
        cpds.setUser(datasource.getUser());
        cpds.setPassword(datasource.getPassword());

        cpds.setAcquireRetryAttempts(3); // default is 30
        cpds.setAcquireRetryDelay(10000);

        cpds.setInitialPoolSize(1);
        cpds.setMinPoolSize(1);
        cpds.setAcquireIncrement(1);
        if (maxPoolSize == null || maxPoolSize == 0 || maxPoolSize > 500) {
            log.warn("Poll size for '" + datasource.getName() + "' is incorrect (allowed 1-500). It will be set" +
                    " to 1.");
            cpds.setMaxPoolSize(1);
        } else {
            cpds.setMaxPoolSize(maxPoolSize);
        }

        try {
            cpds.setDriverClass(datasource.getDriver());
            DATASOURCES_MAP.put(datasource.getName(), cpds);
        } catch (PropertyVetoException e) {
            // we only log it but not quit application (even it is misconfigured) because we want to run all test
            // anyway and mark them as failed (instead of just one "silent" exception in logs). They will fail
            // while trying to getConnection (see method below).
            log.error(e);
        }
    }
    log.debug("Max Pool Size for each DataSource should be >= Threads");
}
 
開發者ID:ObjectivityLtd,項目名稱:DBTestCompare,代碼行數:49,代碼來源:DataSource.java

示例7: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize, int idleConnectionTestPeriod) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "org.gjt.mm.mysql.Driver";
	}

	logger.info("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);

	// testConnectionOnCheckout
	// 如果設置為true,每次從池中取一個連接,將做一下測試,使用automaticTestTable 或者 preferredTestQuery,
	// 做一條查詢語句.看看連接好不好用,不好用,就關閉它,重新從池中拿一個.
	// idleConnectionTestPeriod
	// 設置在池中的沒有被使用的連接,是否定時做測試,看看這個連接還可以用嗎?

	// <!--每60秒檢查所有連接池中的空閑連接。Default: 0 -->
	// <property name="idleConnectionTestPeriod" value="60" />
	dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new ProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:42,代碼來源:ProxyDataSource.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: getDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public DataSource getDataSource(JsonObject config) throws SQLException {
  String url = config.getString("url");
  if (url == null) throw new NullPointerException("url cannot be null");
  String driverClass = config.getString("driver_class");
  String user = config.getString("user");
  String password = config.getString("password");
  Integer maxPoolSize = config.getInteger("max_pool_size");
  Integer initialPoolSize = config.getInteger("initial_pool_size");
  Integer minPoolSize = config.getInteger("min_pool_size");
  Integer maxStatements = config.getInteger("max_statements");
  Integer maxStatementsPerConnection = config.getInteger("max_statements_per_connection");
  Integer maxIdleTime = config.getInteger("max_idle_time");
  Integer acquireRetryAttempts = config.getInteger("acquire_retry_attempts");
  Integer acquireRetryDelay = config.getInteger("acquire_retry_delay");
  Boolean breakAfterAcquireFailure = config.getBoolean("break_after_acquire_failure");

  // If you want to configure any other C3P0 properties you can add a file c3p0.properties to the classpath
  ComboPooledDataSource cpds = new ComboPooledDataSource();
  cpds.setJdbcUrl(url);
  if (driverClass != null) {
    try {
      cpds.setDriverClass(driverClass);
    } catch (PropertyVetoException e) {
      throw new IllegalArgumentException(e);
    }
  }
  if (user != null) {
    cpds.setUser(user);
  }
  if (password != null) {
    cpds.setPassword(password);
  }
  if (maxPoolSize != null) {
    cpds.setMaxPoolSize(maxPoolSize);
  }
  if (minPoolSize != null) {
    cpds.setMinPoolSize(minPoolSize);
  }
  if (initialPoolSize != null) {
    cpds.setInitialPoolSize(initialPoolSize);
  }
  if (maxStatements != null) {
    cpds.setMaxStatements(maxStatements);
  }
  if (maxStatementsPerConnection != null) {
    cpds.setMaxStatementsPerConnection(maxStatementsPerConnection);
  }
  if (maxIdleTime != null) {
    cpds.setMaxIdleTime(maxIdleTime);
  }
  if(acquireRetryAttempts != null){
    cpds.setAcquireRetryAttempts(acquireRetryAttempts);
  }
  if(acquireRetryDelay != null){
    cpds.setAcquireRetryDelay(acquireRetryDelay);
  }
  if(breakAfterAcquireFailure != null){
    cpds.setBreakAfterAcquireFailure(breakAfterAcquireFailure);
  }
  return cpds;
}
 
開發者ID:vert-x3,項目名稱:vertx-jdbc-client,代碼行數:63,代碼來源:C3P0DataSourceProvider.java


注:本文中的com.mchange.v2.c3p0.ComboPooledDataSource.setAcquireRetryAttempts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。