1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.ejb.cfg.EjbEntityBean; 33 import com.caucho.util.CharBuffer; 34 35 import java.lang.reflect.Method ; 36 37 40 class MemberExpr extends Expr { 41 private PathExpr _item; 43 private CollectionExpr _collection; 45 private CollectionIdExpr _collectionId; 46 private boolean _isNot; 48 49 private Query _parent; 50 51 57 MemberExpr(boolean isNot, Expr item, Expr collection) 58 throws ConfigException 59 { 60 _isNot = isNot; 61 62 if (collection instanceof CollectionExpr) 63 _collection = (CollectionExpr) collection; 64 else if (collection instanceof CollectionIdExpr) { 65 _collectionId = (CollectionIdExpr) collection; 66 } 67 else 68 throw error(L.l("MEMBER OF needs a collection-valued field at `{0}'.", 69 collection)); 70 71 if (! (item instanceof PathExpr)) 72 throw error(L.l("MEMBER OF needs a single-valued field at `{0}'.", 73 item)); 74 75 _item = (PathExpr) item; 76 77 setJavaType(boolean.class); 78 } 79 80 public String addRelation(EjbEntityBean bean, FieldExpr id) 81 throws ConfigException 82 { 83 return null; 84 } 85 86 public Method getMethod() 87 { 88 throw new UnsupportedOperationException (); 90 } 91 92 public EjbEntityBean getPersistentBean() 93 { 94 throw new UnsupportedOperationException (); 96 } 97 98 public void addArg(Expr arg) 99 { 100 throw new UnsupportedOperationException (); 102 } 103 104 109 void generateWhere(CharBuffer cb) 110 { 111 if (_isNot) 112 cb.append("NOT "); 113 114 _item.generateWhere(cb); 115 116 cb.append(" MEMBER OF ("); 117 118 if (_collection != null) 119 _collection.generateSelect(cb); 120 else 121 _collectionId.generateSelect(cb); 122 123 cb.append(")"); 124 125 180 } 181 182 public String toString() 183 { 184 String str = _item.toString(); 185 186 if (_isNot) 187 return str + " NOT MEMBER OF " + _collection; 188 else 189 return str + " MEMBER OF " + _collection; 190 } 191 } 192 | Popular Tags |