本文整理汇总了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setTestConnectionOnCheckout方法的典型用法代码示例。如果您正苦于以下问题:Java ComboPooledDataSource.setTestConnectionOnCheckout方法的具体用法?Java ComboPooledDataSource.setTestConnectionOnCheckout怎么用?Java ComboPooledDataSource.setTestConnectionOnCheckout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setTestConnectionOnCheckout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static boolean initialize(String url, String user, String password, int minPoolSize, int maxPoolSize,
int poolIncrement) {
try {
cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.cj.jdbc.Driver");
cpds.setJdbcUrl(url);
cpds.setUser(user);
cpds.setPassword(password);
cpds.setInitialPoolSize(minPoolSize);
cpds.setMinPoolSize(minPoolSize);
cpds.setAcquireIncrement(poolIncrement);
cpds.setMaxPoolSize(maxPoolSize);
cpds.setNumHelperThreads(Nomad.DB_WORKERS);
cpds.setTestConnectionOnCheckout(true);
} catch (Exception e) {
logger.error("Failed to initialize DB.", e);
return false;
}
logger.debug("Initialized DB.");
return true;
}
示例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: 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);
}
示例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 = "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);
}
示例5: init
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public void init(String configurationName, Map<String, String> properties) {
this.configurationName = configurationName;
this.properties = new HashMap<>(properties);
String connectionKey = getConnectionKey();
try {
String driver = property("driver");
String userName = property("user");
String password = property("pass");
cpds = new ComboPooledDataSource();
cpds.setDriverClass(driver);
cpds.setJdbcUrl(getJdbcUrl());
cpds.setUser(userName);
cpds.setPassword(password);
int minPoolSize = Integer.parseInt(property("pool_min_size"));
int aquireIncrement = Integer.parseInt(property("pool_increment_by"));
int maxPoolSize = Integer.parseInt(property("pool_max_size"));
cpds.setMinPoolSize(minPoolSize);
cpds.setAcquireIncrement(aquireIncrement);
cpds.setMaxPoolSize(maxPoolSize);
cpds.setIdleConnectionTestPeriod(300);
cpds.setPreferredTestQuery("SELECT 1");
cpds.setTestConnectionOnCheckin(false);
cpds.setTestConnectionOnCheckout(false);
} catch (Throwable t) {
throw new RuntimeException("Unable to establich SQL connection for JDBC-key: " + connectionKey, t);
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:35,代码来源:MySqlDatabaseConnection.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;
}
}
示例7: 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);
}
示例8: start
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public void start() {
cpds = new ComboPooledDataSource();
cpds.setJdbcUrl(getServerURL());
cpds.setUser(getUsername());
cpds.setPassword(getPassword());
cpds.setMinPoolSize(getMinConnections());
cpds.setMaxPoolSize(getMaxConnections());
cpds.setIdleConnectionTestPeriod(getIdleTestInterval());
cpds.setTestConnectionOnCheckout(getTestBeforeUse());
cpds.setTestConnectionOnCheckin(getTestAfterUse());
cpds.setPreferredTestQuery(getTestSQL());
cpds.setMaxConnectionAge(getConnectionTimeout());
}
示例9: createDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public DataSource createDataSource(String url, String username, String password, int initialSize, int maxPoolSize) throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl(url);
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setInitialPoolSize(initialSize);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setTestConnectionOnCheckout(true);
return dataSource;
}
示例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);
}
}
示例11: 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);
}
示例12: init
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public void init(Map<String, String> configuration) {
try {
Class.forName("com.mysql.jdbc.Driver");
String connectURI = "jdbc:mysql://" + MYSQL_SERVER + ":"
+ MYSQL_PORT + "/" + MYSQL_DATABASE + "?"
+ "user=" + MYSQL_USER + "&password=" + MYSQL_PASSWORD;
datasource = new ComboPooledDataSource();
datasource.setJdbcUrl(connectURI);
datasource.setMaxPoolSize(16);
datasource.setMinPoolSize(4);
datasource.setInitialPoolSize(4);
datasource.setNumHelperThreads(6);
datasource.setTestConnectionOnCheckin(true);
datasource.setTestConnectionOnCheckout(true);
connection = datasource.getConnection();
preparedLookupStatement = connection
.prepareStatement("SELECT value FROM " + MYSQL_TABLE
+ " WHERE `key` = ?");
preparedDeleteStatement = connection
.prepareStatement("DELETE FROM " + MYSQL_TABLE
+ " WHERE `key` = ?");
preparedDeleteAllStatement = connection
.prepareStatement("DELETE FROM " + MYSQL_TABLE);
preparedInsertStatement = connection
.prepareStatement("INSERT INTO " + MYSQL_TABLE
+ " (`key`, value) VALUES (?, ?)");
preparedCreateTableStatement = connection
.prepareStatement("CREATE TABLE "
+ MYSQL_TABLE
+ " (`key` VARCHAR(255) NOT NULL, value BLOB NOT NULL, PRIMARY KEY (`key`))"
+ "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");
preparedCreateDatabaseStatement = connection
.prepareStatement("CREATE DATABASE IF NOT EXISTS "
+ MYSQL_DATABASE);
// Check if database exist, on fail, create it
//
preparedCreateDatabaseStatement.executeUpdate();
// Check if table exist, on fail, create it
//
DatabaseMetaData dbm = connection.getMetaData();
resultSet = dbm.getTables(null, null, MYSQL_TABLE, null);
if (!resultSet.next()) {
preparedCreateTableStatement.executeUpdate();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}