コード例 #1
0
 /**
  * If pooling of <code>PreparedStatement</code>s is turned on in the {@link DriverAdapterCPDS}, a
  * pooled object may be returned, otherwise delegate to the wrapped jdbc 1.x {@link
  * java.sql.Connection}.
  *
  * @exception SQLException if this connection is closed or an error occurs in the wrapped
  *     connection.
  */
 public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
     throws SQLException {
   assertOpen();
   return pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency);
 }
コード例 #2
0
 /**
  * Marks the Connection as closed, and notifies the pool that the pooled connection is available.
  * In accordance with the jdbc specification this Connection cannot be used after closed() is
  * called. Any further usage will result in an SQLException.
  *
  * @exception SQLException The database connection couldn't be closed.
  */
 public void close() throws SQLException {
   isClosed = true;
   pooledConnection.notifyListeners();
 }
コード例 #3
0
 /**
  * If pooling of <code>PreparedStatement</code>s is turned on in the {@link DriverAdapterCPDS}, a
  * pooled object may be returned, otherwise delegate to the wrapped jdbc 1.x {@link
  * java.sql.Connection}.
  *
  * @exception SQLException if this connection is closed or an error occurs in the wrapped
  *     connection.
  */
 public PreparedStatement prepareStatement(String sql) throws SQLException {
   assertOpen();
   return pooledConnection.prepareStatement(sql);
 }
コード例 #4
0
 /**
  * Attempt to establish a database connection.
  *
  * @param username name to be used for the connection
  * @param pass password to be used fur the connection
  */
 public PooledConnection getPooledConnection(String username, String pass) throws SQLException {
   getConnectionCalled = true;
   /*
   public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
   int maxActive, byte whenExhaustedAction, long maxWait,
   int maxIdle, boolean testOnBorrow, boolean testOnReturn,
   long timeBetweenEvictionRunsMillis,
   int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
   boolean testWhileIdle) {
   */
   KeyedObjectPool stmtPool = null;
   if (isPoolPreparedStatements()) {
     if (getMaxPreparedStatements() <= 0) {
       // since there is no limit, create a prepared statement pool with an eviction thread
       //  evictor settings are the same as the connection pool settings.
       stmtPool =
           new GenericKeyedObjectPool(
               null,
               getMaxActive(),
               GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW,
               0,
               getMaxIdle(),
               false,
               false,
               getTimeBetweenEvictionRunsMillis(),
               getNumTestsPerEvictionRun(),
               getMinEvictableIdleTimeMillis(),
               false);
     } else {
       // since there is limit, create a prepared statement pool without an eviction thread
       //  pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
       // see org.apache.commons.pool.impl.GenericKeyedObjectPool.clearOldest method
       stmtPool =
           new GenericKeyedObjectPool(
               null,
               getMaxActive(),
               GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW,
               0,
               getMaxIdle(),
               getMaxPreparedStatements(),
               false,
               false,
               -1,
               0,
               0, // -1 tells the pool that there should be no eviction thread.
               false);
     }
   }
   // Workaround for buggy WebLogic 5.1 classloader - ignore the
   // exception upon first invocation.
   try {
     PooledConnectionImpl pci = null;
     if (connectionProperties != null) {
       connectionProperties.put("user", username);
       connectionProperties.put("password", pass);
       pci =
           new PooledConnectionImpl(
               DriverManager.getConnection(getUrl(), connectionProperties), stmtPool);
     } else {
       pci =
           new PooledConnectionImpl(
               DriverManager.getConnection(getUrl(), username, pass), stmtPool);
     }
     pci.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
     return pci;
   } catch (ClassCircularityError e) {
     PooledConnectionImpl pci = null;
     if (connectionProperties != null) {
       pci =
           new PooledConnectionImpl(
               DriverManager.getConnection(getUrl(), connectionProperties), stmtPool);
     } else {
       pci =
           new PooledConnectionImpl(
               DriverManager.getConnection(getUrl(), username, pass), stmtPool);
     }
     pci.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
     return pci;
   }
 }