You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2010/09/18 21:19:35 UTC
svn commit: r998526 -
/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
Author: psteitz
Date: Sat Sep 18 19:19:34 2010
New Revision: 998526
URL: http://svn.apache.org/viewvc?rev=998526&view=rev
Log:
Make datasource type configurable
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=998526&r1=998525&r2=998526&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 Sat Sep 18 19:19:34 2010
@@ -24,8 +24,10 @@ import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;
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;
@@ -79,14 +81,46 @@ public class DBCPSoak extends LoadGenera
private int minIdle;
private long maxWait;
+ // DataSource type
+ private String dataSourceType;
+
// Instance variables
private GenericObjectPool connectionPool;
- private PoolingDataSource dataSource;
+ private DataSource dataSource;
/**
* Create connection pool and, if necessary, test table.
*/
protected void init() throws Exception {
+
+ if (dataSourceType.equals("BasicDataSource")) {
+ BasicDataSource bds = new 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;
+ }
+
Class.forName(driverClass);
// Create object pool
@@ -147,7 +181,10 @@ public class DBCPSoak extends LoadGenera
// Create DataSource
dataSource = new PoolingDataSource(connectionPool);
-
+ checkDatabase();
+ }
+
+ protected void checkDatabase() throws Exception {
// Try to connect and query test_table. If "test_table" appears in
// exception message, assume table needs to be created.
Connection conn = dataSource.getConnection();
@@ -172,7 +209,11 @@ public class DBCPSoak extends LoadGenera
* Close connection pool
*/
protected void cleanUp() throws Exception {
- connectionPool.close();
+ if (dataSourceType.equals("BasicDataSource")) {
+ ((BasicDataSource) dataSource).close();
+ } else {
+ connectionPool.close();
+ }
}
protected ClientThread makeClientThread(
@@ -200,6 +241,10 @@ public class DBCPSoak extends LoadGenera
this.queryType = queryType;
}
+ public void configureDataSource(String type) {
+ this.dataSourceType = type;
+ }
+
public void configureConnectionFactory(String type,
String autoCommit, String readOnly, String validationQuery) {
this.driverType = type;
@@ -310,6 +355,9 @@ public class DBCPSoak extends LoadGenera
digester.addCallParam("configuration/database/password", 3);
digester.addCallParam("configuration/database/query-type", 4);
+ digester.addCallMethod("configuration", "configureDataSource", 1);
+ digester.addCallParam("configuration/datasource-type", 0);
+
digester.addCallMethod("configuration/connection-factory",
"configureConnectionFactory", 4);
digester.addCallParam(