当前位置: 首页>>代码示例>>Java>>正文


Java KeyedObjectPoolFactory类代码示例

本文整理汇总了Java中org.apache.commons.pool.KeyedObjectPoolFactory的典型用法代码示例。如果您正苦于以下问题:Java KeyedObjectPoolFactory类的具体用法?Java KeyedObjectPoolFactory怎么用?Java KeyedObjectPoolFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyedObjectPoolFactory类属于org.apache.commons.pool包,在下文中一共展示了KeyedObjectPoolFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PoolableConnectionFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
/**
 * 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
 */
public PoolableConnectionFactory(
    ConnectionFactory connFactory,
    ObjectPool pool,
    KeyedObjectPoolFactory stmtPoolFactory,
    String validationQuery,
    boolean defaultReadOnly,
    boolean defaultAutoCommit,
    AbandonedConfig config) {

    _connFactory = connFactory;
    _pool = pool;
    _config = config;
    _pool.setFactory(this);
    _stmtPoolFactory = stmtPoolFactory;
    _validationQuery = validationQuery;
    _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
    _defaultAutoCommit = defaultAutoCommit;
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:29,代码来源:PoolableConnectionFactory.java

示例2: testStmtPool

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
public void testStmtPool() throws Exception {
    new TesterDriver();
    ConnectionFactory connFactory = new DriverManagerConnectionFactory(
            "jdbc:apache:commons:testdriver","u1","p1");

    ObjectPool connPool = new GenericObjectPool();
    KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);

    new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
            null, false, true);

    DataSource ds = new PoolingDataSource(connPool);

    Connection conn = ds.getConnection();
    Statement stmt1 = conn.prepareStatement("select 1 from dual");
    Statement ustmt1 = ((DelegatingStatement) stmt1).getInnermostDelegate();
    stmt1.close();
    Statement stmt2 = conn.prepareStatement("select 1 from dual");
    Statement ustmt2 = ((DelegatingStatement) stmt2).getInnermostDelegate();
    stmt2.close();
    assertSame(ustmt1, ustmt2);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:23,代码来源:TestPStmtPooling.java

示例3: StatementClosingPoolableConnectionFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
/**
 * Default superclass constructor.
 *
 * @throws Exception When there is an error in the PoolableConnectionFactory constructor.
 */
public StatementClosingPoolableConnectionFactory(ConnectionFactory factory,
												 ObjectPool pool,
												 KeyedObjectPoolFactory stmtPoolFactory,
												 String validationQuery,
												 boolean defaultReadOnly,
												 boolean defaultAutoCommit)
	throws Exception {

	super(factory, pool, stmtPoolFactory, validationQuery,
		  defaultReadOnly, defaultAutoCommit);
}
 
开发者ID:SQLPower,项目名称:sqlpower-library,代码行数:17,代码来源:StatementClosingPoolableConnectionFactory.java

示例4: initConnection

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
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);
}
 
开发者ID:sunenielsen,项目名称:tribaltrouble,代码行数:9,代码来源:DBUtils.java

示例5: createStatementPoolFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
protected KeyedObjectPoolFactory createStatementPoolFactory() {
	return new GenericKeyedObjectPoolFactory(null, 
               -1, // unlimited maxActive (per key)
               GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 
               0, // maxWait
               1, // maxIdle (per key) 
               getPreparedStatementCacheSize()); 
}
 
开发者ID:kuali,项目名称:rice,代码行数:9,代码来源:RiceXADataSource.java

示例6: testCallableStatementPooling

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
public void testCallableStatementPooling() throws Exception {
    new TesterDriver();
    ConnectionFactory connFactory = new DriverManagerConnectionFactory(
            "jdbc:apache:commons:testdriver","u1","p1");

    ObjectPool connPool = new GenericObjectPool();
    KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);

    new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
            null, false, true);

    DataSource ds = new PoolingDataSource(connPool);

    Connection conn = ds.getConnection();
    Statement stmt1 = conn.prepareStatement("select 1 from dual");
    Statement ustmt1 = ((DelegatingStatement) stmt1).getInnermostDelegate();
    Statement cstmt1 = conn.prepareCall("{call home}");
    Statement ucstmt1 = ((DelegatingStatement) cstmt1).getInnermostDelegate();
    stmt1.close();  // Return to pool
    cstmt1.close(); // ""
    Statement stmt2 = conn.prepareStatement("select 1 from dual"); // Check out from pool
    Statement ustmt2 = ((DelegatingStatement) stmt2).getInnermostDelegate();
    Statement cstmt2 = conn.prepareCall("{call home}");
    Statement ucstmt2 = ((DelegatingStatement) cstmt2).getInnermostDelegate();
    stmt2.close();  // Return to pool
    cstmt2.close(); // ""
    assertSame(ustmt1, ustmt2);
    assertSame(ucstmt1, ucstmt2);
    // Verify key distinguishes Callable from Prepared Statements in the pool
    Statement stmt3 = conn.prepareCall("select 1 from dual");
    Statement ustmt3 = ((DelegatingStatement) stmt3).getInnermostDelegate();
    stmt3.close();
    assertNotSame(ustmt1, ustmt3);
    assertNotSame(ustmt3, ucstmt1);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:36,代码来源:TestPStmtPooling.java

示例7: testClosePool

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
public void testClosePool() throws Exception {
    new TesterDriver();
    ConnectionFactory connFactory = new DriverManagerConnectionFactory(
            "jdbc:apache:commons:testdriver","u1","p1");

    ObjectPool connPool = new GenericObjectPool();
    KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);

    new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
            null, false, true);

    DataSource ds = new PoolingDataSource(connPool);
    ((PoolingDataSource) ds).setAccessToUnderlyingConnectionAllowed(true);

    Connection conn = ds.getConnection();
    conn.prepareStatement("select 1 from dual");
    
    Connection poolableConnection = ((DelegatingConnection) conn).getDelegate();
    Connection poolingConnection = 
        ((DelegatingConnection) poolableConnection).getDelegate();
    poolingConnection.close();
    try {
        conn.prepareStatement("select 1 from dual");
        fail("Expecting SQLException");
    } catch (SQLException ex) {
        assertTrue(ex.getMessage().endsWith("invalid PoolingConnection."));
    }     
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:29,代码来源:TestPStmtPooling.java

示例8: setupDataSource

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
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;
}
 
开发者ID:warlock-china,项目名称:wisp,代码行数:49,代码来源:DbWrapper.java

示例9: addNewPool

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
public void addNewPool(String dbDriver, String dbServer, String dbLogin, String dbPassword,
    int minConns, int maxConns, double maxConnTime, String dbSessionConfig, String _rdbms,
    String name) throws Exception {

  if (this.defaultPoolName == null || this.defaultPoolName.equals("")) {
    this.defaultPoolName = name;
    this.bbdd = dbServer;
    this.rdbms = _rdbms;
  }
  if (externalConnectionPool != null) {
    // No need to create and add a new pool
    return;
  }

  log4j.debug("Loading underlying JDBC driver.");
  try {
    Class.forName(dbDriver);
  } catch (ClassNotFoundException e) {
    throw new Exception(e);
  }
  log4j.debug("Done.");

  GenericObjectPool connectionPool = new GenericObjectPool(null);
  connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
  connectionPool.setMaxActive(maxConns);
  connectionPool.setTestOnBorrow(false);
  connectionPool.setTestOnReturn(false);
  connectionPool.setTestWhileIdle(false);

  KeyedObjectPoolFactory keyedObject = new StackKeyedObjectPoolFactory();
  ConnectionFactory connectionFactory = new OpenbravoDriverManagerConnectionFactory(dbServer,
      dbLogin, dbPassword, dbSessionConfig, _rdbms);
  @SuppressWarnings("unused")
  // required by dbcp
  PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
      connectionFactory, connectionPool, keyedObject, null, false, true);

  Class.forName("org.apache.commons.dbcp.PoolingDriver");
  PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
  driver.registerPool(contextName + "_" + name, connectionPool);

}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:43,代码来源:ConnectionProviderImpl.java

示例10: TraceablePoolableConnectionFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
TraceablePoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit) {
  super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit);
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:4,代码来源:DBCPConnectionFactory.java

示例11: PoolableManagedConnectionFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
/**
 * Create a PoolableManagedConnectionFactory and attach it to a connection pool.
 * 
 * @param connFactory XAConnectionFactory
 * @param pool connection pool 
 * @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 validationQueryTimeout the number of seconds that validation queries will wait for database response
 * before failing. Use a value less than or equal to 0 for no timeout.
 * @param connectionInitSqls a Collection of SQL statements to initialize {@link Connection}s.
 * Using <tt>null</tt> turns off initialization.
 * @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
 */
public PoolableManagedConnectionFactory(XAConnectionFactory connFactory,
        ObjectPool pool,
        KeyedObjectPoolFactory stmtPoolFactory,
        String validationQuery,
        int validationQueryTimeout,
        Collection connectionInitSqls,
        Boolean defaultReadOnly,
        boolean defaultAutoCommit,
        int defaultTransactionIsolation,
        String defaultCatalog,
        AbandonedConfig config) {
    super(connFactory, pool, stmtPoolFactory, validationQuery, validationQueryTimeout, connectionInitSqls,
            defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config);
    this.transactionRegistry = connFactory.getTransactionRegistry();
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:35,代码来源:PoolableManagedConnectionFactory.java

示例12: makeFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) {
    return new GenericKeyedObjectPoolFactory(objectFactory);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:4,代码来源:TestGenericKeyedObjectPoolFactory.java

示例13: makeFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
    return new StackKeyedObjectPoolFactory(objectFactory);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:4,代码来源:TestStackKeyedObjectPoolFactory.java

示例14: SakaiPoolableConnectionFactory

import org.apache.commons.pool.KeyedObjectPoolFactory; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:25,代码来源:SakaiPoolableConnectionFactory.java


注:本文中的org.apache.commons.pool.KeyedObjectPoolFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。