commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp BasicDataSourceFactory.java BasicDataSource.java
Date Tue, 26 Aug 2003 14:19:28 GMT
dirkv       2003/08/26 07:19:28

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        BasicDataSourceFactory.java BasicDataSource.java
  Log:
  Bugzilla Bug 18012: BasicDataSource doesn't include PreparedStmt Pooling
  
  implementation of the requested feature
  started from patch from Mike Patnode but used the new maxTotal parameter
  to limit the MaxOpenPreparedStatements
  
  Revision  Changes    Path
  1.9       +15 -3     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
  
  Index: BasicDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BasicDataSourceFactory.java	25 Aug 2003 16:17:45 -0000	1.8
  +++ BasicDataSourceFactory.java	26 Aug 2003 14:19:28 -0000	1.9
  @@ -273,6 +273,18 @@
                   (Boolean.valueOf(ra.getContent().toString()).booleanValue());
           }
   
  +        ra = ref.get("poolPreparedStatements");
  +        if (ra != null) {
  +            dataSource.setPoolPreparedStatements
  +                (Boolean.valueOf(ra.getContent().toString()).booleanValue());
  +        }
  +
  +        ra = ref.get("maxOpenPreparedStatements");
  +        if (ra != null) {
  +            dataSource.setMaxOpenPreparedStatements
  +                (Integer.parseInt(ra.getContent().toString()));
  +        }
  +
           ra = ref.get("connectionProperties");
           if (ra != null) {
             Properties p = getProperties(ra.getContent().toString());
  
  
  
  1.22      +57 -7     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java
  
  Index: BasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- BasicDataSource.java	25 Aug 2003 16:17:45 -0000	1.21
  +++ BasicDataSource.java	26 Aug 2003 14:19:28 -0000	1.22
  @@ -68,9 +68,9 @@
   import java.sql.DriverManager;
   import java.sql.SQLException;
   import javax.sql.DataSource;
  -import org.apache.commons.dbcp.DriverConnectionFactory;
  -import org.apache.commons.dbcp.PoolableConnectionFactory;
  -import org.apache.commons.dbcp.PoolingDataSource;
  +
  +import org.apache.commons.pool.impl.GenericKeyedObjectPool;
  +import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
   import org.apache.commons.pool.impl.GenericObjectPool;
   
   
  @@ -205,6 +205,45 @@
       }
   
       /**
  +     * Prepared statement pooling for this pool.
  +     */
  +    protected boolean poolPreparedStatements = false;
  +    
  +    /**
  +     * Returns true if we are pooling statements.
  +     * @return boolean
  +     */
  +    public boolean isPoolPreparedStatements()
  +    {
  +        return poolPreparedStatements;
  +    }
  +
  +    /**
  +     * Sets whether to pool statements or not.
  +     * @param poolPreparedStatements pooling on or off
  +     */
  +    public void setPoolPreparedStatements(boolean poolingStatements)
  +    {
  +         this.poolPreparedStatements = poolingStatements;
  +    }
  +
  +    /**
  +     * The maximum number of open statements that can be allocated from
  +     * the statement pool at the same time, or zero for no limit.  Since 
  +     * a connection usually only uses one or two statements at a time, this is
  +     * mostly used to help detect resource leaks.
  +     */
  +    protected int maxOpenPreparedStatements = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
  +
  +    public int getMaxOpenPreparedStatements() {
  +        return maxOpenPreparedStatements;
  +    }
  +
  +    public void setMaxOpenPreparedStatements(int maxOpenStatements) {
  +        this.maxOpenPreparedStatements = maxOpenStatements;
  +    }
  +
  +    /**
        * The indication of whether objects will be validated before being
        * borrowed from the pool.  If the object fails to validate, it will be
        * dropped from the pool, and we will attempt to borrow another.
  @@ -697,6 +736,17 @@
               connectionPool.setTestOnBorrow(true);
           }
   
  +        // Set up statement pool, if desired
  +        GenericKeyedObjectPoolFactory statementPoolFactory = null;
  +        if (isPoolPreparedStatements()) {
  +            statementPoolFactory = new GenericKeyedObjectPoolFactory(null, 
  +                        -1, // unlimited maxActive (per key)
  +                        GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL, 
  +                        0, // maxWait
  +                        1, // maxIdle (per key) 
  +                        maxOpenPreparedStatements); 
  +        }
  +
           // Set up the driver connection factory we will use
           if (username != null) {
               connectionProperties.put("user", username);
  @@ -719,7 +769,7 @@
               connectionFactory =
                   new PoolableConnectionFactory(driverConnectionFactory,
                                                 connectionPool,
  -                                              null, // FIXME - stmtPoolFactory?
  +                                              statementPoolFactory,
                                                 validationQuery,
                                                 defaultReadOnly,
                                                 defaultAutoCommit,
  
  
  

Mime
View raw message