commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 18012] New: - BasicDataSource doesn't include PreparedStmt Pooling
Date Fri, 14 Mar 2003 19:20:50 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18012>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18012

BasicDataSource doesn't include PreparedStmt Pooling

           Summary: BasicDataSource doesn't include PreparedStmt Pooling
           Product: Commons
           Version: 1.0.1 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Dbcp
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: mike@mpsharp.com


BasicDataSource was missing prepared statement pooling.   Here's the patch

*** BasicDataSource.java.orig	Sat Jul 20 18:38:36 2002
--- BasicDataSource.java	Fri Mar 14 11:06:10 2003
***************
*** 71,76 ****
--- 71,78 ----
  import org.apache.commons.dbcp.PoolableConnectionFactory;
  import org.apache.commons.dbcp.PoolingDataSource;
  import org.apache.commons.pool.impl.GenericObjectPool;
+ import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+ import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
  
  
  /**
***************
*** 267,272 ****
--- 269,331 ----
      }
  
  
+     /**
+      * Prepared statement pooling for this pool.
+      */
+     protected boolean poolingStatements = true;
+     
+     /**
+      * Returns true if we are pooling statements.
+      * @return boolean
+      */
+     public boolean isPoolingStatements()
+     {
+         return poolingStatements;
+     }
+ 
+     /**
+      * Sets whether to pool statements or not.
+      * @param poolStatements pooling on or off
+      */
+     public void setPoolingStatements(boolean poolingStatements)
+     {
+          this.poolingStatements = 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.  A NoSuchElementException will
+      * be thrown when this limit is exceeded.
+      */
+     protected int maxOpenStatements = GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE;
+ 
+     public int getMaxOpenStatements() {
+         return (maxOpenStatements);
+     }
+ 
+     public void setMaxOpenStatements(int maxOpenStatements) {
+         this.maxOpenStatements = maxOpenStatements;
+     }
+     
+     /**
+      * The maximum number of statements that can be in
+      * the statement pool at the same time, or zero for no limit
+      */
+     protected int maxStatements = GenericKeyedObjectPool.DEFAULT_MAX_IDLE;
+ 
+     public int getMaxStatements() {
+         return (maxStatements);
+     }
+ 
+     public void setMaxStatements(int maxStatements) {
+         this.maxStatements = maxStatements;
+     }
+ 
+  
+ 
      // ----------------------------------------------------- Instance Variables
  
  
***************
*** 550,555 ****
--- 609,626 ----
              connectionPool.setTestOnBorrow(true);
          }
  
+         // Set up statement pool, if desired
+         GenericKeyedObjectPoolFactory statementFactory = null;
+         if (poolingStatements) {
+         	statementFactory = new GenericKeyedObjectPoolFactory(null, 
+                         maxOpenStatements,
+                         // If statements are unlimited, then always grow
+                         (maxOpenStatements == 0 || maxStatements == 0) ?
+                             GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW : 
+                             GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL, 
+                         0, maxStatements); 
+         }
+         
          // Set up the driver connection factory we will use
          if (username != null) {
              connectionProperties.put("user", username);
***************
*** 572,578 ****
              connectionFactory =
                  new PoolableConnectionFactory(driverConnectionFactory,
                                                connectionPool,
!                                               null, // FIXME - stmtPoolFactory?
                                                validationQuery,
                                                defaultReadOnly,
                                                defaultAutoCommit,
--- 643,649 ----
              connectionFactory =
                  new PoolableConnectionFactory(driverConnectionFactory,
                                                connectionPool,
!                                               statementFactory,
                                                validationQuery,
                                                defaultReadOnly,
                                                defaultAutoCommit,
*** BasicDataSourceFactory.java.orig	Fri Jun 21 15:56:14 2002
--- BasicDataSourceFactory.java	Fri Mar 14 10:16:13 2003
***************
*** 194,199 ****
--- 194,217 ----
                  (Boolean.valueOf(ra.getContent().toString()).booleanValue());
          }
  
+         ra = ref.get("poolStatements");
+         if (ra != null) {
+             dataSource.setPoolingStatements
+                 (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+         }
+ 		
+         ra = ref.get("maxStatements");
+         if (ra != null) {
+             dataSource.setMaxStatements
+                 (Integer.parseInt(ra.getContent().toString()));
+         }
+ 
+         ra = ref.get("maxOpenStatements");
+         if (ra != null) {
+             dataSource.setMaxOpenStatements
+                 (Integer.parseInt(ra.getContent().toString()));
+         }
+ 
          // Return the configured data source instance
          return (dataSource);

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message