Package org.pjdbc.drivers
Class TimeoutDriver
java.lang.Object
org.pjdbc.sql.AbstractDriver
org.pjdbc.sql.AbstractProxyDriver
org.pjdbc.drivers.TimeoutDriver
- All Implemented Interfaces:
Driver
@DriverCapability(prefix="timeout",
description="Enforces query timeout limits on all statements",
capabilities="resilience")
@DriverParameter(name="queryTimeout",type=INTEGER,description="Query timeout in seconds (0 = no timeout)",defaultValue="30",min=0L) @DriverParameter(name="cancelOnTimeout",type=BOOLEAN,description="Whether to attempt cancellation on timeout",defaultValue="true")
public class TimeoutDriver
extends AbstractProxyDriver
TimeoutDriver enforces query timeout limits on all statements.
This driver wraps statements and applies a configurable query timeout
using JDBC's Statement.setQueryTimeout() method. When a query exceeds
the timeout, the database driver throws a SQLException.
URL format: jdbc:timeout[param=value,...]:jdbc:target:...
Example URLs:
jdbc:timeout:jdbc:postgresql://localhost/mydb jdbc:timeout[queryTimeout=60]:jdbc:postgresql://localhost/mydb jdbc:timeout[queryTimeout=10,cancelOnTimeout=false]:jdbc:mysql://localhost/db
Notes:
- Timeout of 0 means no timeout (unlimited)
- The actual timeout behavior depends on the underlying JDBC driver
- Some databases may not support query cancellation
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration holder for timeout parameters. -
Driver Parameters
URL format:
jdbc:timeout[param=value,...]:<target-url>Parameter Type Default Constraints Description queryTimeoutinteger 30≥ 0 Query timeout in seconds (0 = no timeout) cancelOnTimeoutboolean true- Whether to attempt cancellation on timeout Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubName(String subname) protected booleanacceptsSubProtocol(String subprotocol) connect(String url, Properties info) static TimeoutDriver.TimeoutConfiggetTimeoutConfig(Connection conn) Get the timeout configuration for a connection.protected CallableStatementproxyCallableStatement(CallableStatement delegate, Connection conn) protected ConnectionproxyConnection(Connection delegate, String url, Properties info, Driver driver) protected PreparedStatementproxyPreparedStatement(PreparedStatement delegate, Connection conn) protected StatementproxyStatement(Statement delegate, Connection conn) Methods inherited from class org.pjdbc.sql.AbstractProxyDriver
getPropertyInfo, isCompositionValidationEnabled, isValidateParametersEnabled, proxyCallableStatement, proxyConnection, proxyConnection, proxyPreparedStatement, proxyResultSetMethods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Constructor Details
-
TimeoutDriver
public TimeoutDriver()
-
-
Method Details
-
acceptsSubProtocol
- Specified by:
acceptsSubProtocolin classAbstractDriver
-
acceptsSubName
- Overrides:
acceptsSubNamein classAbstractProxyDriver
-
connect
- Specified by:
connectin interfaceDriver- Overrides:
connectin classAbstractProxyDriver- Throws:
SQLException
-
proxyConnection
protected Connection proxyConnection(Connection delegate, String url, Properties info, Driver driver) throws SQLException - Overrides:
proxyConnectionin classAbstractProxyDriver- Throws:
SQLException
-
proxyStatement
- Overrides:
proxyStatementin classAbstractProxyDriver- Throws:
SQLException
-
proxyPreparedStatement
protected PreparedStatement proxyPreparedStatement(PreparedStatement delegate, Connection conn) throws SQLException - Overrides:
proxyPreparedStatementin classAbstractProxyDriver- Throws:
SQLException
-
proxyCallableStatement
protected CallableStatement proxyCallableStatement(CallableStatement delegate, Connection conn) throws SQLException - Overrides:
proxyCallableStatementin classAbstractProxyDriver- Throws:
SQLException
-
getTimeoutConfig
Get the timeout configuration for a connection. Returns null if connection is not a TimeoutDriver connection.
-