Package groovy.sql
Class SqlWhereVisitor
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
groovy.sql.SqlWhereVisitor
- All Implemented Interfaces:
GroovyCodeVisitor
AST visitor used by
DataSet to derive an SQL WHERE clause
and positional parameter list from a supported filter closure.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the positional parameters collected while building the SQL fragment.getWhere()Returns the SQLWHEREfragment built so far.voidsetClosure(Closure<?> closure) Supplies the closure whose captured variables may be referenced while the SQL fragment is being derived.protected StringtokenAsSql(Token token) Maps a Groovy AST token to its SQL operator representation.voidvisitBinaryExpression(BinaryExpression expression) Visits a binary expression and renders it as SQL, collecting any literal values as parameters.voidvisitBooleanExpression(BooleanExpression expression) Visits the wrapped boolean expression.voidvisitConstantExpression(ConstantExpression expression) Adds a constant value as a positional parameter.voidvisitPropertyExpression(PropertyExpression expression) Appends a property reference as a column name.voidvisitReturnStatement(ReturnStatement statement) Visits the closure return expression that defines the filter.voidvisitVariableExpression(VariableExpression expression) Resolves a variable captured from the enclosing closure scope and adds it as a positional parameter.Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitWhileLoopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Constructor Details
-
SqlWhereVisitor
public SqlWhereVisitor()
-
-
Method Details
-
getWhere
Returns the SQLWHEREfragment built so far.- Returns:
- the derived where fragment
-
visitReturnStatement
Visits the closure return expression that defines the filter.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classCodeVisitorSupport- Parameters:
statement- the return statement to visit
-
visitBinaryExpression
Visits a binary expression and renders it as SQL, collecting any literal values as parameters.- Specified by:
visitBinaryExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBinaryExpressionin classCodeVisitorSupport- Parameters:
expression- the binary expression to visit
-
visitBooleanExpression
Visits the wrapped boolean expression.- Specified by:
visitBooleanExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBooleanExpressionin classCodeVisitorSupport- Parameters:
expression- the boolean expression to visit
-
visitConstantExpression
Adds a constant value as a positional parameter.- Specified by:
visitConstantExpressionin interfaceGroovyCodeVisitor- Overrides:
visitConstantExpressionin classCodeVisitorSupport- Parameters:
expression- the constant expression to visit
-
visitPropertyExpression
Appends a property reference as a column name.- Specified by:
visitPropertyExpressionin interfaceGroovyCodeVisitor- Overrides:
visitPropertyExpressionin classCodeVisitorSupport- Parameters:
expression- the property expression to visit
-
setClosure
Supplies the closure whose captured variables may be referenced while the SQL fragment is being derived.- Parameters:
closure- the closure currently being translated- Since:
- 6.0.0
-
visitVariableExpression
Resolves a variable captured from the enclosing closure scope and adds it as a positional parameter.- Specified by:
visitVariableExpressionin interfaceGroovyCodeVisitor- Overrides:
visitVariableExpressionin classCodeVisitorSupport- Parameters:
expression- the variable expression to visit
-
getParameters
Returns the positional parameters collected while building the SQL fragment.- Returns:
- the collected parameter values
-
tokenAsSql
Maps a Groovy AST token to its SQL operator representation.- Parameters:
token- the AST token to translate- Returns:
- the SQL operator text
-