Author: sebb
Date: Mon Oct  1 11:36:38 2007
New Revision: 581032

URL: http://svn.apache.org/viewvc?rev=581032&view=rev
Log:
Create getConnection() method in DataSourceElement; use it in JDBCSampler
This is to make future changes easier.

Modified:
    
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
    
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java

Modified: 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java?rev=581032&r1=581031&r2=581032&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
 Mon Oct  1 11:36:38 2007
@@ -17,7 +17,10 @@
 package org.apache.jmeter.protocol.jdbc.config;
 
 import java.io.ObjectStreamException;
+import java.sql.Connection;
+import java.sql.SQLException;
 
+import org.apache.avalon.excalibur.datasource.DataSourceComponent;
 import org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.logger.LogKitLogger;
@@ -27,6 +30,7 @@
 import org.apache.jmeter.testbeans.TestBeanHelper;
 import org.apache.jmeter.testelement.AbstractTestElement;
 import org.apache.jmeter.testelement.TestListener;
+import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
@@ -110,6 +114,20 @@
                getThreadContext().getVariables().putObject(getDataSource(), 
excaliburSource);
        }
 
+       /*
+        * Utility routine to get the connection from the pool.
+        * Purpose:
+        * - allows JDBCSampler to be entirely independent of the pooling 
classes
+        * - allows the pool storage mechanism to be changed if necessary
+        */
+       public static Connection getConnection(String poolName) throws 
SQLException{
+               DataSourceComponent pool = (DataSourceComponent) 
+                   
JMeterContextService.getContext().getVariables().getObject(poolName);
+               if (pool == null) {
+                       throw new SQLException("No pool found named: '" + 
poolName + "'");
+               }
+               return pool.getConnection();
+       }
        /*
         * (non-Javadoc)
         * 

Modified: 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java?rev=581032&r1=581031&r2=581032&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
 Mon Oct  1 11:36:38 2007
@@ -32,7 +32,7 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import org.apache.avalon.excalibur.datasource.DataSourceComponent;
+import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
 import org.apache.jmeter.samplers.AbstractSampler;
 import org.apache.jmeter.samplers.Entry;
 import org.apache.jmeter.samplers.SampleResult;
@@ -138,19 +138,13 @@
 
 
                res.sampleStart();
-               DataSourceComponent pool = (DataSourceComponent) 
getThreadContext().getVariables().getObject(getDataSource());
-               log.debug("DataSourceComponent: " + pool);
                Connection conn = null;
                Statement stmt = null;
 
                try {
 
-                       if (pool == null)
-                               throw new SQLException("No pool created");
-
-                       // TODO: Consider creating a sub-result with the time 
to get the
-                       // connection.
-                       conn = pool.getConnection();
+                       // TODO: Consider creating a sub-result with the time 
to get the connection.
+                       conn = DataSourceElement.getConnection(getDataSource());
 
             // Based on query return value, get results
             String _queryType = getQueryType();



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to