1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.bytecode.JClass; 32 import com.caucho.config.ConfigException; 33 import com.caucho.util.CharBuffer; 34 35 38 class IsExpr extends Expr { 39 private Expr _value; 41 private int _op; 43 private boolean _isNot; 45 46 53 IsExpr(Query query, Expr value, int op, boolean isNot) 54 throws ConfigException 55 { 56 _query = query; 57 58 _value = value; 59 _op = op; 60 _isNot = isNot; 61 62 evalTypes(); 63 } 64 65 68 void evalTypes() 69 throws ConfigException 70 { 71 if (getJavaType() != null) 72 return; 73 74 if (_op == Query.EMPTY && ! _value.isCollection()) 75 throw error(L.l("IS EMPTY requires a collection at `{0}'", 76 _value)); 77 else if (_op == Query.NULL && _value.isCollection()) 78 throw error(L.l("IS NULL requires a single value at `{0}'", 79 _value)); 80 81 setJavaType(boolean.class); 82 } 83 84 85 90 void generateWhere(CharBuffer cb) 91 { 92 _value.generateWhereSubExpr(cb); 93 94 JClass valueType = _value.getJavaType(); 95 116 117 if (_isNot) 118 cb.append(" IS NOT "); 119 else 120 cb.append(" IS "); 121 122 switch (_op) { 123 case Query.NULL: 124 cb.append("NULL"); 125 break; 126 case Query.EMPTY: 127 cb.append("EMPTY"); 128 break; 129 } 130 } 131 132 133 public String toString() 134 { 135 String str = _value.toString(); 136 137 if (_isNot) 138 str += " IS NOT "; 139 else 140 str += " IS "; 141 142 switch (_op) { 143 case Query.NULL: 144 return str + "NULL"; 145 case Query.EMPTY: 146 return str + "EMPTY"; 147 default: 148 return super.toString(); 149 } 150 } 151 } 152 | Popular Tags |