Class SqlVisitor
- java.lang.Object
-
- com.github.collinalpert.lambda2sql.SqlVisitor
-
- All Implemented Interfaces:
com.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>
public class SqlVisitor extends Object implements com.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>
Converts a lambda expression to an SQL where condition.
-
-
Method Summary
Modifier and Type Method Description StringBuildervisit(com.trigersoft.jaque.expression.BinaryExpression e)Converts a binary expression to the SQL equivalent.StringBuildervisit(com.trigersoft.jaque.expression.ConstantExpression e)Returns a constant used in a lambda expression as the SQL equivalent.StringBuildervisit(com.trigersoft.jaque.expression.DelegateExpression e)StringBuildervisit(com.trigersoft.jaque.expression.InvocationExpression e)An expression which represents an invocation of a lambda expression.StringBuildervisit(com.trigersoft.jaque.expression.LambdaExpression<?> e)The entry point for converting lambda expressions.StringBuildervisit(com.trigersoft.jaque.expression.MemberExpression e)An expression which represents a getter, and thus a field in a database, in the lambda expression.StringBuildervisit(com.trigersoft.jaque.expression.ParameterExpression e)Represents a parameterized expression, for example if a variable is used in a query.StringBuildervisit(com.trigersoft.jaque.expression.UnaryExpression e)Converts a unary expression to the SQL equivalent.
-
-
-
Method Detail
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.BinaryExpression e)
Converts a binary expression to the SQL equivalent. For example:person -> person.getId() == 2becomes: id = 2- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- theBinaryExpressionto convert- Returns:
- the
StringBuildercontaining the where condition.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.ConstantExpression e)
Returns a constant used in a lambda expression as the SQL equivalent.- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- TheConstantExpressionto transform.- Returns:
- A
StringBuilderthat has this constant appended.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.InvocationExpression e)
An expression which represents an invocation of a lambda expression. It is the lastvisit(com.trigersoft.jaque.expression.BinaryExpression)where the arguments ofParameterExpressions are available which is why they are temporarily saved in a list to be inserted into the SQL where condition later.- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- TheInvocationExpressionto convert.- Returns:
- A
StringBuildercontaining the body/target of the lambda expression.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.LambdaExpression<?> e)
The entry point for converting lambda expressions.- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- The entire lambda expression to convert.- Returns:
- A
StringBuildercontaining the body of the lambda expression.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.DelegateExpression e)
- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.MemberExpression e)
An expression which represents a getter, and thus a field in a database, in the lambda expression. For example:person -> person.getName();becomes: name- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- TheMemberExpressionto convert.- Returns:
- A
StringBuilderwith the name of the database field appended.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.ParameterExpression e)
Represents a parameterized expression, for example if a variable is used in a query.- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- The parameterized expression.- Returns:
- The
StringBuilderwith the SQL equivalent appended.
-
visit
public StringBuilder visit(com.trigersoft.jaque.expression.UnaryExpression e)
Converts a unary expression to the SQL equivalent. For example:person -> !person.isActive();becomes: !active- Specified by:
visitin interfacecom.trigersoft.jaque.expression.ExpressionVisitor<StringBuilder>- Parameters:
e- theUnaryExpressionto convert- Returns:
- A
StringBuilderwith the unary expression appended.
-
-