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


Java ComboPooledDataSource.setMaxStatementsPerConnection方法代碼示例

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


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

示例1: connect

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Method load properties and get connection pool to database.
 * Use c3p0 library.
 */
public void connect() {
    pool = new ComboPooledDataSource();
    try {
        pool.setDriverClass(dbPROP.getProperty("driver"));
    } catch (PropertyVetoException ex) {
        ex.printStackTrace();
    }
    pool.setJdbcUrl(dbPROP.getProperty("url"));
    pool.setUser(dbPROP.getProperty("username"));
    pool.setPassword(dbPROP.getProperty("password"));
    pool.setMinPoolSize(2);
    pool.setAcquireIncrement(1);
    pool.setMaxPoolSize(5);
    pool.setMaxStatements(50);
    pool.setMaxStatementsPerConnection(10);
}
 
開發者ID:CkimiHoK,項目名稱:JavaWork,代碼行數:21,代碼來源:DataBaseController.java

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

示例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 driverClassName, String jdbcURL, String userName, String userPassword, int initPoolSize,
        int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod, String testQuerySQL) {

    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);
    ds.setMaxStatementsPerConnection(200);

}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:36,代碼來源:DAOFactory.java

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

示例6: createDelegate

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
protected DataSource createDelegate() {
    final ComboPooledDataSource ds = new ComboPooledDataSource();
    try {
        ds.setDriverClass(context.getConnectionDriver());
    } catch (final PropertyVetoException e1) {
        throw Err.process(e1);
    }
    ds.setJdbcUrl(context.getConnectionUrl());
    ds.setUser(context.getConnectionUser());
    ds.setPassword(context.getConnectionPassword());

    ds.setMaxStatements(5000);
    ds.setMaxStatementsPerConnection(50);
    ds.setStatementCacheNumDeferredCloseThreads(1); //fix apparent deadlocks

    ds.setMaxPoolSize(100);
    ds.setMinPoolSize(1);
    ds.setMaxIdleTime(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.SECONDS));
    ds.setTestConnectionOnCheckout(true);

    ds.setAutoCommitOnClose(true);

    Assertions.assertThat(this.closeableDs).isNull();
    this.closeableDs = ds;

    if (logging) {
        try {
            final ConnectionPoolDataSourceProxy proxy = new ConnectionPoolDataSourceProxy();
            proxy.setTargetDSDirect(ds);
            return proxy;
        } catch (final JdbcDsLogRuntimeException e) {
            throw new RuntimeException(e);
        }
    } else {
        return ds;
    }
}
 
開發者ID:subes,項目名稱:invesdwin-context-persistence,代碼行數:39,代碼來源:ConfiguredCPDataSource.java

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

示例8: Dao

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public Dao(DbConfig config) {
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	dataSource.setJdbcUrl(config.getUrl());
	dataSource.setUser(config.getUser());
	dataSource.setPassword(config.getPassword());
	try {
		dataSource.setDriverClass(config.getDriverClass());
	} catch (PropertyVetoException e) {
		throw new ServiceException(MessageFormat.format("{0} not found",
				config.getDriverClass()));
	}
	logger.info("Dao init url={},user={},driverClass={}", new Object[] {
			config.getUrl(), config.getUser(), config.getDriverClass() });
	if (config.getInitialPoolSize() != 0) {
		dataSource.setInitialPoolSize(config.getInitialPoolSize());
	}
	if (config.getMaxPoolSize() != 0) {
		dataSource.setMaxPoolSize(config.getMaxPoolSize());
	}
	if (config.getMinPoolSize() != 0) {
		dataSource.setMinPoolSize(config.getMinPoolSize());
	}
	if (config.getAcquireIncrement() != 0) {
		dataSource.setAcquireIncrement(config.getAcquireIncrement());
	}
	if (config.getMaxIdleTime() != 0) {
		dataSource.setMaxIdleTime(config.getMaxIdleTime());
	}
	if (config.getMaxStatements() != 0) {
		dataSource.setMaxStatements(config.getMaxStatements());
	}
	if (config.getMaxStatementsPerConnection() != 0) {
		dataSource.setMaxStatementsPerConnection(config
				.getMaxStatementsPerConnection());
	}
	if (config.getPreferredTestQuery() != null) {
		dataSource.setPreferredTestQuery(config.getPreferredTestQuery());
	}
	jdbc = new JDBCTemplate(dataSource);
}
 
開發者ID:nichoding,項目名稱:daisy-db,代碼行數:41,代碼來源:Dao.java

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

示例10: initialize

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Create the underlying C3PO ComboPooledDataSource with the 
 * default supported properties.
 * @throws SchedulerException 
 */
private void initialize(
    String dbDriver, 
    String dbURL, 
    String dbUser,
    String dbPassword, 
    int maxConnections, 
    int maxStatementsPerConnection, 
    String dbValidationQuery,
    boolean validateOnCheckout,
    int idleValidationSeconds,
    int maxIdleSeconds) throws SQLException, SchedulerException {
    if (dbURL == null) {
        throw new SQLException(
            "DBPool could not be created: DB URL cannot be null");
    }
    
    if (dbDriver == null) {
        throw new SQLException(
            "DBPool '" + dbURL + "' could not be created: " +
            "DB driver class name cannot be null!");
    }
    
    if (maxConnections < 0) {
        throw new SQLException(
            "DBPool '" + dbURL + "' could not be created: " + 
            "Max connections must be greater than zero!");
    }

    
    datasource = new ComboPooledDataSource(); 
    try {
        datasource.setDriverClass(dbDriver);
    } catch (PropertyVetoException e) {
        throw new SchedulerException("Problem setting driver class name on datasource: " + e.getMessage(), e);
    }  
    datasource.setJdbcUrl(dbURL); 
    datasource.setUser(dbUser); 
    datasource.setPassword(dbPassword);
    datasource.setMaxPoolSize(maxConnections);
    datasource.setMinPoolSize(1);
    datasource.setMaxIdleTime(maxIdleSeconds);
    datasource.setMaxStatementsPerConnection(maxStatementsPerConnection);
    
    if (dbValidationQuery != null) {
        datasource.setPreferredTestQuery(dbValidationQuery);
        if(!validateOnCheckout)
            datasource.setTestConnectionOnCheckin(true);
        else
            datasource.setTestConnectionOnCheckout(true);
        datasource.setIdleConnectionTestPeriod(idleValidationSeconds);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:58,代碼來源:PoolingConnectionProvider.java

示例11: setupDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static void setupDataSource(Isolation isolation) {
  ds = new ComboPooledDataSource();
  Endpoint locatorEndPoint = (Endpoint) (NetworkServerHelper.getNetworkLocatorEndpoints()).get(0);
  String hostname = getHostNameFromEndpoint(locatorEndPoint);
  int port = getPortFromEndpoint(locatorEndPoint); 
  
  connProp.putAll(getExtraConnProp()); //singlehop conn properties and any additional prop
  
  try {
    ds.setProperties(connProp); 
    ds.setDriverClass(driver);
    ds.setJdbcUrl(protocol + hostname+ ":" + port);
    
    ds.setMinPoolSize(5);
    ds.setAcquireIncrement(5);
    ds.setMaxPoolSize(numOfWorkers + 100);
    ds.setMaxStatementsPerConnection(10);
    
    if (isolation == Isolation.NONE) {
      ds.setConnectionCustomizerClassName( "sql.sqlutil.MyConnectionCustomizer");
    } else if (isolation == Isolation.READ_COMMITTED) {
      ds.setConnectionCustomizerClassName("sql.sqlutil.IsolationRCConnectionCustomizer");
    } else {
      ds.setConnectionCustomizerClassName("sql.sqlutil.IsolationRRConnectionCustomizer");
    }
    
    Log.getLogWriter().info("Pooled data source url is set as " + ds.getJdbcUrl());
    
    StringBuilder sb = new StringBuilder();
    
    for (Iterator iter = connProp.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry<String, String> entry = (Map.Entry<String, String>) iter.next();
      
      sb.append(entry.getKey() + " is set to " + entry.getValue() +"\n");
    }
    
    Log.getLogWriter().info("Pooled data source setting the following connection prop: " + sb.toString());
    
  } catch (Exception e) {
    throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:44,代碼來源:PooledConnectionC3P0.java

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

示例13: initDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Initializes the connection pool.
 * @param dbSpec the object representing the chosen DB target system.
 * @param jdbcUrl the JDBC URL to connect to.
 * @throws SQLException 
 */
private static void initDataSource(DBSpecifics dbSpec, String jdbcUrl)
throws SQLException {

    dataSource = new ComboPooledDataSource();
    String username = Settings.get(ArchiveSettings.DB_USERNAME);
    if (!username.isEmpty()) {
        dataSource.setUser(username);
    }
    String password = Settings.get(ArchiveSettings.DB_PASSWORD);
    if (!password.isEmpty()) {
        dataSource.setPassword(password);
    }
    try {
        dataSource.setDriverClass(dbSpec.getDriverClassName());
    } catch (PropertyVetoException e) {
        final String message =
            "Failed to set datasource JDBC driver class '"
            + dbSpec.getDriverClassName() + "'" + "\n";
        throw new IOFailure(message, e);
    }
    dataSource.setJdbcUrl(jdbcUrl);

    // Configure pool size
    dataSource.setMinPoolSize(
            Settings.getInt(ArchiveSettings.DB_POOL_MIN_SIZE));
    dataSource.setMaxPoolSize(
            Settings.getInt(ArchiveSettings.DB_POOL_MAX_SIZE));
    dataSource.setAcquireIncrement(
            Settings.getInt(ArchiveSettings.DB_POOL_ACQ_INC));

    // Configure idle connection testing
    int testPeriod =
        Settings.getInt(ArchiveSettings.DB_POOL_IDLE_CONN_TEST_PERIOD);
    if (testPeriod > 0) {
        dataSource.setIdleConnectionTestPeriod(testPeriod);
        dataSource.setTestConnectionOnCheckin(
                Settings.getBoolean(
                        ArchiveSettings.DB_POOL_IDLE_CONN_TEST_ON_CHECKIN));
        String testQuery =
            Settings.get(ArchiveSettings.DB_POOL_IDLE_CONN_TEST_QUERY);
        if (!testQuery.isEmpty()) {
            dataSource.setPreferredTestQuery(testQuery);
        }
    }

    // Configure statement pooling
    dataSource.setMaxStatements(
            Settings.getInt(ArchiveSettings.DB_POOL_MAX_STM));
    dataSource.setMaxStatementsPerConnection(
            Settings.getInt(ArchiveSettings.DB_POOL_MAX_STM_PER_CONN));

    if (log.isInfoEnabled()) {
        String msg = 
                "Connection pool initialized with the following values:";
        msg += "\n- minPoolSize=" + dataSource.getMinPoolSize();
        msg += "\n- maxPoolSize=" + dataSource.getMaxPoolSize();
        msg += "\n- acquireIncrement=" + dataSource.getAcquireIncrement();
        msg += "\n- maxStatements=" + dataSource.getMaxStatements();
        msg += "\n- maxStatementsPerConnection="
            + dataSource.getMaxStatementsPerConnection();
        msg += "\n- idleConnTestPeriod="
            + dataSource.getIdleConnectionTestPeriod();
        msg += "\n- idleConnTestQuery='"
            + dataSource.getPreferredTestQuery() + "'";
        msg += "\n- idleConnTestOnCheckin="
            + dataSource.isTestConnectionOnCheckin();
        log.info(msg.toString());
    }
}
 
開發者ID:netarchivesuite,項目名稱:netarchivesuite-svngit-migration,代碼行數:76,代碼來源:ArchiveDBConnection.java

示例14: initDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Initializes the connection pool.
 * @param dbSpec the object representing the chosen DB target system.
 * @param jdbcUrl the JDBC URL to connect to.
 * @throws SQLException 
 */
private static void initDataSource(DBSpecifics dbSpec, String jdbcUrl)
throws SQLException {

    dataSource = new ComboPooledDataSource();
    try {
        dataSource.setDriverClass(dbSpec.getDriverClassName());
    } catch (PropertyVetoException e) {
        final String message =
            "Failed to set datasource JDBC driver class '"
            + dbSpec.getDriverClassName() + "'" + "\n";
        throw new IOFailure(message, e);
    }
    dataSource.setJdbcUrl(jdbcUrl);
    String username = Settings.get(CommonSettings.DB_USERNAME);
    if (!username.isEmpty()) {
        dataSource.setUser(username);
    }
    String password = Settings.get(CommonSettings.DB_PASSWORD);
    if (!password.isEmpty()) {
        dataSource.setPassword(password);
    }
    // Configure pool size
    dataSource.setMinPoolSize(
            Settings.getInt(CommonSettings.DB_POOL_MIN_SIZE));
    dataSource.setMaxPoolSize(
            Settings.getInt(CommonSettings.DB_POOL_MAX_SIZE));
    dataSource.setAcquireIncrement(
            Settings.getInt(CommonSettings.DB_POOL_ACQ_INC));

    // Configure idle connection testing
    int testPeriod =
        Settings.getInt(CommonSettings.DB_POOL_IDLE_CONN_TEST_PERIOD);
    //TODO This looks odd. Why is checkin-testing inside this if statement?
    if (testPeriod > 0) {
        dataSource.setIdleConnectionTestPeriod(testPeriod);
        dataSource.setTestConnectionOnCheckin(
                Settings.getBoolean(
                        CommonSettings.DB_POOL_IDLE_CONN_TEST_ON_CHECKIN));
        String testQuery =
            Settings.get(CommonSettings.DB_POOL_IDLE_CONN_TEST_QUERY);
        if (!testQuery.isEmpty()) {
            dataSource.setPreferredTestQuery(testQuery);
        }
    }

    // Configure statement pooling
    dataSource.setMaxStatements(
            Settings.getInt(CommonSettings.DB_POOL_MAX_STM));
    dataSource.setMaxStatementsPerConnection(
            Settings.getInt(CommonSettings.DB_POOL_MAX_STM_PER_CONN));

    //dataSource.setTestConnectionOnCheckout(true);
    //dataSource.setBreakAfterAcquireFailure(false);
    //dataSource.setAcquireRetryAttempts(10000);
    //dataSource.setAcquireRetryDelay(10);

    if (log.isInfoEnabled()) {
        String msg = 
                "Connection pool initialized with the following values:";
        msg += "\n- minPoolSize=" + dataSource.getMinPoolSize();
        msg += "\n- maxPoolSize=" + dataSource.getMaxPoolSize();
        msg += "\n- acquireIncrement=" + dataSource.getAcquireIncrement();
        msg += "\n- maxStatements=" + dataSource.getMaxStatements();
        msg += "\n- maxStatementsPerConnection="
            + dataSource.getMaxStatementsPerConnection();
        msg += "\n- idleConnTestPeriod="
            + dataSource.getIdleConnectionTestPeriod();
        msg += "\n- idleConnTestQuery='"
            + dataSource.getPreferredTestQuery() + "'";
        msg += "\n- idleConnTestOnCheckin="
            + dataSource.isTestConnectionOnCheckin();
        log.info(msg.toString());
    }
}
 
開發者ID:netarchivesuite,項目名稱:netarchivesuite-svngit-migration,代碼行數:81,代碼來源:HarvestDBConnection.java

示例15: 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.setMaxStatementsPerConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。