本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setBreakAfterAcquireFailure方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.setBreakAfterAcquireFailure方法的具體用法?Java ComboPooledDataSource.setBreakAfterAcquireFailure怎麽用?Java ComboPooledDataSource.setBreakAfterAcquireFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setBreakAfterAcquireFailure方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerC3P0DataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Test
public void registerC3P0DataSource() throws Exception {
MetricCollector metricCollector = MonitoringCenter.getMetricCollector(MonitoringCenterTest.class);
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver");
cpds.setMinPoolSize(2);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);
cpds.setMaxStatements(180);
cpds.setBreakAfterAcquireFailure(true);
metricCollector.registerC3P0DataSource(cpds, "testDB");
C3P0PooledDataSourceMetricSet c3P0PooledDataSourceMetricSet = new C3P0PooledDataSourceMetricSet(cpds);
String[] startsWithFilters = {"MonitoringCenterTest."};
Assert.assertEquals(c3P0PooledDataSourceMetricSet.getMetrics().size(), MonitoringCenter.getMetricsByNames(false, startsWithFilters).size());
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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&characterEncoding=UTF-8&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;
}
示例5: 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;
}