1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.ejb.cfg.EjbEntityBean; 33 import com.caucho.util.CharBuffer; 34 35 38 class CollectionIdExpr extends PathExpr { 39 private String _name; 41 42 private CollectionExpr _path; 44 45 private String _keyTable; 46 private String []_keyColumns; 47 48 private boolean _usesField; 49 50 57 CollectionIdExpr(Query query, String name, CollectionExpr path) 58 throws ConfigException 59 { 60 super(path.getItemBean()); 61 62 _query = query; 63 _name = name; 64 _path = path; 65 66 path.setId(this); 67 68 if (getBean() == null) 69 throw new NullPointerException ("unknown bean for " + name + " " + query); 70 71 73 98 } 99 100 CollectionExpr getPath() 101 { 102 return _path; 103 } 104 105 void setUsesField() 106 { 107 if (_usesField) 108 return; 109 110 _usesField = true; 111 112 117 } 118 119 String getKeyTable() 120 { 121 return _keyTable; 122 } 123 124 String []getKeyFields() 125 { 126 return _keyColumns; 127 } 128 129 int getComponentCount() 130 { 131 return _path.getComponentCount(); 132 } 133 134 String getTable() 135 { 136 return _name; 137 } 138 139 142 String getName() 143 { 144 return _name; 145 } 146 147 150 EjbEntityBean getBean() 151 { 152 return _bean; 153 } 154 155 EjbEntityBean getItemBean() 156 { 157 return _bean; 158 } 159 160 String getReturnEJB() 161 { 162 return getItemBean().getEJBName(); 163 } 164 165 170 void printSelect(CharBuffer cb) 171 throws ConfigException 172 { 173 String []names = getKeyFields(); 174 175 for (int i = 0; i < names.length; i++) { 176 if (i != 0) 177 cb.append(", "); 178 179 cb.append(getKeyTable()); 180 cb.append("."); 181 cb.append(names[i]); 182 } 183 } 184 185 190 String getSelectTable(CharBuffer cb) 191 throws ConfigException 192 { 193 return getKeyTable(); 194 } 195 196 201 void printWhere(CharBuffer cb) 202 throws ConfigException 203 { 204 String []names = getKeyFields(); 205 if (names.length != 1) 206 throw new RuntimeException (); 207 208 cb.append(getKeyTable()); 209 cb.append("."); 210 cb.append(names[0]); 211 } 212 213 void printComponent(CharBuffer cb, int index) 214 throws ConfigException 215 { 216 cb.append(getKeyTable()); 217 cb.append("."); 218 cb.append(getKeyFields()[index]); 219 } 220 221 226 void generateWhere(CharBuffer cb) 227 { 228 if (_bean == null) 229 throw new IllegalStateException ("no bean for " + getName()); 230 231 cb.append(getName()); 232 } 233 234 239 void generateComponent(CharBuffer cb, int i) 240 { 241 if (_bean == null) 242 throw new IllegalStateException ("no bean for " + getName()); 243 244 cb.append(getName()); 245 cb.append('.'); 246 cb.append(generateKeyField(getItemBean().getEntityType(), i)); 247 } 248 249 254 void generateAmber(CharBuffer cb) 255 { 256 cb.append("IN("); 257 _path.generateSelect(cb); 258 cb.append(") "); 259 cb.append(getName()); 260 } 261 262 265 public boolean equals(Object bObj) 266 { 267 if (! (bObj instanceof CollectionIdExpr)) 268 return false; 269 270 CollectionIdExpr b = (CollectionIdExpr) bObj; 271 272 return _name.equals(b._name); 273 } 274 275 278 public int hashCode() 279 { 280 return _name.hashCode(); 281 } 282 283 286 public String toString() 287 { 288 return _name; 289 } 290 } 291 | Popular Tags |