1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.query.FromItem; 32 import com.caucho.amber.query.QueryParser; 33 import com.caucho.amber.table.Table; 34 import com.caucho.amber.type.EntityType; 35 import com.caucho.util.CharBuffer; 36 37 40 public class IdExpr extends AbstractPathExpr { 41 private FromItem _fromItem; 42 43 46 public IdExpr(FromItem fromItem) 47 { 48 _fromItem = fromItem; 49 50 } 53 54 57 String getId() 58 { 59 return _fromItem.getName(); 60 } 61 62 65 public FromItem getFromItem() 66 { 67 return _fromItem; 68 } 69 70 73 Table getTable() 74 { 75 return _fromItem.getTable(); 76 } 77 78 81 public FromItem getChildFromItem() 82 { 83 return getFromItem(); 84 } 85 86 89 public EntityType getTargetType() 90 { 91 return _fromItem.getEntityType(); 92 } 93 94 97 public AmberExpr bindSelect(QueryParser parser) 98 { 99 return this; 100 } 101 102 105 public FromItem bindSubPath(QueryParser parser) 106 { 107 return _fromItem; 108 } 109 110 113 public boolean usesFrom(FromItem from, int type, boolean isNot) 114 { 115 return (type == IS_INNER_JOIN && _fromItem == from); 116 } 117 118 121 public AmberExpr replaceJoin(JoinExpr join) 122 { 123 return join.replace(this); 124 } 125 126 129 public void generateWhere(CharBuffer cb) 130 { 131 generateInternalWhere(cb, true); 132 } 133 134 137 public void generateUpdateWhere(CharBuffer cb) 138 { 139 generateInternalWhere(cb, false); 140 } 141 142 145 public void generateHaving(CharBuffer cb) 146 { 147 generateWhere(cb); 148 } 149 150 public String toString() 151 { 152 return getId(); 153 } 154 155 public int hashCode() 156 { 157 return _fromItem.hashCode(); 158 } 159 160 public boolean equals(Object o) 161 { 162 if (o == null || ! getClass().equals(o.getClass())) 163 return false; 164 165 IdExpr id = (IdExpr) o; 166 167 return _fromItem.equals(id._fromItem); 168 } 169 170 173 private void generateInternalWhere(CharBuffer cb, 174 boolean select) 175 { 176 if (select) { 177 cb.append(_fromItem.getName()); 178 cb.append('.'); 179 } 180 181 cb.append(getTargetType().getId().getColumns().get(0).getName()); 182 } 183 } 184 | Popular Tags |