commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1130015 - /commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
Date Wed, 01 Jun 2011 06:35:29 GMT
Author: psteitz
Date: Wed Jun  1 06:35:29 2011
New Revision: 1130015

URL: http://svn.apache.org/viewvc?rev=1130015&view=rev
Log:
Added support for dbcp2 and tomcat-jdbc-pool.

Modified:
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java?rev=1130015&r1=1130014&r2=1130015&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
Wed Jun  1 06:35:29 2011
@@ -27,7 +27,6 @@ import java.util.logging.Logger;
 import javax.sql.DataSource;
 import org.apache.commons.dbcp.AbandonedConfig;
 import org.apache.commons.dbcp.AbandonedObjectPool;
-import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.commons.dbcp.ConnectionFactory;
 import org.apache.commons.dbcp.DriverConnectionFactory;
 import org.apache.commons.dbcp.DriverManagerConnectionFactory;
@@ -44,6 +43,7 @@ import org.apache.commons.performance.Co
 import org.apache.commons.performance.ClientThread;
 import org.apache.commons.performance.LoadGenerator;
 import org.apache.commons.performance.Statistics;
+import org.apache.tomcat.jdbc.pool.PoolProperties;
  
 /**
  * Configurable load / performance tester for commons dbcp.
@@ -85,7 +85,7 @@ public class DBCPSoak extends LoadGenera
     private String dataSourceType;
     
     // Instance variables
-    private GenericObjectPool connectionPool;
+    private GenericObjectPool connectionPool; 
     private DataSource dataSource;
     
     /**
@@ -94,7 +94,7 @@ public class DBCPSoak extends LoadGenera
     protected void init() throws Exception {
         
         if (dataSourceType.equals("BasicDataSource")) {
-            BasicDataSource bds = new BasicDataSource();
+            org.apache.commons.dbcp.BasicDataSource bds = new org.apache.commons.dbcp.BasicDataSource();
             bds.setDefaultAutoCommit(autocommit);
             bds.setPassword(connectPassword);
             bds.setUrl(connectUrl);
@@ -120,18 +120,69 @@ public class DBCPSoak extends LoadGenera
             checkDatabase();
             return;
         }
+        
+        if (dataSourceType.equals("BasicDataSource2")) {
+            org.apache.commons.dbcp2.BasicDataSource bds = new org.apache.commons.dbcp2.BasicDataSource();
+            bds.setDefaultAutoCommit(autocommit);
+            bds.setPassword(connectPassword);
+            bds.setUrl(connectUrl);
+            bds.setUsername(connectUser);
+            bds.setDriverClassName(driverClass);
+            bds.setMinEvictableIdleTimeMillis(idleTimeout);
+            bds.setMaxActive(maxActive);
+            bds.setMaxIdle(maxIdle);
+            bds.setMaxWait(maxWait);
+            bds.setMinIdle(minIdle);
+            bds.setPoolPreparedStatements(poolPreparedStatements);
+            bds.setDefaultReadOnly(readOnly);
+            bds.setTestOnBorrow(testOnBorrow);
+            bds.setTestOnReturn(testOnReturn);
+            bds.setTestWhileIdle(testWhileIdle);
+            bds.setNumTestsPerEvictionRun(testsPerEviction);
+            bds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
+            bds.setValidationQuery(validationQuery);
+            if (poolType.equals("AbandonedObjectPool")) {
+                    bds.setRemoveAbandoned(true);
+            }
+            dataSource = bds; 
+            checkDatabase();
+            return;
+        }
+        
+        if (dataSourceType.equals("tomcat-jdbc-pool")) {
+            PoolProperties config = new PoolProperties();
+            config.setDefaultAutoCommit(autocommit);
+            config.setPassword(connectPassword);
+            config.setUrl(connectUrl);
+            config.setUsername(connectUser);
+            config.setDriverClassName(driverClass);
+            config.setMinEvictableIdleTimeMillis((int) idleTimeout);
+            config.setMaxActive(maxActive);
+            config.setMaxIdle(maxIdle);
+            config.setMaxWait((int) maxWait);
+            config.setMinIdle(minIdle);
+            config.setDefaultReadOnly(readOnly);
+            config.setTestOnBorrow(testOnBorrow);
+            config.setTestOnReturn(testOnReturn);
+            config.setTestWhileIdle(testWhileIdle);
+            config.setNumTestsPerEvictionRun(testsPerEviction);
+            config.setTimeBetweenEvictionRunsMillis((int) timeBetweenEvictions);
+            dataSource = new org.apache.tomcat.jdbc.pool.DataSource(config);
+            checkDatabase();
+            return;
+        }
 
         Class.forName(driverClass);
         
         // Create object pool
         if (poolType.equals("GenericObjectPool")) {
-            connectionPool = new GenericObjectPool(
+            connectionPool = new org.apache.commons.pool.impl.GenericObjectPool(
                     null, maxActive, exhaustedAction,
                     maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
                     timeBetweenEvictions, testsPerEviction, idleTimeout,
                     testWhileIdle);
         } else if (poolType.equals("AbandonedObjectPool")) {
-            connectionPool = new AbandonedObjectPool(null,abandonedConfig);
+            connectionPool = new org.apache.commons.dbcp.AbandonedObjectPool(null,abandonedConfig);
         } else {
             throw new ConfigurationException(
                     "invalid pool type configuration: " + poolType);
@@ -210,9 +261,11 @@ public class DBCPSoak extends LoadGenera
      */
     protected void cleanUp() throws Exception {
         if (dataSourceType.equals("BasicDataSource")) {
-            ((BasicDataSource) dataSource).close();
+            ((org.apache.commons.dbcp.BasicDataSource) dataSource).close();
+        } else if (dataSourceType.equals("tomcat-jdbc-pool")) {
+            ((org.apache.tomcat.jdbc.pool.DataSource) dataSource).close();
         } else {
-            connectionPool.close();
+            ((org.apache.commons.dbcp2.BasicDataSource) dataSource).close();
         }
     }
     
@@ -416,8 +469,4 @@ public class DBCPSoak extends LoadGenera
         
         this.configFile = "config-dbcp.xml";
     }
-
-    public GenericObjectPool getConnectionPool() {
-        return connectionPool;
-    }
 }



Mime
View raw message