1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.CharBuffer; 33 34 37 class LikeExpr extends Expr { 38 private Expr _value; 40 private Expr _pattern; 42 private String _escape; 44 private boolean _isNot; 46 47 55 LikeExpr(Expr value, Expr pattern, String escape, boolean isNot) 56 throws ConfigException 57 { 58 _value = value; 59 _pattern = pattern; 60 _escape = escape; 61 _isNot = isNot; 62 63 evalTypes(); 64 } 65 66 69 void evalTypes() 70 throws ConfigException 71 { 72 if (getJavaType() != null) 73 return; 74 75 if (! _value.isString()) 76 throw error(L.l("LIKE value `{0}' must be a string expression", 77 _value)); 78 79 if (! _pattern.isString()) 80 throw error(L.l("LIKE pattern `{0}' must be a string expression.", 81 _pattern)); 82 83 setJavaType(boolean.class); 84 } 85 86 87 92 void generateWhere(CharBuffer cb) 93 { 94 _value.generateWhereSubExpr(cb); 95 96 if (_isNot) 97 cb.append(" NOT LIKE "); 98 else 99 cb.append(" LIKE "); 100 101 _pattern.generateWhereSubExpr(cb); 102 103 if (_escape != null) { 104 cb.append(" ESCAPE "); 105 cb.append(_escape); 106 } 107 } 108 109 public String toString() 110 { 111 String not = _isNot ? "NOT " : ""; 112 113 if (_escape != null) 114 return not + _pattern + " ESCAPE " + _escape; 115 else 116 return not + _pattern; 117 } 118 } 119 | Popular Tags |