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 EmptyExpr extends AbstractAmberExpr { 40 private AmberExpr _collectionExpr; 41 42 private String _tableName; 43 44 EmptyExpr(AmberExpr collectionExpr) 45 { 46 _collectionExpr = collectionExpr; 47 } 48 49 52 public AmberExpr bindSelect(QueryParser parser) 53 { 54 _tableName = parser.createTableName(); 55 56 return this; 57 } 58 59 62 public boolean usesFrom(FromItem from, int type, boolean isNot) 63 { 64 return (_collectionExpr.usesFrom(from, type)); 65 } 66 67 70 public AmberExpr replaceJoin(JoinExpr join) 71 { 72 _collectionExpr = _collectionExpr.replaceJoin(join); 73 74 return this; 75 } 76 77 80 public void generateWhere(CharBuffer cb) 81 { 82 if (_collectionExpr instanceof OneToManyExpr) { 83 OneToManyExpr oneToMany = (OneToManyExpr) _collectionExpr; 84 85 LinkColumns join = oneToMany.getLinkColumns(); 86 87 cb.append("EXISTS(SELECT *"); 88 Table table = join.getSourceTable(); 89 cb.append(" FROM " + table.getName() + " " + _tableName); 90 cb.append(" WHERE "); 91 92 String targetTable = oneToMany.getParent().getChildFromItem().getName(); 93 94 cb.append(join.generateJoin(_tableName, targetTable)); 95 96 cb.append(')'); 97 } 98 else 99 throw new UnsupportedOperationException(); 100 } 101 } 102 | Popular Tags |