Package org.pjdbc.sql
Class WhereTransformer
java.lang.Object
org.pjdbc.sql.AbstractJdbcTransformer
org.pjdbc.sql.WhereTransformer
- All Implemented Interfaces:
JdbcTransformer
Transformer that appends conditions to WHERE clauses in SQL.
Adds a condition to SELECT, UPDATE, and DELETE statements. If a WHERE clause exists, the condition is appended with AND. If no WHERE clause exists, one is added before any GROUP BY, HAVING, ORDER BY, LIMIT, or end of statement.
URL Configuration
jdbc:filter[where=deleted=false]:jdbc:postgresql://localhost/db jdbc:filter[where=tenant_id=123]:jdbc:mysql://localhost/db
Examples
SELECT * FROM users→SELECT * FROM users WHERE deleted=falseSELECT * FROM users WHERE active=true→SELECT * FROM users WHERE active=true AND deleted=falseSELECT * FROM users ORDER BY name→SELECT * FROM users WHERE deleted=false ORDER BY nameUPDATE users SET x=1→UPDATE users SET x=1 WHERE deleted=falseDELETE FROM users→DELETE FROM users WHERE deleted=false
Limitations
- Uses regex heuristics - may not handle complex SQL perfectly
- Does not parse SQL AST
- INSERT statements are not modified
- Subqueries may not be handled correctly in all cases
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionWhereTransformer(String condition) Create a WhereTransformer with the specified condition. -
Method Summary
Modifier and TypeMethodDescriptiontransformSql(String sql) Default implementation returns SQL unchanged.Methods inherited from class org.pjdbc.sql.AbstractJdbcTransformer
transformParameter, transformResultValue
-
Constructor Details
-
WhereTransformer
Create a WhereTransformer with the specified condition.- Parameters:
condition- the condition to append (e.g., "deleted=false")
-
-
Method Details
-
transformSql
Description copied from class:AbstractJdbcTransformerDefault implementation returns SQL unchanged.- Specified by:
transformSqlin interfaceJdbcTransformer- Overrides:
transformSqlin classAbstractJdbcTransformer- Parameters:
sql- Original SQL string- Returns:
- Transformed SQL string
- Throws:
SQLException- if transformation fails
-