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 InExpr extends Expr { 40 private Expr _expr; 42 private ArrayList <Expr> _args; 44 private boolean _isNot; 46 47 54 InExpr(Query query, Expr expr, ArrayList <Expr> args, boolean isNot) 55 throws ConfigException 56 { 57 _query = query; 58 59 _expr = expr; 60 _args = args; 61 _isNot = isNot; 62 63 evalTypes(); 64 } 65 66 69 void evalTypes() 70 throws ConfigException 71 { 72 if (getJavaType() != null) 73 return; 74 75 for (int i = 0; i < _args.size(); i++) { 76 Expr expr = _args.get(i); 77 78 if (! expr.isString()) 79 throw error(L.l("'IN' literal requires strings at `{0}'", 80 expr)); 81 } 82 83 setJavaType(boolean.class); 84 } 85 86 87 92 void generateWhere(CharBuffer cb) 93 { 94 _expr.generateWhereSubExpr(cb); 95 96 if (_isNot) 97 cb.append(" NOT "); 98 99 cb.append(" IN ("); 100 for (int i = 0; i < _args.size(); i++) { 101 Expr arg = _args.get(i); 102 103 if (i != 0) 104 cb.append(", "); 105 106 arg.generateWhereSubExpr(cb); 107 } 108 cb.append(")"); 109 } 110 111 112 public String toString() 113 { 114 String str = _expr.toString(); 115 116 if (_isNot) 117 str += " NOT "; 118 119 str += " IN ("; 120 for (int i = 0; i < _args.size(); i++) { 121 if (i != 0) 122 str += ", "; 123 124 Expr arg = _args.get(i); 125 126 str += arg; 127 } 128 str += ")"; 129 130 return str; 131 } 132 } 133 | Popular Tags |