1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.amber.type.EntityType; 32 import com.caucho.bytecode.JClass; 33 import com.caucho.config.ConfigException; 34 import com.caucho.ejb.cfg.CmrRelation; 35 import com.caucho.ejb.cfg.EjbEntityBean; 36 import com.caucho.util.CharBuffer; 37 38 41 class RelationExpr extends PathExpr { 42 private PathExpr _base; 44 private String _fieldName; 46 47 private CmrRelation _relation; 49 50 private String _keyTable; 51 private String []_keyColumns; 52 53 private boolean _usesField; 54 55 61 RelationExpr(Query query, PathExpr base, 62 String field, CmrRelation relation) 63 throws ConfigException 64 { 65 super(relation.getTargetBean()); 66 67 _query = query; 68 _base = base; 69 _fieldName = field; 70 _relation = relation; 71 72 74 83 } 84 85 88 public JClass getJavaType() 89 { 90 return _relation.getTargetType(); 91 } 92 93 void setUsesField() 94 { 95 if (_usesField) 96 return; 97 98 _usesField = true; 99 100 108 } 110 111 String getKeyTable() 112 { 113 return _keyTable; 114 } 115 116 String []getKeyFields() 117 { 118 return _keyColumns; 119 } 120 121 String getTable() 122 { 123 return _keyTable; 124 } 125 126 129 String getName() 130 { 131 return _keyTable; 132 } 133 134 137 EjbEntityBean getBean() 138 { 139 return _bean; 140 } 141 142 EjbEntityBean getItemBean() 143 { 144 return _bean; 145 } 146 147 150 String getReturnEJB() 151 { 152 return _bean.getEJBName(); 153 } 154 155 int getComponentCount() 156 { 157 return getItemBean().getEntityType().getId().getKeyCount(); 158 } 159 160 165 void generateSelect(CharBuffer cb) 166 { 167 generateWhere(cb); 168 } 169 170 175 String getSelectTable(CharBuffer cb) 176 { 177 return getKeyTable(); 178 } 179 180 185 void generateWhere(CharBuffer cb) 186 { 187 _base.generateWhere(cb); 188 cb.append("."); 189 cb.append(_fieldName); 190 } 191 192 201 202 void generateComponent(CharBuffer cb, int index) 203 { 204 EjbEntityBean bean = getItemBean(); 205 206 EntityType type = bean.getEntityType(); 207 208 _base.generateWhere(cb); 209 cb.append("."); 210 cb.append(_fieldName); 211 cb.append("."); 212 213 cb.append(keyComponent(type, index)); 214 } 215 216 219 public boolean equals(Object bObj) 220 { 221 if (! (bObj instanceof RelationExpr)) 222 return false; 223 224 RelationExpr b = (RelationExpr) bObj; 225 226 return _fieldName.equals(b._fieldName) && _base.equals(b._base); 227 } 228 229 232 public int hashCode() 233 { 234 return 65531 * _fieldName.hashCode() + _base.hashCode(); 235 } 236 237 240 public String toString() 241 { 242 return String.valueOf(_base) + '.' + _fieldName; 243 } 244 } 245 | Popular Tags |