1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.CharBuffer; 33 34 import java.util.ArrayList ; 35 36 39 class AndExpr extends Expr { 40 private ArrayList <Expr> _components = new ArrayList <Expr>(); 42 43 46 AndExpr(Query query) 47 throws ConfigException 48 { 49 setJavaType(boolean.class); 50 } 51 52 55 void evalTypes() 56 throws ConfigException 57 { 58 setJavaType(boolean.class); 59 } 60 61 64 void add(Expr expr) 65 { 66 _components.add(expr); 67 } 68 69 72 Expr getSingleExpr() 73 { 74 if (_components.size() == 1) 75 return _components.get(0); 76 else 77 return this; 78 } 79 80 85 void generateWhere(CharBuffer cb) 86 { 87 if (_components.size() == 1) { 88 Expr comp = _components.get(0); 89 90 comp.generateWhere(cb); 91 return; 92 } 93 94 for (int i = 0; i < _components.size(); i++) { 95 Expr comp = _components.get(i); 96 97 if (i != 0) 98 cb.append(" AND "); 99 100 comp.generateWhereSubExpr(cb); 101 } 102 } 103 104 107 void generateWhereSubExpr(CharBuffer cb) 108 { 109 cb.append("("); 110 generateWhere(cb); 111 cb.append(")"); 112 } 113 114 void printSelect(CharBuffer cb) 115 throws ConfigException 116 { 117 cb.append("("); 118 generateWhere(cb); 119 cb.append(")"); 120 } 121 122 public String toString() 123 { 124 CharBuffer value = CharBuffer.allocate(); 125 126 value.append("("); 127 128 for (int i = 0; i < _components.size(); i++) { 129 Expr comp = _components.get(i); 130 131 if (i != 0) 132 value.append(" AND "); 133 134 value.append(comp.toString()); 135 } 136 137 value.append(")"); 138 139 return value.close(); 140 } 141 } 142 | Popular Tags |