Package org.pjdbc.sql
Class AbstractProxyDriver
java.lang.Object
org.pjdbc.sql.AbstractDriver
org.pjdbc.sql.AbstractProxyDriver
- All Implemented Interfaces:
Driver
- Direct Known Subclasses:
CatDriver,ChaosDriver,CircuitBreakerDriver,DataMaskingDriver,FilterDriver,ReadonlyDriver,RetryDriver,SchemaValidationDriver,SinkDriver,TeeDriver,TimeoutDriver,UserMapDriver
Base class for PJDBC proxy drivers that wrap and delegate to other JDBC drivers.
This class provides the core infrastructure for creating proxy drivers that can intercept and modify JDBC operations. Subclasses override specific methods to implement custom behavior such as SQL transformation, connection routing, or operation logging.
Key extension points:
AbstractDriver.acceptsSubProtocol(String)- Define which URL prefix this driver handlesproxyConnection(Connection, String, Properties, Driver)- Customize connection wrappingproxyStatement(Statement, Connection)- Customize statement wrappingproxyPreparedStatement(PreparedStatement, Connection)- Customize prepared statement wrapping
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubName(String subname) connect(String url, Properties info) getPropertyInfo(String url, Properties info) protected booleanWhether to automatically validate driver composition on connect.protected booleanWhether to automatically validate parameters on connect.protected CallableStatementproxyCallableStatement(CallableStatement delegate, Connection conn) protected CallableStatementproxyCallableStatement(CallableStatement delegate, Connection conn, String sql) Proxy a CallableStatement with access to the original SQL.protected ConnectionproxyConnection(String url, Properties info, Connection[] delegates) protected ConnectionproxyConnection(Connection conn, String url, Properties info, Driver driver) protected ConnectionproxyConnection(Connection delegate, String url, Properties info, List<Connection> delegates) protected PreparedStatementproxyPreparedStatement(PreparedStatement delegate, Connection conn) protected PreparedStatementproxyPreparedStatement(PreparedStatement delegate, Connection conn, String sql) Proxy a PreparedStatement with access to the original SQL.proxyResultSet(Statement stmt, ResultSet delegate) protected StatementproxyStatement(Statement delegate, Connection conn) Methods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsSubProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Constructor Details
-
AbstractProxyDriver
public AbstractProxyDriver()
-
-
Method Details
-
acceptsSubName
- Specified by:
acceptsSubNamein classAbstractDriver
-
proxyConnection
protected Connection proxyConnection(Connection conn, String url, Properties info, Driver driver) throws SQLException - Throws:
SQLException
-
proxyConnection
protected Connection proxyConnection(Connection delegate, String url, Properties info, List<Connection> delegates) throws SQLException - Throws:
SQLException
-
proxyConnection
protected Connection proxyConnection(String url, Properties info, Connection[] delegates) throws SQLException - Throws:
SQLException
-
proxyStatement
- Throws:
SQLException
-
proxyCallableStatement
protected CallableStatement proxyCallableStatement(CallableStatement delegate, Connection conn) throws SQLException - Throws:
SQLException
-
proxyPreparedStatement
protected PreparedStatement proxyPreparedStatement(PreparedStatement delegate, Connection conn) throws SQLException - Throws:
SQLException
-
proxyPreparedStatement
protected PreparedStatement proxyPreparedStatement(PreparedStatement delegate, Connection conn, String sql) throws SQLException Proxy a PreparedStatement with access to the original SQL. Override this method when you need to recreate the statement (e.g., on connection failure). The default implementation ignores the SQL and delegates toproxyPreparedStatement(PreparedStatement, Connection).- Parameters:
delegate- the delegate PreparedStatementconn- the connectionsql- the SQL used to prepare the statement- Returns:
- the proxied PreparedStatement
- Throws:
SQLException- if an error occurs
-
proxyCallableStatement
protected CallableStatement proxyCallableStatement(CallableStatement delegate, Connection conn, String sql) throws SQLException Proxy a CallableStatement with access to the original SQL. Override this method when you need to recreate the statement (e.g., on connection failure). The default implementation ignores the SQL and delegates toproxyCallableStatement(CallableStatement, Connection).- Parameters:
delegate- the delegate CallableStatementconn- the connectionsql- the SQL used to prepare the statement- Returns:
- the proxied CallableStatement
- Throws:
SQLException- if an error occurs
-
proxyResultSet
- Throws:
SQLException
-
isValidateParametersEnabled
protected boolean isValidateParametersEnabled()Whether to automatically validate parameters on connect. Subclasses can override to enable/disable validation.- Returns:
- true to validate parameters, false to skip validation
-
isCompositionValidationEnabled
protected boolean isCompositionValidationEnabled()Whether to automatically validate driver composition on connect. Subclasses can override to enable/disable validation. Can also be disabled via system property: -Dpjdbc.validation.composition=false- Returns:
- true to validate composition, false to skip validation
-
connect
- Throws:
SQLException
-
getPropertyInfo
- Specified by:
getPropertyInfoin interfaceDriver- Overrides:
getPropertyInfoin classAbstractDriver- Throws:
SQLException
-