Package org.pjdbc.drivers
Class FilterDriver
java.lang.Object
org.pjdbc.sql.AbstractDriver
org.pjdbc.sql.AbstractProxyDriver
org.pjdbc.drivers.FilterDriver
- All Implemented Interfaces:
Driver
@DriverCapability(prefix="filter",
description="Transforms SQL statements using built-in or custom transformers",
capabilities={"transformation","filtering"})
@DriverParameter(name="class",type=STRING,description="Fully qualified class name of custom JdbcTransformer implementation") @DriverParameter(name="schema",type=STRING,description="Schema prefix to add to unqualified table names") @DriverParameter(name="where",type=STRING,description="Condition to append to WHERE clauses (e.g., deleted=false)") @DriverParameter(name="rename.*",type=STRING,description="Rename identifiers: rename.OLD_NAME=NEW_NAME")
public class FilterDriver
extends AbstractProxyDriver
FilterDriver transforms SQL statements using configurable transformers.
Built-in Transformers
URL-configurable transformers for common use cases:
Schema Prefix
Add schema prefix to unqualified table names:
jdbc:filter[schema=tenant_123]:jdbc:postgresql://localhost/db -- SELECT * FROM users → SELECT * FROM tenant_123.users
WHERE Clause
Append condition to all SELECT/UPDATE/DELETE statements:
jdbc:filter[where=deleted=false]:jdbc:mysql://localhost/db -- SELECT * FROM users → SELECT * FROM users WHERE deleted=false -- SELECT * FROM users WHERE active=true → SELECT * FROM users WHERE active=true AND deleted=false
Rename Identifiers
Rename table or column names (case-insensitive):
jdbc:filter[rename.old_table=new_table]:jdbc:h2:mem:test jdbc:filter[rename.users=customers,rename.created=created_at]:jdbc:...
Combining Transformers
Multiple transformers are applied in order:
jdbc:filter[schema=acme,where=active=true,rename.old=new]:jdbc:...
Custom Transformer Class
For complex transformations, specify a custom transformer class:
jdbc:filter[class=com.example.MyTransformer]:jdbc:postgresql://localhost/db
The transformer class must implement JdbcTransformer and have a
no-argument constructor.
Per-Connection Transformers
Each connection gets its own transformer instance. This ensures thread-safety and predictable behavior in connection-pooled environments.
- See Also:
-
Driver Parameters
URL format:
jdbc:filter[param=value,...]:<target-url>Parameter Type Default Constraints Description classstring - - Fully qualified class name of custom JdbcTransformer implementation schemastring - - Schema prefix to add to unqualified table names wherestring - - Condition to append to WHERE clauses (e.g., deleted=false) rename.*string - - Rename identifiers: rename.OLD_NAME=NEW_NAME Field Summary
FieldsModifier and TypeFieldDescriptionprotected ThreadLocal<JdbcTransformer> Deprecated.Use URL parameter class= instead. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubProtocol(String subprotocol) connect(String url, Properties info) Deprecated.Use URL parameter class= instead.protected ConnectionproxyConnection(Connection delegate, String url, Properties info, Driver driver) protected StatementproxyStatement(Statement delegate, Connection conn) voidsetTransformer(JdbcTransformer transformer) Deprecated.Use URL parameter class= instead: jdbc:filter[class=com.example.MyTransformer]:jdbc:...Methods inherited from class org.pjdbc.sql.AbstractProxyDriver
acceptsSubName, getPropertyInfo, isCompositionValidationEnabled, isValidateParametersEnabled, proxyCallableStatement, proxyCallableStatement, proxyConnection, proxyConnection, proxyPreparedStatement, proxyPreparedStatement, proxyResultSetMethods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Field Details
-
transformer
Deprecated.Use URL parameter class= instead. This field will be removed in a future version.ThreadLocal for backward compatibility with setTransformer() API.
-
-
Constructor Details
-
FilterDriver
public FilterDriver()
-
-
Method Details
-
acceptsSubProtocol
- Specified by:
acceptsSubProtocolin classAbstractDriver
-
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
-
getTransformer
Deprecated.Use URL parameter class= instead. Per-thread transformers are confusing in pooled connection scenarios.Get the current transformer for this thread.- Returns:
- the JdbcTransformer used for SQL transformation, or null if not set
-
setTransformer
Deprecated.Use URL parameter class= instead: jdbc:filter[class=com.example.MyTransformer]:jdbc:... Per-thread transformers cause confusion in pooled connection scenarios.Set the transformer for SQL transformation for this thread.- Parameters:
transformer- the JdbcTransformer to use
-