jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1797689 - /jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
Date Mon, 05 Jun 2017 19:39:45 GMT
Author: fschumacher
Date: Mon Jun  5 19:39:45 2017
New Revision: 1797689

URL: http://svn.apache.org/viewvc?rev=1797689&view=rev
Log:
Extract code into private method to reuse it and fix possible null pointer exception.

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

Modified: jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java?rev=1797689&r1=1797688&r2=1797689&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
(original)
+++ jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
Mon Jun  5 19:39:45 2017
@@ -301,18 +301,12 @@ public class DataSourceElement extends A
         DataSourceComponentImpl(BasicDataSource p_dsc){
             sharedDSC=p_dsc;
         }
-        
+
         /**
          * @return String connection information
          */
         public String getConnectionInfo() {
-            BasicDataSource dsc;
-            if (sharedDSC != null){ // i.e. shared pool
-                dsc = sharedDSC;
-            } else {
-                Map<String, BasicDataSource> poolMap = perThreadPoolMap.get();
-                dsc = poolMap.get(getDataSourceName());
-            }
+            BasicDataSource dsc = getConfiguredDatatSource();
             StringBuilder builder = new StringBuilder(100);
             builder.append("shared:").append(sharedDSC != null)
                 .append(", driver:").append(dsc.getDriverClassName())
@@ -326,22 +320,8 @@ public class DataSourceElement extends A
          * @throws SQLException if database access error occurred
          */
         public Connection getConnection() throws SQLException {
-            Connection conn;
-            BasicDataSource dsc;
-            if (sharedDSC != null){ // i.e. shared pool
-                dsc = sharedDSC;
-            } else {
-                Map<String, BasicDataSource> poolMap = perThreadPoolMap.get();
-                dsc = poolMap.get(getDataSourceName());
-                if (dsc == null){
-                    dsc = initPool("1");
-                    poolMap.put(getDataSourceName(),dsc);
-                    log.debug("Storing pool: {}@{}", getName(), System.identityHashCode(dsc));
-                    perThreadPoolSet.add(dsc);
-                }
-            }
-
-            conn=dsc.getConnection();
+            BasicDataSource dsc = getConfiguredDatatSource();
+            Connection conn=dsc.getConnection();
             int isolation = DataSourceElementBeanInfo.getTransactionIsolationMode(getTransactionIsolation());
             if (isolation >= 0 && conn.getTransactionIsolation() != isolation)
{
                 try {
@@ -357,6 +337,23 @@ public class DataSourceElement extends A
 
             return conn;
         }
+
+        private BasicDataSource getConfiguredDatatSource() {
+            BasicDataSource dsc;
+            if (sharedDSC != null){ // i.e. shared pool
+                dsc = sharedDSC;
+            } else {
+                Map<String, BasicDataSource> poolMap = perThreadPoolMap.get();
+                dsc = poolMap.get(getDataSourceName());
+                if (dsc == null){
+                    dsc = initPool("1");
+                    poolMap.put(getDataSourceName(),dsc);
+                    log.debug("Storing pool: {}@{}", getName(), System.identityHashCode(dsc));
+                    perThreadPoolSet.add(dsc);
+                }
+            }
+            return dsc;
+        }
     }
 
     @Override



Mime
View raw message