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.CmrRelation; 34 import com.caucho.ejb.cfg.EjbEntityBean; 35 import com.caucho.util.CharBuffer; 36 37 41 class CollectionExpr extends Expr { 42 private PathExpr _base; 44 private String _fieldName; 46 47 private CmrRelation _relation; 49 50 private CollectionIdExpr _id; 51 private boolean _usesField; 52 53 59 CollectionExpr(Query query, PathExpr base, 60 String field, CmrRelation relation) 61 throws ConfigException 62 { 63 _query = query; 64 _base = base; 65 _fieldName = field; 66 _relation = relation; 67 68 base.setUsesField(); 69 70 } 72 73 void setId(CollectionIdExpr id) 74 { 75 if (_id != null) 76 throw new RuntimeException (); 77 78 _id = id; 79 } 80 81 CollectionIdExpr getId() 82 { 83 return _id; 84 } 85 86 void setUsesField() 87 { 88 if (! _usesField) { 89 _usesField = true; 90 } 91 } 92 93 PathExpr getBase() 94 { 95 return _base; 96 } 97 98 EjbEntityBean getItemBean() 99 { 100 return _relation.getTargetBean(); 101 } 102 103 int getComponentCount() 104 { 105 EjbEntityBean bean = getItemBean(); 106 107 EntityType type = bean.getEntityType(); 108 109 return type.getId().getKeyCount(); 110 } 111 112 115 String getReturnEJB() 116 { 117 return getItemBean().getEJBName(); 118 } 119 120 CmrRelation getRelation() 121 { 122 return _relation; 123 } 124 125 130 void generateSelect(CharBuffer cb) 131 { 132 _base.generateSelect(cb); 133 cb.append('.'); 134 cb.append(_fieldName); 135 136 } 138 139 public String toString() 140 { 141 return String.valueOf(_base) + "." + _fieldName; 142 } 143 } 144 | Popular Tags |