org.apache.commons.pool.KeyedObjectPoolFactory Java Examples
The following examples show how to use
org.apache.commons.pool.KeyedObjectPoolFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBUtils.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
public final static void initConnection(String address, String user, String password) throws ClassNotFoundException { Class.forName("com.mysql.jdbc.Driver"); GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(address, user, password); KeyedObjectPoolFactory keyed_factory = new StackKeyedObjectPoolFactory(); new PoolableConnectionFactory(connectionFactory, connectionPool, keyed_factory, null, false, true); ds = new PoolingDataSource(connectionPool); }
Example #2
Source File: RiceXADataSource.java From rice with Educational Community License v2.0 | 5 votes |
protected KeyedObjectPoolFactory createStatementPoolFactory() { return new GenericKeyedObjectPoolFactory(null, -1, // unlimited maxActive (per key) GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0, // maxWait 1, // maxIdle (per key) getPreparedStatementCacheSize()); }
Example #3
Source File: DbWrapper.java From wisp with Apache License 2.0 | 4 votes |
private DataSource setupDataSource(String driver, String connectURI, String userName, String passwd) throws ClassNotFoundException { // driver Class.forName(driver); // // First, we'll need a ObjectPool that serves as the // actual pool of connections. // // We'll use a GenericObjectPool instance, although // any ObjectPool implementation will suffice. // GenericObjectPool connectionPool = new GenericObjectPool(null); // 设置在getConnection时验证Connection是否有效 connectionPool.setTestOnBorrow(true); // // Next, we'll create a ConnectionFactory that the // pool will use to create Connections. // We'll use the DriverManagerConnectionFactory, // using the connect string passed in the command line // arguments. // ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, userName, passwd); // null can be used as parameter because this parameter is set in // PoolableConnectionFactory when creating a new PoolableConnection KeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory( null); // // Now we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, "select now()", false, true); // // Finally, we create the PoolingDriver itself, // passing in the object pool we created. // PoolingDataSource dataSource = new PoolingDataSource(connectionPool); return dataSource; }
Example #4
Source File: DBCPConnectionFactory.java From ontopia with Apache License 2.0 | 4 votes |
TraceablePoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit); }
Example #5
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit); m_rollbackOnReturn = rollbackOnReturn; }
Example #6
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation); m_rollbackOnReturn = rollbackOnReturn; }
Example #7
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #8
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #9
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param defaultCatalog * the default "catalog" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #10
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param defaultCatalog * the default "catalog" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #11
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit); m_rollbackOnReturn = rollbackOnReturn; }
Example #12
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation); m_rollbackOnReturn = rollbackOnReturn; }
Example #13
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #14
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #15
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param defaultCatalog * the default "catalog" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting * @deprecated AbandonedConfig is now deprecated. */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config); m_rollbackOnReturn = rollbackOnReturn; }
Example #16
Source File: SakaiPoolableConnectionFactory.java From sakai with Educational Community License v2.0 | 3 votes |
/** * Create a new <tt>PoolableConnectionFactory</tt>. * * @param connFactory * the {@link ConnectionFactory} from which to obtain base {@link Connection}s * @param pool * the {@link ObjectPool} in which to pool those {@link Connection}s * @param stmtPoolFactory * the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling * @param validationQuery * a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one row. Using <tt>null</tt> turns off validation. * @param defaultReadOnly * the default "read only" setting for borrowed {@link Connection}s * @param defaultAutoCommit * the default "auto commit" setting for returned {@link Connection}s * @param defaultTransactionIsolation * the default "Transaction Isolation" setting for returned {@link Connection}s * @param defaultCatalog * the default "catalog" setting for returned {@link Connection}s * @param config * the AbandonedConfig if tracing SQL objects * @param rollbackOnReturn * The rollback on borrow setting */ public SakaiPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config, boolean rollbackOnReturn) { super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config); m_rollbackOnReturn = rollbackOnReturn; }