本文整理汇总了Java中org.apache.commons.pool.KeyedObjectPool.setFactory方法的典型用法代码示例。如果您正苦于以下问题:Java KeyedObjectPool.setFactory方法的具体用法?Java KeyedObjectPool.setFactory怎么用?Java KeyedObjectPool.setFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool.KeyedObjectPool
的用法示例。
在下文中一共展示了KeyedObjectPool.setFactory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapConnection
import org.apache.commons.pool.KeyedObjectPool; //导入方法依赖的package包/类
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();
}
KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
PreparedStatementCachingConnection wrappedConnection = new PreparedStatementCachingConnection(realConnection, stmtpool);
stmtpool.setFactory(wrappedConnection);
return wrappedConnection;
}
示例2: makeObject
import org.apache.commons.pool.KeyedObjectPool; //导入方法依赖的package包/类
public Object makeObject() throws Exception {
Connection conn = _connFactory.createConnection();
if (conn == null) {
throw new IllegalStateException("Connection factory returned null from createConnection");
}
initializeConnection(conn);
if(null != _stmtPoolFactory) {
KeyedObjectPool stmtpool = _stmtPoolFactory.createPool();
conn = new PoolingConnection(conn,stmtpool);
stmtpool.setFactory((PoolingConnection)conn);
}
return new PoolableConnection(conn,_pool,_config);
}
示例3: testSetFactory
import org.apache.commons.pool.KeyedObjectPool; //导入方法依赖的package包/类
public void testSetFactory() throws Exception {
KeyedObjectPool pool = new StackKeyedObjectPool();
try {
pool.borrowObject("x");
fail("Expected NoSuchElementException");
} catch(NoSuchElementException e) {
// expected
}
pool.setFactory(new SimpleFactory());
Object obj = pool.borrowObject("x");
assertNotNull(obj);
pool.returnObject("x",obj);
}
示例4: testCantResetFactoryWithActiveObjects
import org.apache.commons.pool.KeyedObjectPool; //导入方法依赖的package包/类
public void testCantResetFactoryWithActiveObjects() throws Exception {
KeyedObjectPool pool = new StackKeyedObjectPool();
pool.setFactory(new SimpleFactory());
Object obj = pool.borrowObject("x");
assertNotNull(obj);
try {
pool.setFactory(new SimpleFactory());
fail("Expected IllegalStateException");
} catch(IllegalStateException e) {
// expected
}
}
示例5: KeyedCPDSConnectionFactory
import org.apache.commons.pool.KeyedObjectPool; //导入方法依赖的package包/类
/**
* Create a new <tt>KeyedPoolableConnectionFactory</tt>.
* @param cpds the ConnectionPoolDataSource from which to obtain
* PooledConnections
* @param pool the {@link KeyedObjectPool} in which to pool those
* {@link Connection}s
* @param validationQuery a query to use to {@link #validateObject validate}
* {@link Connection}s. Should return at least one row. May be <tt>null</tt>
* @param rollbackAfterValidation whether a rollback should be issued after
* {@link #validateObject validating} {@link Connection}s.
*/
public KeyedCPDSConnectionFactory(ConnectionPoolDataSource cpds,
KeyedObjectPool pool,
String validationQuery,
boolean rollbackAfterValidation) {
_cpds = cpds;
_pool = pool;
pool.setFactory(this);
_validationQuery = validationQuery;
_rollbackAfterValidation = rollbackAfterValidation;
}