1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.amber.type.EntityType; 32 import com.caucho.config.ConfigException; 33 import com.caucho.ejb.cfg.EjbEntityBean; 34 import com.caucho.util.CharBuffer; 35 36 39 class IdExpr extends PathExpr { 40 private String _name; 42 43 private String _tableName; 45 46 53 IdExpr(Query query, String name, EjbEntityBean bean) 54 throws ConfigException 55 { 56 super(bean); 57 58 _query = query; 59 _name = name; 60 61 setJavaType(bean.getEJBClass()); 62 } 63 64 67 String getName() 68 { 69 return _name; 70 } 71 72 String getKeyTable() 73 { 74 return getName(); 75 } 76 77 String []getKeyFields() 78 { 79 84 throw new UnsupportedOperationException (); 85 } 86 87 90 String getReturnEJB() 91 { 92 return getBean().getEJBName(); 93 } 94 95 String getTable() 96 { 97 return _name; 98 } 99 100 103 EjbEntityBean getBean() 104 { 105 return _bean; 106 } 107 108 111 void setBean(EjbEntityBean bean) 112 { 113 _bean = bean; 114 } 115 116 119 String getTableName() 120 { 121 if (_tableName != null) 122 return _tableName; 123 else if (_bean != null) 124 return _bean.getSQLTable(); 125 else 126 return null; 127 } 128 129 132 void setTableName(String tableName) 133 { 134 _tableName = tableName; 135 } 136 137 140 EjbEntityBean getItemBean() 141 { 142 return _bean; 143 } 144 145 int getComponentCount() 146 { 147 EjbEntityBean bean = getItemBean(); 148 149 EntityType type = bean.getEntityType(); 150 151 return type.getId().getKeyCount(); 152 } 153 154 159 void printSelect(CharBuffer cb) 160 throws ConfigException 161 { 162 if (_bean == null) 163 throw new ConfigException("no bean for " + getName()); 164 165 184 cb.append(getName()); 185 } 186 187 192 String getSelectTable(CharBuffer cb) 193 throws ConfigException 194 { 195 203 return getName(); 204 } 205 206 211 void generateWhere(CharBuffer cb) 212 { 213 if (_bean == null) 214 throw new IllegalStateException ("no bean for " + getName()); 215 216 cb.append(getName()); 217 218 233 } 234 235 void generateComponent(CharBuffer cb, int index) 236 { 237 EjbEntityBean bean = getItemBean(); 238 239 EntityType type = bean.getEntityType(); 240 241 cb.append(getName()); 242 cb.append("."); 243 244 cb.append(keyComponent(type, index)); 245 } 246 247 252 void generateAmber(CharBuffer cb) 253 { 254 cb.append(getBean().getAbstractSchemaName()); 255 cb.append(' '); 256 cb.append(getName()); 257 } 258 259 262 public boolean equals(Object bObj) 263 { 264 if (! (bObj instanceof IdExpr)) 265 return false; 266 267 IdExpr b = (IdExpr) bObj; 268 269 return _name.equals(b._name); 270 } 271 272 275 public int hashCode() 276 { 277 return _name.hashCode(); 278 } 279 280 283 public String toString() 284 { 285 return _name; 286 } 287 } 288 | Popular Tags |