commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1056867 - in /commons/proper/dbcp: branches/DBCP_1_4_x_BRANCH/src/changes/ branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/ branches/DBCP_1_4_x_BRANCH/src/site/xdoc/ branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/ ...
Date Sun, 09 Jan 2011 02:26:56 GMT
Author: psteitz
Date: Sun Jan  9 02:26:55 2011
New Revision: 1056867

URL: http://svn.apache.org/viewvc?rev=1056867&view=rev
Log:
Exposed pool LIFO property as config option for DBCP.
JIRA: DBCP-346
Reported and patched by Ken Tatsushita

Modified:
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/site/xdoc/configuration.xml
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
    commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml (original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml Sun Jan  9 02:26:55
2011
@@ -39,12 +39,17 @@ The <action> type attribute can be add,u
   </properties>
   <body>
     <release version="1.4.1" date="TBD" description="TBD">
-      <action dev="psteitz" issue="DBCP-344" due-to="Jeremy Whiting">
+      <action dev="psteitz" issue="DBCP-346" type="update" due-to="Ken Tatsushita">
+        LIFO configuration option has been added to BasicDataSource.  When set
+        to true (the default), the pool acts as a LIFO queue; setting to false
+        causes connections to enter and exit to pool in FIFO order.
+      </action>
+      <action dev="psteitz" issue="DBCP-344" type="fix" due-to="Jeremy Whiting">
         Test transitive dependencies brought in by geronimo-transaction created
         version conflicts (commons logging and junit).  These have been explicitly
         excluded in the POM.
       </action>
-      <action dev="psteitz" issue="DBCP-348" due-to="Eiji Takahashi>
+      <action dev="psteitz" issue="DBCP-348" type="fix" due-to="Eiji Takahashi">
         BasicDataSourceFactory incorrectly used "initConnectSqls" in versions
         1.3 and 1.4 of DBCP as the property name for connectionInitSqls.
         Online docs for 1.3/1/4 have been updated to reflect this inconsistency.

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
Sun Jan  9 02:26:55 2011
@@ -261,6 +261,39 @@ public class BasicDataSource implements 
     }
     
     /**
+     * True means that borrowObject returns the most recently used ("last in")
+     * connection in the pool (if there are idle connections available).  False
+     * means that the pool behaves as a FIFO queue - connections are taken from
+     * the idle instance pool in the order that they are returned to the pool.
+     */
+    private boolean lifo = GenericObjectPool.DEFAULT_LIFO;
+
+    /**
+     * Returns the LIFO property. 
+     * 
+     * @return true if connection pool behaves as a LIFO queue.
+     * 
+     * @see #lifo 
+     */ 
+    public synchronized boolean getLifo() {
+        return this.lifo;
+    }
+
+    /**
+     * Sets the LIFO property. True means the pool behaves as a LIFO queue;
+     * false means FIFO.
+     *  
+     * @param lifo the new value for the LIFO property
+     *  
+     */    
+    public synchronized void setLifo(boolean lifo) {
+        this.lifo = lifo;	
+        if (connectionPool != null) {
+            connectionPool.setLifo(lifo);
+        }
+    }
+    
+    /**
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or negative for no limit.
      */
@@ -1510,6 +1543,7 @@ public class BasicDataSource implements 
         gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
         gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         gop.setTestWhileIdle(testWhileIdle);
+        gop.setLifo(lifo);
         connectionPool = gop;
     }
 

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
Sun Jan  9 02:26:55 2011
@@ -50,6 +50,7 @@ public class BasicDataSourceFactory impl
     private final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
     private final static String PROP_DEFAULTCATALOG = "defaultCatalog";
     private final static String PROP_DRIVERCLASSNAME = "driverClassName";
+    private final static String PROP_LIFO = "lifo";
     private final static String PROP_MAXACTIVE = "maxActive";
     private final static String PROP_MAXIDLE = "maxIdle";
     private final static String PROP_MINIDLE = "minIdle";
@@ -86,6 +87,7 @@ public class BasicDataSourceFactory impl
         PROP_DEFAULTTRANSACTIONISOLATION,
         PROP_DEFAULTCATALOG,
         PROP_DRIVERCLASSNAME,
+        PROP_LIFO,
         PROP_MAXACTIVE,
         PROP_MAXIDLE,
         PROP_MINIDLE,
@@ -218,6 +220,11 @@ public class BasicDataSourceFactory impl
             dataSource.setDriverClassName(value);
         }
 
+        value = properties.getProperty(PROP_LIFO);
+        if (value != null) {
+            dataSource.setLifo(Boolean.valueOf(value).booleanValue());
+        }
+        
         value = properties.getProperty(PROP_MAXACTIVE);
         if (value != null) {
             dataSource.setMaxActive(Integer.parseInt(value));

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/site/xdoc/configuration.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/site/xdoc/configuration.xml?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/site/xdoc/configuration.xml (original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/site/xdoc/configuration.xml Sun Jan
 9 02:26:55 2011
@@ -257,6 +257,16 @@ one row.
   only once - when the configured connection factory creates the connection.
      </td>
   </tr>
+  <tr>
+    <td>lifo</td>
+    <td>true</td>
+    <td>
+       True means that borrowObject returns the most recently used ("last in")
+       connection in the pool (if there are idle connections available).  False
+       means that the pool behaves as a FIFO queue - connections are taken from
+       the idle instance pool in the order that they are returned to the pool.
+    </td>
+  </tr>
 </table>
 
 <table>

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
Sun Jan  9 02:26:55 2011
@@ -79,6 +79,7 @@ public class TestBasicDataSourceFactory 
         properties.setProperty("logAbandoned", "true");
         properties.setProperty("poolPreparedStatements", "true");
         properties.setProperty("maxOpenPreparedStatements", "10");
+        properties.setProperty("lifo", "true");
 
         BasicDataSource ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(properties);
         
@@ -113,5 +114,6 @@ public class TestBasicDataSourceFactory 
         assertEquals(true, ds.getLogAbandoned());
         assertEquals(true, ds.isPoolPreparedStatements());
         assertEquals(10, ds.getMaxOpenPreparedStatements());
+        assertEquals(true, ds.getLifo());
     }
 }

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Sun Jan  9 02:26:55 2011
@@ -38,13 +38,20 @@ The <action> type attribute can be add,u
     <title>Commons DBCP Release Notes</title>
   </properties>
   <body>
+    <release version="2.0" date="TBD" description="TBD">
+    </release>
     <release version="1.4.1" date="TBD" description="TBD">
-      <action dev="psteitz" issue="DBCP-344" due-to="Jeremy Whiting">
+      <action dev="psteitz" issue="DBCP-346" type="update" due-to="Ken Tatsushita">
+        LIFO configuration option has been added to BasicDataSource.  When set
+        to true (the default), the pool acts as a LIFO queue; setting to false
+        causes connections to enter and exit to pool in FIFO order.
+      </action>
+      <action dev="psteitz" issue="DBCP-344" type="fix" due-to="Jeremy Whiting">
         Test transitive dependencies brought in by geronimo-transaction created
         version conflicts (commons logging and junit).  These have been explicitly
         excluded in the POM.
       </action>
-      <action dev="psteitz" issue="DBCP-348" due-to="Eiji Takahashi>
+      <action dev="psteitz" issue="DBCP-348" type="fix" due-to="Eiji Takahashi">
         BasicDataSourceFactory incorrectly used "initConnectSqls" in versions
         1.3 and 1.4 of DBCP as the property name for connectionInitSqls.
         Online docs for 1.3/1/4 have been updated to reflect this inconsistency.

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java Sun Jan
 9 02:26:55 2011
@@ -261,6 +261,39 @@ public class BasicDataSource implements 
     }
     
     /**
+     * True means that borrowObject returns the most recently used ("last in")
+     * connection in the pool (if there are idle connections available).  False
+     * means that the pool behaves as a FIFO queue - connections are taken from
+     * the idle instance pool in the order that they are returned to the pool.
+     */
+    private boolean lifo = GenericObjectPool.DEFAULT_LIFO;
+
+    /**
+     * Returns the LIFO property. 
+     * 
+     * @return true if connection pool behaves as a LIFO queue.
+     * 
+     * @see #lifo 
+     */ 
+    public synchronized boolean getLifo() {
+        return this.lifo;
+    }
+
+    /**
+     * Sets the LIFO property. True means the pool behaves as a LIFO queue;
+     * false means FIFO.
+     *  
+     * @param lifo the new value for the LIFO property
+     *  
+     */    
+    public synchronized void setLifo(boolean lifo) {
+        this.lifo = lifo;   
+        if (connectionPool != null) {
+            connectionPool.setLifo(lifo);
+        }
+    }
+    
+    /**
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or negative for no limit.
      */
@@ -1510,6 +1543,7 @@ public class BasicDataSource implements 
         gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
         gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         gop.setTestWhileIdle(testWhileIdle);
+        gop.setLifo(lifo);
         connectionPool = gop;
     }
 

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
Sun Jan  9 02:26:55 2011
@@ -50,6 +50,7 @@ public class BasicDataSourceFactory impl
     private final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
     private final static String PROP_DEFAULTCATALOG = "defaultCatalog";
     private final static String PROP_DRIVERCLASSNAME = "driverClassName";
+    private final static String PROP_LIFO = "lifo";
     private final static String PROP_MAXACTIVE = "maxActive";
     private final static String PROP_MAXIDLE = "maxIdle";
     private final static String PROP_MINIDLE = "minIdle";
@@ -86,6 +87,7 @@ public class BasicDataSourceFactory impl
         PROP_DEFAULTTRANSACTIONISOLATION,
         PROP_DEFAULTCATALOG,
         PROP_DRIVERCLASSNAME,
+        PROP_LIFO,
         PROP_MAXACTIVE,
         PROP_MAXIDLE,
         PROP_MINIDLE,
@@ -218,6 +220,11 @@ public class BasicDataSourceFactory impl
             dataSource.setDriverClassName(value);
         }
 
+        value = properties.getProperty(PROP_LIFO);
+        if (value != null) {
+            dataSource.setLifo(Boolean.valueOf(value).booleanValue());
+        }
+        
         value = properties.getProperty(PROP_MAXACTIVE);
         if (value != null) {
             dataSource.setMaxActive(Integer.parseInt(value));

Modified: commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml (original)
+++ commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml Sun Jan  9 02:26:55 2011
@@ -250,6 +250,16 @@ one row.
   only once - when the configured connection factory creates the connection.
      </td>
   </tr>
+  <tr>
+    <td>lifo</td>
+    <td>true</td>
+    <td>
+       True means that borrowObject returns the most recently used ("last in")
+       connection in the pool (if there are idle connections available).  False
+       means that the pool behaves as a FIFO queue - connections are taken from
+       the idle instance pool in the order that they are returned to the pool.
+    </td>
+  </tr>
 </table>
 
 <table>

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java?rev=1056867&r1=1056866&r2=1056867&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
Sun Jan  9 02:26:55 2011
@@ -79,6 +79,7 @@ public class TestBasicDataSourceFactory 
         properties.setProperty("logAbandoned", "true");
         properties.setProperty("poolPreparedStatements", "true");
         properties.setProperty("maxOpenPreparedStatements", "10");
+        properties.setProperty("lifo", "true");
 
         BasicDataSource ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(properties);
         
@@ -113,5 +114,6 @@ public class TestBasicDataSourceFactory 
         assertEquals(true, ds.getLogAbandoned());
         assertEquals(true, ds.isPoolPreparedStatements());
         assertEquals(10, ds.getMaxOpenPreparedStatements());
+        assertEquals(true, ds.getLifo());
     }
 }



Mime
View raw message