1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.field.EntityEmbeddedField; 32 import com.caucho.amber.query.FromItem; 33 import com.caucho.amber.query.QueryParser; 34 import com.caucho.amber.table.Column; 35 import com.caucho.amber.type.EmbeddableType; 36 import com.caucho.amber.type.Type; 37 import com.caucho.util.CharBuffer; 38 39 import java.util.HashMap ; 40 import java.util.Map ; 41 42 45 public class EmbeddedExpr extends AbstractPathExpr { 46 private PathExpr _parent; 47 48 private EmbeddableType _embeddableType; 49 50 private HashMap <String , Column> _columns; 51 52 private HashMap <String , String > _fieldNameByColumn; 53 54 private FromItem _fromItem; 55 private FromItem _childFromItem; 56 57 60 public EmbeddedExpr(PathExpr parent, 61 EmbeddableType embeddableType, 62 HashMap <String , Column> columns, 63 HashMap <String , String > fieldNameByColumn) 64 { 65 _parent = parent; 66 _embeddableType = embeddableType; 67 _columns = columns; 68 _fieldNameByColumn = fieldNameByColumn; 69 } 70 71 74 public EmbeddableType getTargetType() 75 { 76 return _embeddableType; 77 } 78 79 82 public Type getType() 83 { 84 return _embeddableType; 85 } 86 87 90 public Column getColumnByFieldName(String fieldName) 91 { 92 for (Map.Entry <String , String > entry : 94 _fieldNameByColumn.entrySet()) { 95 96 String name = entry.getValue(); 97 98 if (name.equals(fieldName)) 99 return _columns.get(entry.getKey()); 100 } 101 102 return null; 103 } 104 105 108 public AmberExpr bindSelect(QueryParser parser) 109 { 110 _fromItem = _parent.bindSubPath(parser); 111 112 return this; 113 } 114 115 118 public FromItem getFromItem() 119 { 120 return _fromItem; 121 } 122 123 126 public FromItem getChildFromItem() 127 { 128 return _childFromItem; 129 } 130 131 134 public FromItem bindSubPath(QueryParser parser) 135 { 136 139 FromItem parentFromItem = _parent.bindSubPath(parser); 140 141 _fromItem = parentFromItem; 142 143 return _fromItem; 144 145 162 } 163 164 167 public PathExpr bindSelect(QueryParser parser, String id) 168 { 169 _fromItem = bindSubPath(parser); 170 171 return this; 172 173 182 } 183 184 187 public boolean usesFrom(FromItem from, int type, boolean isNot) 188 { 189 return (_childFromItem == from && type == IS_INNER_JOIN || 190 _fromItem == from || 191 _parent.usesFrom(from, type)); 192 } 193 194 197 public void generateMatchArgWhere(CharBuffer cb) 198 { 199 throw new UnsupportedOperationException (); 200 201 209 } 210 211 214 public void generateWhere(CharBuffer cb) 215 { 216 generateInternalWhere(cb, true); 217 } 218 219 222 public void generateUpdateWhere(CharBuffer cb) 223 { 224 generateInternalWhere(cb, false); 225 } 226 227 230 public void generateSelect(CharBuffer cb) 231 { 232 cb.append(EntityEmbeddedField.generateSelect(null, 233 _embeddableType, 234 _fieldNameByColumn, 235 _columns)); 236 } 237 238 241 public PathExpr getParent() 242 { 243 return _parent; 244 } 245 246 public int hashCode() 247 { 248 return 65521 * _parent.hashCode() + _columns.hashCode(); 249 } 250 251 public boolean equals(Object o) 252 { 253 if (o == null || ! getClass().equals(o.getClass())) 254 return false; 255 256 EmbeddedExpr embedded = (EmbeddedExpr) o; 257 258 return (_parent.equals(embedded._parent) && 259 _columns.equals(embedded._columns)); 260 } 261 262 public String toString() 263 { 264 return "EmbeddedExpr[" + _childFromItem + "," + _fromItem + "," + _parent + "]"; 265 } 266 267 270 private void generateInternalWhere(CharBuffer cb, 271 boolean select) 272 { 273 throw new UnsupportedOperationException (); 274 } 275 } 276 | Popular Tags |