package com.mysema.query.grammar; import com.mysema.query.grammar.Types.*; /** * Grammar provides * * @author tiwe * @version $Id$ */ public class Grammar { // order public static OrderSpecifier asc(Expr target){ return _asc(target); } public static OrderSpecifier desc(Expr target){ return _desc(target); } // boolean public static Expr and(Expr left, Expr right){ return _bbe(BoOp.AND, left, right); } public static Expr not(Expr left){ return _bue(BoOp.NE, left); } public static Expr or(Expr left, Expr right){ return _bbe(BoOp.OR, left, right); } // number compariosn public static Expr eq(Object left, Object right){ return _bbe(BoOp.EQ, left, right); } public static Expr goe(Object left, Object right){ return _bbe(BoOp.GOE, left, right); } public static Expr gt(Object left, Object right){ return _bbe(BoOp.GT, left, right); } public static Expr loe(Object left, Object right){ return _bbe(BoOp.LOE, left, right); } public static Expr lt(Object left, Object right){ return _bbe(BoOp.LT, left, right); } public static Expr ne(Object left, Object right){ return _bbe(BoOp.NE, left, right); } // string comparison public static Expr like(Expr left, String right){ return _bbe(BoOp.LIKE, left, right); } public static Expr lower(Expr path){ return null; } // arithmetic operations // TODO : +,-,*,/,mod,div // order static OrderSpecifier _asc(Expr target) { OrderSpecifier os = new OrderSpecifier(); os.order = Order.ASC; os.target = target; return os; } static OrderSpecifier _desc(Expr target) { OrderSpecifier os = new OrderSpecifier(); os.order = Order.DESC; os.target = target; return os; } // constants static Expr _co(A obj){ ConstantExpr e = new ConstantExpr(); e.constant = obj; return e; } // boolean static BooleanBinaryExpr _bbe(BoOp type,Object left, Object right){ BooleanBinaryExpr bbe = new BooleanBinaryExpr(); bbe.type = type; bbe.left = left instanceof Expr ? (Expr)left : _co(left); bbe.right = right instanceof Expr ? (Expr)right : _co(left); return bbe; } static BooleanUnaryExpr _bue(BoOp type, Expr left){ BooleanUnaryExpr bue = new BooleanUnaryExpr(); bue.type = type; bue.left = left; return bue; } }