1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.util.CharBuffer; 32 33 import com.caucho.amber.table.Table; 34 import com.caucho.amber.table.LinkColumns; 35 36 39 public class MemberExpr extends AbstractAmberExpr { 40 private boolean _isNot; 41 private PathExpr _itemExpr; 42 private AmberExpr _collectionExpr; 43 44 private MemberExpr(PathExpr itemExpr, 45 AmberExpr collectionExpr, boolean isNot) 46 { 47 _itemExpr = itemExpr; 48 _collectionExpr = collectionExpr; 49 } 50 51 static AmberExpr create(QueryParser parser, 52 PathExpr itemExpr, 53 AmberExpr collectionExpr, 54 boolean isNot) 55 { 56 if (collectionExpr instanceof IdExpr) 57 collectionExpr = ((CollectionIdExpr) collectionExpr).getPath(); 58 59 if (collectionExpr instanceof OneToManyExpr) { 60 OneToManyExpr oneToMany = (OneToManyExpr) collectionExpr; 61 PathExpr parent = oneToMany.getParent(); 62 63 AmberExpr expr; 64 expr = new ManyToOneJoinExpr(oneToMany.getLinkColumns(), 65 itemExpr.getChildFromItem(), 66 parent.getChildFromItem()); 67 68 if (isNot) 69 return new UnaryExpr(QueryParser.NOT, expr); 70 else 71 return expr; 72 } 73 else 74 return new MemberExpr(itemExpr, collectionExpr, isNot); 75 } 76 77 80 public AmberExpr bindSelect(QueryParser parser) 81 { 82 return this; 83 } 84 85 88 public boolean usesFrom(FromItem from, int type, boolean isNot) 89 { 90 return (_collectionExpr.usesFrom(from, type) || 91 _itemExpr.usesFrom(from, type)); 92 } 93 94 97 public AmberExpr replaceJoin(JoinExpr join) 98 { 99 _collectionExpr = _collectionExpr.replaceJoin(join); 100 _itemExpr = (PathExpr) _itemExpr.replaceJoin(join); 101 102 return this; 103 } 104 105 108 public void generateWhere(CharBuffer cb) 109 { 110 if (_collectionExpr instanceof OneToManyExpr) { 111 OneToManyExpr oneToMany = (OneToManyExpr) _collectionExpr; 112 113 LinkColumns join = oneToMany.getLinkColumns(); 114 115 cb.append("EXISTS(SELECT *"); 116 Table table = join.getSourceTable(); 117 cb.append(" FROM " + table.getName() + " caucho"); 118 cb.append(')'); 119 } 120 else 121 throw new UnsupportedOperationException(); 122 } 123 } 124 | Popular Tags |