1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.query.FromItem; 32 import com.caucho.amber.query.QueryParser; 33 import com.caucho.amber.type.BooleanType; 34 import com.caucho.amber.type.Type; 35 import com.caucho.util.CharBuffer; 36 37 40 public class LikeExpr extends AbstractAmberExpr { 41 private AmberExpr _expr; 42 43 private AmberExpr _value; 44 private String _escape; 45 private boolean _isNot; 46 47 50 public LikeExpr(AmberExpr expr, 51 AmberExpr value, 52 String escape, 53 boolean isNot) 54 { 55 _expr = expr; 56 _value = value; 57 _isNot = isNot; 58 _escape = escape; 59 } 60 61 64 public boolean isBoolean() 65 { 66 return true; 67 } 68 69 72 public Type getType() 73 { 74 return BooleanType.create(); 75 } 76 77 80 public AmberExpr bindSelect(QueryParser parser) 81 { 82 _expr = _expr.bindSelect(parser); 83 _value = _value.bindSelect(parser); 84 85 return this; 86 } 87 88 91 public boolean usesFrom(FromItem from, int type, boolean isNot) 92 { 93 return (_expr.usesFrom(from, type)); 94 } 95 96 99 public AmberExpr replaceJoin(JoinExpr join) 100 { 101 _expr = _expr.replaceJoin(join); 102 _value = _value.replaceJoin(join); 103 104 return this; 105 } 106 107 110 public void generateWhere(CharBuffer cb) 111 { 112 generateInternalWhere(cb, true); 113 } 114 115 118 public void generateUpdateWhere(CharBuffer cb) 119 { 120 generateInternalWhere(cb, false); 121 } 122 123 126 public void generateHaving(CharBuffer cb) 127 { 128 generateWhere(cb); 129 } 130 131 public String toString() 132 { 133 CharBuffer cb = CharBuffer.allocate(); 134 135 cb.append('('); 136 cb.append(_expr); 137 138 if (_isNot) 139 cb.append(" NOT"); 140 141 cb.append(" LIKE "); 142 143 cb.append(_value); 144 145 cb.append(')'); 146 147 return cb.close(); 148 } 149 150 153 private void generateInternalWhere(CharBuffer cb, 154 boolean select) 155 { 156 cb.append('('); 157 158 if (select) 159 _expr.generateWhere(cb); 160 else 161 _expr.generateUpdateWhere(cb); 162 163 if (_isNot) 164 cb.append(" NOT"); 165 166 cb.append(" LIKE "); 167 168 if (select) 169 _value.generateWhere(cb); 170 else 171 _value.generateUpdateWhere(cb); 172 173 if (_escape != null) { 174 cb.append(" ESCAPE "); 175 cb.append(_escape); 176 } 177 178 cb.append(')'); 179 } 180 } 181 | Popular Tags |