Class ToSqlVisitor

  • All Implemented Interfaces:
    com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>

    public class ToSqlVisitor
    extends java.lang.Object
    implements com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
    Converts a lambda expression to an SQL where condition.
    • Constructor Summary

      Constructors 
      Constructor Description
      ToSqlVisitor​(java.lang.String prefix)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.BinaryExpression e)
      Converts a binary expression to the SQL equivalent.
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.ConstantExpression e)
      Returns a constant used in a lambda expression as the SQL equivalent.
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.InvocationExpression e)
      An expression which represents an invocation of a lambda expression.
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.LambdaExpression<?> e)
      The entry point for converting lambda expressions.
      java.lang.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.
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.ParameterExpression e)
      Represents a parameterized expression, for example if a variable is used in a query.
      java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.UnaryExpression e)
      Converts a unary expression to the SQL equivalent.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ToSqlVisitor

        public ToSqlVisitor​(java.lang.String prefix)
    • Method Detail

      • visit

        public java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.BinaryExpression e)
        Converts a binary expression to the SQL equivalent. For example: person -> person.getId() == 2 becomes: id = 2
        Specified by:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - the BinaryExpression to convert
        Returns:
        the StringBuilder containing the where condition.
      • visit

        public java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.ConstantExpression e)
        Returns a constant used in a lambda expression as the SQL equivalent. The only time this equivalent differs is when it is a String.
        Specified by:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - The ConstantExpression to transform.
        Returns:
        A StringBuilder that has this constant appended.
      • visit

        public java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.InvocationExpression e)
        An expression which represents an invocation of a lambda expression. It is the last visit(com.trigersoft.jaque.expression.BinaryExpression) where the parameters of ParameterExpressions are available which is why they are temporarily saved in a list to be inserted into the SQL where condition later.
        Specified by:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - The InvocationExpression to convert.
        Returns:
        A StringBuilder containing the body/target of the lambda expression.
      • visit

        public java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.LambdaExpression<?> e)
        The entry point for converting lambda expressions.
        Specified by:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - The entire lambda expression to convert.
        Returns:
        A StringBuilder containing the body of the lambda expression.
      • visit

        public java.lang.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:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - The MemberExpression to convert.
        Returns:
        A StringBuilder with the name of the database field appended.
      • visit

        public java.lang.StringBuilder visit​(com.trigersoft.jaque.expression.ParameterExpression e)
        Represents a parameterized expression, for example if a variable is used in a query.
        Specified by:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - The parameterized expression.
        Returns:
        The StringBuilder with the SQL equivalent appended.
      • visit

        public java.lang.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:
        visit in interface com.trigersoft.jaque.expression.ExpressionVisitor<java.lang.StringBuilder>
        Parameters:
        e - the UnaryExpression to convert
        Returns:
        A StringBuilder with the unary expression appended.