This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 6849c8825056ab9873ba05ea116ff0732f290b53 Author: opencode <[email protected]> AuthorDate: Mon Nov 2 16:23:54 2026 +0100 Scope the query report threshold's documentation to successful executions The threshold field and its getter said that an execution over the threshold is reported as slow and one under it as measured, but failed executions are handed to reportFailedQuery() whatever their duration and whatever the threshold - the setter alone had the wording right. Both now speak of successful executions and point at the failure channel for the rest. createStatement() described itself as creating a statement interceptor, which it does not: it wraps the new statement in a proxy whose executions the hooks report; the wording now says so. Comments that only restated the line below them were dropped, the wrong "If we are calling anything else, bail out" note on the closed-handle refusal was replaced with what the code actually does, the redundant process accumulator became a single assignment, and a stray double blank line went away. --- .../jdbc/pool/interceptor/AbstractQueryReport.java | 39 +++++++++------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java index 740d2d1363..f9d56c7a4e 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java @@ -38,11 +38,12 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce private static final Log log = LogFactory.getLog(AbstractQueryReport.class); /** - * The threshold in milliseconds. An execution that takes longer than - * this is reported as a slow query; one that takes no longer is - * reported as a measured query. A negative threshold keeps every - * execution out of the slow path, so every execution is reported as - * measured. + * The threshold in milliseconds. A successful execution that takes + * longer than this is reported as a slow query; one that takes no + * longer is reported as a measured query. A negative threshold keeps + * every execution out of the slow path, so every successful execution + * is reported as measured. Failed executions are reported through + * {@link #reportFailedQuery} regardless of this threshold. */ protected long threshold = 1000; // Executions slower than this are slow @@ -81,12 +82,10 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce * @return the SQL, {@code "batch"} or {@code null} */ private String extractQuery(String query, Object[] args, final String name) { - // Extract the query string String sql = query; if (sql == null && args != null && args.length > 0 && args[0] instanceof String) { sql = (String) args[0]; } - // If we do batch execution, then we name the query 'batch' if (sql == null && (compare(EXECUTE_BATCH, name) || compare(EXECUTE_LARGE_BATCH, name))) { sql = "batch"; } @@ -153,9 +152,10 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce /** * returns the query measure threshold. This value is in milliseconds. - * An execution that takes longer than this threshold is reported as a - * slow query; see {@link #setThreshold(long)} for the meaning of a - * negative value. + * A successful execution that takes longer than this threshold is + * reported as a slow query; see {@link #setThreshold(long)} for the + * meaning of a negative value and for the handling of failed + * executions. * * @return the threshold in milliseconds */ @@ -180,7 +180,8 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce } /** - * Creates a statement interceptor to monitor query response times + * Wraps a newly created statement in a proxy that measures its executions, so they can be reported as measured, + * slow or failed queries. */ @Override public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) { @@ -190,17 +191,14 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce String sql = null; Constructor<?> constructor = null; if (compare(CREATE_STATEMENT, name)) { - // createStatement constructor = getConstructor(CREATE_STATEMENT_IDX, Statement.class); } else if (compare(PREPARE_STATEMENT, name)) { - // prepareStatement sql = (String) args[0]; constructor = getConstructor(PREPARE_STATEMENT_IDX, PreparedStatement.class); if (sql != null) { prepareStatement(sql, time); } } else if (compare(PREPARE_CALL, name)) { - // prepareCall sql = (String) args[0]; constructor = getConstructor(PREPARE_CALL_IDX, CallableStatement.class); if (sql != null) { @@ -219,7 +217,6 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce return statement; } - /** * Measures the milliseconds elapsed since the {@link System#nanoTime()} * reading taken at {@code startNanos}, rounded to the nearest millisecond. @@ -273,7 +270,6 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - // Get the name of the method for comparison final String name = method.getName(); // Handle identity on this proxy, like the statement facade // does, rather than forwarding it to the delegate: the delegate @@ -291,7 +287,6 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce if (compare(HASHCODE_VAL, name)) { return Integer.valueOf(this.hashCode()); } - // Was close invoked? boolean close = compare(CLOSE_VAL, name); // Read the state once: another thread's close() - the pool's // statement finalizer closes tracked statements from whichever @@ -313,17 +308,15 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce if (close && gone) { return null; } - // Are we calling isClosed? if (compare(ISCLOSED_VAL, name)) { return Boolean.valueOf(gone); } - // If we are calling anything else, bail out + // Anything other than close() or isClosed() on a closed handle is + // refused, the way the closed contract promises if (gone) { throw new SQLException(MessageFactory.get("abstractQueryReport.statementClosed")); } - boolean process = false; - // Check to see if we are about to execute a query - process = isExecute(method, process); + boolean process = isExecute(method, false); // If we are executing, get the current time. The wall clock // only gives the timestamp the report hooks carry; the elapsed // time is measured with the monotonic clock on both the success @@ -372,7 +365,6 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce throw t; } } - // Measure the elapsed time with the monotonic clock long delta = (process) ? elapsedMillis(startNanos) : Long.MIN_VALUE; // See if we meet the requirements to measure. A negative // threshold keeps every execution out of the slow path: the @@ -386,7 +378,6 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce // threshold anyway. if (process && threshold >= 0 && delta > threshold) { try { - // Report the slow query reportSlowQuery(query, args, name, start, delta); } catch (Throwable t) { if (log.isWarnEnabled()) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
