View | Details | Raw Unified | Return to bug 53995
Collapse All | Expand All

(-)src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/processor/AbstractJDBCProcessor.java (-1 / +1 lines)
Lines 31-37 Link Here
31
 * As pre- and post-processors essentially do the same this class provides the implmentation.
31
 * As pre- and post-processors essentially do the same this class provides the implmentation.
32
 */
32
 */
33
public abstract class AbstractJDBCProcessor extends AbstractJDBCTestElement {
33
public abstract class AbstractJDBCProcessor extends AbstractJDBCTestElement {
34
    
34
35
    private static final Logger log = LoggingManager.getLoggerForClass();
35
    private static final Logger log = LoggingManager.getLoggerForClass();
36
36
37
    private static final long serialVersionUID = 232L;
37
    private static final long serialVersionUID = 232L;
(-)src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java (-20 / +22 lines)
Lines 31-43 Link Here
31
import java.util.ArrayList;
31
import java.util.ArrayList;
32
import java.util.Arrays;
32
import java.util.Arrays;
33
import java.util.Collection;
33
import java.util.Collection;
34
import java.util.Collections;
35
import java.util.HashMap;
34
import java.util.HashMap;
36
import java.util.HashSet;
35
import java.util.HashSet;
37
import java.util.LinkedHashMap;
36
import java.util.LinkedHashMap;
38
import java.util.List;
37
import java.util.List;
39
import java.util.Map;
38
import java.util.Map;
40
import java.util.Set;
39
import java.util.Set;
40
import java.util.concurrent.ConcurrentHashMap;
41
41
42
import org.apache.jmeter.engine.event.LoopIterationEvent;
42
import org.apache.jmeter.engine.event.LoopIterationEvent;
43
import org.apache.jmeter.samplers.SampleResult;
43
import org.apache.jmeter.samplers.SampleResult;
Lines 128-147 Link Here
128
     *  cache is another Map mapping the statement string to the actual PreparedStatement.
128
     *  cache is another Map mapping the statement string to the actual PreparedStatement.
129
     *  The cache has a fixed size of MAX_ENTRIES and it will throw away all PreparedStatements
129
     *  The cache has a fixed size of MAX_ENTRIES and it will throw away all PreparedStatements
130
     *  from the least recently used connections.
130
     *  from the least recently used connections.
131
     *
132
     *  Fixed by Haixing Hu: The prepredStatement or callableStatement should
133
     *  NOT be shared between threads, therefore we use a cache per thread per
134
     *  connection.
131
     */
135
     */
132
    private static final Map<Connection, Map<String, PreparedStatement>> perConnCache =
136
    private static final Map<Thread, Map<Connection, Map<String, PreparedStatement>>> perConnCache =
133
        Collections.synchronizedMap(new LinkedHashMap<Connection, Map<String, PreparedStatement>>(MAX_ENTRIES){
137
        new ConcurrentHashMap<Thread, Map<Connection, Map<String, PreparedStatement>>>();
134
        private static final long serialVersionUID = 1L;
135
        @Override
136
        protected boolean removeEldestEntry(Map.Entry<Connection, Map<String, PreparedStatement>> arg0) {
137
            if (size() > MAX_ENTRIES) {
138
                final  Map<String, PreparedStatement> value = arg0.getValue();
139
                closeAllStatements(value.values());
140
                return true;
141
            }
142
            return false;
143
        }
144
    });
145
138
146
    /**
139
    /**
147
     * Creates a JDBCSampler.
140
     * Creates a JDBCSampler.
Lines 340-349 Link Here
340
    }
333
    }
341
334
342
    private PreparedStatement getPreparedStatement(Connection conn, boolean callable) throws SQLException {
335
    private PreparedStatement getPreparedStatement(Connection conn, boolean callable) throws SQLException {
343
        Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
336
        Thread thread = Thread.currentThread();
337
        Map<Connection, Map<String, PreparedStatement>> cache = perConnCache.get(thread);
338
        if (cache == null) {
339
          cache = new HashMap<Connection, Map<String, PreparedStatement>>();
340
          perConnCache.put(thread, cache);
341
        }
342
        Map<String, PreparedStatement> preparedStatementMap = cache.get(conn);
344
        if (null == preparedStatementMap ) {
343
        if (null == preparedStatementMap ) {
345
            // MRU PreparedStatements cache.
344
            // MRU PreparedStatements cache.
346
            preparedStatementMap = Collections.synchronizedMap(new LinkedHashMap<String, PreparedStatement>(MAX_ENTRIES) {
345
            preparedStatementMap = new LinkedHashMap<String, PreparedStatement>(MAX_ENTRIES) {
347
                private static final long serialVersionUID = 240L;
346
                private static final long serialVersionUID = 240L;
348
347
349
                @Override
348
                @Override
Lines 359-366 Link Here
359
                    }
358
                    }
360
                    return false;
359
                    return false;
361
                }
360
                }
362
            });
361
            };
363
            perConnCache.put(conn, preparedStatementMap);
362
            cache.put(conn, preparedStatementMap);
364
        }
363
        }
365
        PreparedStatement pstmt = preparedStatementMap.get(getQuery());
364
        PreparedStatement pstmt = preparedStatementMap.get(getQuery());
366
        if (null == pstmt) {
365
        if (null == pstmt) {
Lines 649-657 Link Here
649
	 * Clean cache of PreparedStatements
648
	 * Clean cache of PreparedStatements
650
	 */
649
	 */
651
	private static final void cleanCache() {
650
	private static final void cleanCache() {
652
		for (Map.Entry<Connection, Map<String, PreparedStatement>> element : perConnCache.entrySet()) {
651
	    for (Map<Connection, Map<String, PreparedStatement>> cache : perConnCache.values()) {
653
			closeAllStatements(element.getValue().values());
652
		for (Map<String, PreparedStatement> element : cache.values()) {
653
		    closeAllStatements(element.values());
654
		}
654
		}
655
		cache.clear();
656
	    }
655
		perConnCache.clear();
657
		perConnCache.clear();
656
	}
658
	}
657
659
(-)src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java (+2 lines)
Lines 84-95 Link Here
84
            res.setResponseHeaders(conn.toString());
84
            res.setResponseHeaders(conn.toString());
85
            res.setResponseData(execute(conn));
85
            res.setResponseData(execute(conn));
86
        } catch (SQLException ex) {
86
        } catch (SQLException ex) {
87
            log.error("SQL Problem in  "+ getName() + ": " + ex.toString());
87
            final String errCode = Integer.toString(ex.getErrorCode());
88
            final String errCode = Integer.toString(ex.getErrorCode());
88
            res.setResponseMessage(ex.toString());
89
            res.setResponseMessage(ex.toString());
89
            res.setResponseCode(ex.getSQLState()+ " " +errCode);
90
            res.setResponseCode(ex.getSQLState()+ " " +errCode);
90
            res.setResponseData(ex.getMessage().getBytes());
91
            res.setResponseData(ex.getMessage().getBytes());
91
            res.setSuccessful(false);
92
            res.setSuccessful(false);
92
        } catch (Exception ex) {
93
        } catch (Exception ex) {
94
            log.error("Unknown Problem in  "+ getName() + ": " + ex.toString());
93
            res.setResponseMessage(ex.toString());
95
            res.setResponseMessage(ex.toString());
94
            res.setResponseCode("000");
96
            res.setResponseCode("000");
95
            res.setResponseData(ex.getMessage().getBytes());
97
            res.setResponseData(ex.getMessage().getBytes());
(-)build.properties (-1 / +1 lines)
Lines 165-171 Link Here
165
165
166
jcharts.version             = 0.7.5
166
jcharts.version             = 0.7.5
167
jcharts.jar                 = jcharts-${jcharts.version}.jar
167
jcharts.jar                 = jcharts-${jcharts.version}.jar
168
jcharts.loc                 = http://www.mvnsearch.org/maven2/jcharts/jcharts/${jcharts.version}
168
jcharts.loc                 = ${maven2.repo}/jcharts/jcharts/${jcharts.version}
169
jcharts.md5                 = 13927D8077C991E7EBCD8CB284746A7A
169
jcharts.md5                 = 13927D8077C991E7EBCD8CB284746A7A
170
170
171
jdom.version                = 1.1.2
171
jdom.version                = 1.1.2

Return to bug 53995