KickJava   Java API By Example, From Geeks To Geeks.

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


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 Relations {
14   public static Relation tablename(final TableName tn){
15     return new Relation(){
16       public void acceptVisitor(RelationVisitor v){
17         v.visitTableName(tn);
18       }
19       public String JavaDoc toString(){
20         return ""+tn;
21       }
22     };
23   }
24   public static Relation join(final Relation r1, final int type,
25       final Relation r2, final BoolExpression cond){
26     return new Relation(){
27       public void acceptVisitor(RelationVisitor v){
28         v.visitJoin(r1, type, r2, cond);
29       }
30       public String JavaDoc toString(){
31         final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
32         buf.append('(').append(r1).append(' ');
33         switch(type){
34           case Join.FULL : buf.append("full outer"); break;
35           case Join.INNER : buf.append("inner");break;
36           case Join.LEFT : buf.append("left outer");break;
37           case Join.RIGHT : buf.append("right outer");break;
38           default : buf.append("unknown");
39         }
40         buf.append(" join ").append(r2).append(" on ").append(cond)
41         .append(')');
42         return buf.toString();
43       }
44     };
45   }
46   public static Relation product(final Relation r1, final Relation r2){
47     return new Relation(){
48       public void acceptVisitor(RelationVisitor v){
49         v.visitProduct(r1, r2);
50       }
51       public String JavaDoc toString(){
52         return "(" + r1 + " cross join " + r2 + ")";
53       }
54     };
55   }
56 }
57
Popular Tags