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

(-)jmeter-jdbc-to-orig/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java (-1 / +51 lines)
Lines 112-117 Link Here
112
    private String queryArgumentsTypes = ""; // $NON-NLS-1$
112
    private String queryArgumentsTypes = ""; // $NON-NLS-1$
113
    private String variableNames = ""; // $NON-NLS-1$
113
    private String variableNames = ""; // $NON-NLS-1$
114
    private String resultVariable = "";
114
    private String resultVariable = "";
115
    private String queryTimeout = "";
115
116
116
    /**
117
    /**
117
     *  Cache of PreparedStatements stored in a per-connection basis. Each entry of this
118
     *  Cache of PreparedStatements stored in a per-connection basis. Each entry of this
Lines 142-147 Link Here
142
            String _queryType = getQueryType();
143
            String _queryType = getQueryType();
143
            if (SELECT.equals(_queryType)) {
144
            if (SELECT.equals(_queryType)) {
144
                stmt = conn.createStatement();
145
                stmt = conn.createStatement();
146
                setTimeoutForStatement(stmt, getIntegerQueryTimeout());
147
                
145
                ResultSet rs = null;
148
                ResultSet rs = null;
146
                try {
149
                try {
147
                    rs = stmt.executeQuery(getQuery());
150
                    rs = stmt.executeQuery(getQuery());
Lines 159-164 Link Here
159
                return sb.getBytes(ENCODING);
162
                return sb.getBytes(ENCODING);
160
            } else if (UPDATE.equals(_queryType)) {
163
            } else if (UPDATE.equals(_queryType)) {
161
                stmt = conn.createStatement();
164
                stmt = conn.createStatement();
165
                setTimeoutForStatement(stmt, getIntegerQueryTimeout());
162
                stmt.executeUpdate(getQuery());
166
                stmt.executeUpdate(getQuery());
163
                int updateCount = stmt.getUpdateCount();
167
                int updateCount = stmt.getUpdateCount();
164
                String results = updateCount + " updates";
168
                String results = updateCount + " updates";
Lines 332-341 Link Here
332
            } else {
336
            } else {
333
                pstmt = conn.prepareStatement(getQuery());
337
                pstmt = conn.prepareStatement(getQuery());
334
            }
338
            }
339
            setTimeoutForStatement(pstmt, getIntegerQueryTimeout());
340
            
335
            // PreparedStatementMap is associated to one connection so 
341
            // PreparedStatementMap is associated to one connection so 
336
            //  2 threads cannot use the same PreparedStatement map at the same time
342
            //  2 threads cannot use the same PreparedStatement map at the same time
337
            preparedStatementMap.put(getQuery(), pstmt);
343
            preparedStatementMap.put(getQuery(), pstmt);
344
        } else {
345
        	if(pstmt.getQueryTimeout() != getIntegerQueryTimeout()) {
346
        		setTimeoutForStatement(pstmt, getIntegerQueryTimeout());
347
        	}
338
        }
348
        }
349
        
339
        pstmt.clearParameters();
350
        pstmt.clearParameters();
340
        return pstmt;
351
        return pstmt;
341
    }
352
    }
Lines 556-562 Link Here
556
     */
567
     */
557
    public void setResultVariable(String resultVariable) {
568
    public void setResultVariable(String resultVariable) {
558
        this.resultVariable = resultVariable;
569
        this.resultVariable = resultVariable;
559
    }    
570
    }
571
    
572
    /**
573
     * @return the integer representation queryTimeout
574
     */
575
    public int getIntegerQueryTimeout() {
576
        int timeout = 0;
577
    	try {
578
        	timeout = Integer.parseInt(queryTimeout);
579
        } catch (NumberFormatException nfe) {
580
        	timeout = 0;
581
        }
582
    	return timeout;
583
    }
584
    /**
585
     * @return the queryTimeout
586
     */
587
    public String getQueryTimeout() {
588
        return queryTimeout ;
589
    }
590
591
    /**
592
     * @param resultVariable the variable name in which results will be stored
593
     */
594
    public void setQueryTimeout(String queryTimeout) {
595
        this.queryTimeout = queryTimeout;
596
    }  
560
597
561
598
562
    /** 
599
    /** 
Lines 604-608 Link Here
604
        }
641
        }
605
        perConnCache.clear();
642
        perConnCache.clear();
606
    }
643
    }
644
    
645
    /**
646
     * Set timeout for statement
647
     * @param stmt the statement to set timeout
648
     * @param timeout the timeout in seconds to set
649
     */
650
    private static void setTimeoutForStatement(Statement stmt, int timeout) {
651
    	try {
652
    		stmt.setQueryTimeout(timeout);
653
		} catch (SQLException e) {
654
			log.warn("Error setting timeout", e);
655
		}
656
    }
607
657
608
}
658
}
(-)jmeter-jdbc-to-orig/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java (+5 lines)
Lines 42-47 Link Here
42
                "queryArgumentsTypes", // $NON-NLS-1$
42
                "queryArgumentsTypes", // $NON-NLS-1$
43
                "variableNames", // $NON-NLS-1$
43
                "variableNames", // $NON-NLS-1$
44
                "resultVariable", // $NON-NLS-1$
44
                "resultVariable", // $NON-NLS-1$
45
                "queryTimeout",
45
                });
46
                });
46
47
47
        PropertyDescriptor p = property("dataSource"); // $NON-NLS-1$
48
        PropertyDescriptor p = property("dataSource"); // $NON-NLS-1$
Lines 63-68 Link Here
63
        p = property("resultVariable"); // $NON-NLS-1$
64
        p = property("resultVariable"); // $NON-NLS-1$
64
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
65
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
65
        p.setValue(DEFAULT, "");
66
        p.setValue(DEFAULT, "");
67
        
68
        p = property("queryTimeout"); // $NON-NLS-1$
69
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
70
        p.setValue(DEFAULT, "");
66
71
67
        p = property("queryType"); // $NON-NLS-1$
72
        p = property("queryType"); // $NON-NLS-1$
68
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
73
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
(-)jmeter-jdbc-to-orig/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources.properties (+2 lines)
Lines 30-33 Link Here
30
variableNames.shortDescription=Output variable names for each column  (comma separated)
30
variableNames.shortDescription=Output variable names for each column  (comma separated)
31
resultVariable.displayName=Result variable name
31
resultVariable.displayName=Result variable name
32
resultVariable.shortDescription=Name of the JMeter variable that stores the result set objects in a list of maps for looking up results by column name.
32
resultVariable.shortDescription=Name of the JMeter variable that stores the result set objects in a list of maps for looking up results by column name.
33
queryTimeout.displayName=Query timeout
34
resultVariable.shortDescription=The timeout of statement measured in seconds
33
35

Return to bug 55084