本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.getMaxPoolSize方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.getMaxPoolSize方法的具體用法?Java ComboPooledDataSource.getMaxPoolSize怎麽用?Java ComboPooledDataSource.getMaxPoolSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.getMaxPoolSize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMaxConnectionsNumber
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public int getMaxConnectionsNumber(DataSource dataSource) {
try {
ComboPooledDataSource ds = (ComboPooledDataSource)dataSource;
return ds.getMaxPoolSize();
} catch (Exception e) {
if(logger.isDebugEnabled()){
logger.debug(" query C3P0 datasource="+dataSource+" max connections number fail");
}
return IllegalNumber;
}
}
示例2: 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());
}
}
示例3: 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());
}
}