KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > parsec > mssql > BoolExpressions


1 /*
2  * Created on 2004-11-16
3  *
4  * Author Ben Yu
5  */

6 package tests.jfun.parsec.mssql;
7
8 /**
9  * @author Ben Yu
10  *
11  * 2004-11-16
12  */

13 public final class BoolExpressions {
14   static BoolExpression inQuery(final Expression e, final Select sel){
15     return new BoolExpression(){
16       public int getPrecedence(){return Precedences.inRelation();}
17       public void accept(final BoolExpressionVisitor v){
18         v.visitInQuery(e, sel);
19       }
20       public String JavaDoc toString(){
21         return ""+e+" in ("+sel+")";
22       }
23     };
24   }
25   static BoolExpression exists(final Select sel){
26     return new BoolExpression(){
27       public int getPrecedence(){return Precedences.exists();}
28       public void accept(final BoolExpressionVisitor v){
29         v.visitExists(sel);
30       }
31       public String JavaDoc toString(){
32         return "exists (" + sel + ")";
33       }
34     };
35   }
36   static BoolExpression notIn(final Expression e, final Expression[] vals){
37     return new BoolExpression(){
38       public int getPrecedence(){return Precedences.notin();}
39       public void accept(BoolExpressionVisitor v){
40         v.visitNotIn(e, vals);
41       }
42       public String JavaDoc toString(){
43         return ""+e+" not in (" + ShowUtils.showList(vals, ",") + ")";
44       }
45     };
46   }
47   static BoolExpression notInQuery(final Expression e, final Select sel){
48     return new BoolExpression(){
49       public int getPrecedence(){return Precedences.notInRelation();}
50       public void accept(final BoolExpressionVisitor v){
51         v.visitNotInQuery(e, sel);
52       }
53       public String JavaDoc toString(){
54         return ""+e+" not in (" + sel + ")";
55       }
56     };
57   }
58   static BoolExpression like(final Expression e, final Expression pattern){
59     return new BoolExpression(){
60       public int getPrecedence(){return Precedences.like();}
61       public void accept(final BoolExpressionVisitor v){
62         v.visitLike(e, pattern, null);
63       }
64       public String JavaDoc toString(){
65         return ""+e+" like " + pattern;
66       }
67     };
68   }
69   static BoolExpression like(final Expression e, final Expression pattern, final Expression escape){
70     return new BoolExpression(){
71       public int getPrecedence(){return Precedences.like();}
72       public void accept(final BoolExpressionVisitor v){
73         v.visitLike(e, pattern, escape);
74       }
75       public String JavaDoc toString(){
76         return ""+e+" like " + pattern + " escape " + escape;
77       }
78     };
79   }
80   static BoolExpression notLike(final Expression e, final Expression pattern){
81     return new BoolExpression(){
82       public int getPrecedence(){return Precedences.notlike();}
83       public void accept(final BoolExpressionVisitor v){
84         v.visitNotLike(e, pattern, null);
85       }
86       public String JavaDoc toString(){
87         return ""+e+" not like " + pattern;
88       }
89     };
90   }
91   static BoolExpression notLike(final Expression e, final Expression pattern, final Expression escape){
92     return new BoolExpression(){
93       public int getPrecedence(){return Precedences.notlike();}
94       public void accept(final BoolExpressionVisitor v){
95         v.visitNotLike(e, pattern, escape);
96       }
97       public String JavaDoc toString(){
98         return ""+e+" not like " + pattern + " escape " + escape;
99       }
100     };
101   }
102 }
103
Popular Tags