1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.amber.field.IdField; 32 import com.caucho.amber.type.EntityType; 33 import com.caucho.config.ConfigException; 34 import com.caucho.ejb.cfg.CmpField; 35 import com.caucho.ejb.cfg.CmrRelation; 36 import com.caucho.ejb.cfg.EjbEntityBean; 37 import com.caucho.util.CharBuffer; 38 39 import java.util.ArrayList ; 40 import java.util.Collections ; 41 42 47 abstract class PathExpr extends Expr { 48 protected EjbEntityBean _bean; 49 50 PathExpr(EjbEntityBean bean) 51 { 52 _bean = bean; 53 54 setJavaType(bean.getEJBClass()); 55 } 56 57 60 EjbEntityBean getBean() 61 { 62 return _bean; 63 } 64 65 68 74 75 78 Expr newField(String fieldName) 79 throws ConfigException 80 { 81 CmpField field = _bean.getCmpField(fieldName); 82 83 if (field != null) 84 return new FieldExpr(_query, this, fieldName, field); 85 86 CmrRelation relation = _bean.getRelation(fieldName); 87 88 if (relation == null) 89 throw error(L.l("{0}: `{1}' is an unknown cmp-field.", 90 _bean.getEJBClass().getName(), 91 fieldName)); 92 93 95 if (relation.isCollection()) 96 return new CollectionExpr(_query, this, fieldName, relation); 97 else 98 return new RelationExpr(_query, this, fieldName, relation); 99 } 100 101 abstract String getKeyTable(); 102 abstract String []getKeyFields(); 103 104 abstract String getTable(); 105 106 int getComponentCount() 107 { 108 return getKeyFields().length; 109 } 110 111 void setUsesField() 112 { 113 } 114 115 protected String generateKeyField(EntityType type, int index) 116 { 117 ArrayList <String > names = generateKeyFields(type); 118 119 return names.get(index); 120 } 121 122 protected ArrayList <String > generateKeyFields(EntityType type) 123 { 124 ArrayList <String > names = new ArrayList <String >(); 125 126 for (IdField key : type.getId().getKeys()) { 127 String name = key.getName(); 128 129 if (key.getType() instanceof EntityType) { 130 ArrayList <String > subNames; 131 subNames = generateKeyFields((EntityType) key.getType()); 132 133 for (String subName : subNames) { 134 names.add(name + '.' + subName); 135 } 136 } 137 else 138 names.add(name); 139 } 140 141 Collections.sort(names); 142 143 return names; 144 } 145 146 void generateAmber(CharBuffer cb) 147 { 148 throw new UnsupportedOperationException (getClass().getName()); 149 } 150 } 151 | Popular Tags |