List of usage examples for org.apache.commons.pool KeyedObjectPool setFactory
void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException;
From source file:edu.illinois.enforcemop.examples.apache.pool.TestBaseKeyedObjectPool.java
public void testUnsupportedOperations() throws Exception { if (!getClass().equals(TestBaseKeyedObjectPool.class)) { return; // skip redundant tests }// www . ja v a 2s .c om KeyedObjectPool pool = new BaseKeyedObjectPool() { public Object borrowObject(Object key) { return null; } public void returnObject(Object key, Object obj) { } public void invalidateObject(Object key, Object obj) { } }; try { pool.addObject("key"); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } assertTrue("Negative expected.", pool.getNumIdle() < 0); assertTrue("Negative expected.", pool.getNumIdle("key") < 0); assertTrue("Negative expected.", pool.getNumActive() < 0); assertTrue("Negative expected.", pool.getNumActive("key") < 0); try { pool.clear(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { pool.clear("key"); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { pool.setFactory(null); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } pool.close(); // a no-op, probably should be remove }
From source file:org.kuali.rice.core.framework.persistence.jdbc.datasource.RiceXADataSource.java
protected PreparedStatementCachingConnection wrapConnection(Connection realConnection) { // can't initialize the following variable in the constructor because the prepared statement cache size won't be available if (_stmtPoolFactory == null) { _stmtPoolFactory = createStatementPoolFactory(); }//from w w w. j a v a2 s.c o m KeyedObjectPool stmtpool = _stmtPoolFactory.createPool(); PreparedStatementCachingConnection wrappedConnection = new PreparedStatementCachingConnection( realConnection, stmtpool); stmtpool.setFactory(wrappedConnection); return wrappedConnection; }
From source file:org.nuxeo.runtime.datasource.PatchedPoolableManagedConnectionFactory.java
@Override synchronized public Object makeObject() throws Exception { Connection conn = _connFactory.createConnection(); if (conn == null) { throw new IllegalStateException("Connection factory returned null from createConnection"); }/* w w w. ja va2 s .co m*/ initializeConnection(conn); if (null != _stmtPoolFactory) { KeyedObjectPool stmtpool = _stmtPoolFactory.createPool(); conn = new PoolingConnection(conn, stmtpool); stmtpool.setFactory((PoolingConnection) conn); } // PATCH: use patched class return new PatchedPoolableManagedConnection(tr, conn, _pool, _config); }
From source file:org.openconcerto.sql.model.SQLDataSource.java
@Override protected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory, @SuppressWarnings("rawtypes") KeyedObjectPoolFactory statementPoolFactory, AbandonedConfig configuration) throws SQLException { PoolableConnectionFactory connectionFactory = null; try {/*from w ww .j a v a 2 s. c om*/ connectionFactory = new PoolableConnectionFactory(driverConnectionFactory, this.connectionPool, statementPoolFactory, this.validationQuery, this.validationQueryTimeout, this.connectionInitSqls, this.defaultReadOnly, this.defaultAutoCommit, this.defaultTransactionIsolation, this.defaultCatalog, configuration) { @Override public Object makeObject() throws Exception { Connection conn = this._connFactory.createConnection(); if (conn == null) { throw new IllegalStateException("Connection factory returned null from createConnection"); } initializeConnection(conn); setTransactionIsolation(conn); if (null != this._stmtPoolFactory) { @SuppressWarnings("rawtypes") KeyedObjectPool stmtpool = this._stmtPoolFactory.createPool(); conn = new PoolingConnection(conn, stmtpool); stmtpool.setFactory((PoolingConnection) conn); } return new TransactionPoolableConnection(conn, this._pool, this._config); } }; validateConnectionFactory(connectionFactory); } catch (RuntimeException e) { throw e; } catch (SQLException e) { // only wrap if necessary (calling code can use SQLState) throw e; } catch (Exception e) { throw new SQLException("Cannot create PoolableConnectionFactory", e); } }