use of org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory in project cloudstack by apache.
the class TransactionLegacy method getDefaultDataSource.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static DataSource getDefaultDataSource(final String database) {
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
return new PoolingDataSource(connectionPool);
}
use of org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory in project tomcat by apache.
the class BasicManagedDataSource method createPoolableConnectionFactory.
/**
* Creates the PoolableConnectionFactory and attaches it to the connection pool.
*
* @param driverConnectionFactory
* JDBC connection factory created by {@link #createConnectionFactory()}
* @throws SQLException
* if an error occurs creating the PoolableConnectionFactory
*/
@Override
protected PoolableConnectionFactory createPoolableConnectionFactory(final ConnectionFactory driverConnectionFactory) throws SQLException {
PoolableConnectionFactory connectionFactory = null;
try {
connectionFactory = new PoolableManagedConnectionFactory((XAConnectionFactory) driverConnectionFactory, getRegisteredJmxName());
connectionFactory.setValidationQuery(getValidationQuery());
connectionFactory.setValidationQueryTimeout(getValidationQueryTimeoutDuration());
connectionFactory.setConnectionInitSql(getConnectionInitSqls());
connectionFactory.setDefaultReadOnly(getDefaultReadOnly());
connectionFactory.setDefaultAutoCommit(getDefaultAutoCommit());
connectionFactory.setDefaultTransactionIsolation(getDefaultTransactionIsolation());
connectionFactory.setDefaultCatalog(getDefaultCatalog());
connectionFactory.setDefaultSchema(getDefaultSchema());
connectionFactory.setCacheState(getCacheState());
connectionFactory.setPoolStatements(isPoolPreparedStatements());
connectionFactory.setClearStatementPoolOnReturn(isClearStatementPoolOnReturn());
connectionFactory.setMaxOpenPreparedStatements(getMaxOpenPreparedStatements());
connectionFactory.setMaxConn(getMaxConnDuration());
connectionFactory.setRollbackOnReturn(getRollbackOnReturn());
connectionFactory.setAutoCommitOnReturn(getAutoCommitOnReturn());
connectionFactory.setDefaultQueryTimeout(getDefaultQueryTimeoutDuration());
connectionFactory.setFastFailValidation(getFastFailValidation());
connectionFactory.setDisconnectionSqlCodes(getDisconnectionSqlCodes());
validateConnectionFactory(connectionFactory);
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
throw new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
}
return connectionFactory;
}
Aggregations