1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.amber.field.AmberField; 33 import com.caucho.amber.field.EntityMapField; 34 import com.caucho.amber.field.IdField; 35 import com.caucho.amber.type.EntityType; 36 import com.caucho.bytecode.JMethod; 37 import com.caucho.config.ConfigException; 38 import com.caucho.util.L10N; 39 40 43 public class CmrMap extends CmrRelation { 44 private static final L10N L = new L10N(CmrMap.class); 45 46 private EjbEntityBean _targetBean; 47 private CmrManyToOne _idRel; 48 private JMethod _mapMethod; 49 50 53 public CmrMap(EjbEntityBean sourceBean, 54 String fieldName, 55 EjbEntityBean targetBean, 56 CmrManyToOne idRel) 57 throws ConfigException 58 { 59 super(sourceBean); 60 61 setFieldName(fieldName); 62 63 _targetBean = targetBean; 64 _idRel = idRel; 65 } 66 67 70 public void setMapMethod(JMethod method) 71 { 72 _mapMethod = method; 73 } 74 75 78 public JMethod getMapMethod() 79 { 80 return _mapMethod; 81 } 82 83 86 public String getIndexName() 87 { 88 EntityType type = _targetBean.getEntityType(); 89 90 for (IdField key : type.getId().getKeys()) { 91 if (! key.getName().equals(_idRel.getName())) 92 return key.getName(); 93 } 94 95 throw new IllegalStateException (); 96 } 97 98 101 public String getIdName() 102 { 103 return _idRel.getName(); 104 } 105 106 109 public EjbEntityBean getTargetBean() 110 { 111 return _targetBean; 112 } 113 114 117 public EjbMethod createGetter(EjbView view, 118 JMethod apiMethod, 119 JMethod implMethod) 120 throws ConfigException 121 { 122 return new EjbMapMethod(view, apiMethod, implMethod, this); 123 } 124 125 128 public AmberField assembleAmber(EntityType type) 129 throws ConfigException 130 { 131 EntityMapField field = new EntityMapField(type); 132 133 field.setName(getName()); 134 field.setMapMethod(_mapMethod); 135 136 field.setTargetType(_targetBean.getEntityType()); 137 138 EntityType sourceType = _targetBean.getEntityType(); 139 for (IdField key : sourceType.getId().getKeys()) { 140 if (key.getName().equals(_idRel.getName())) { 141 field.setId(key); 142 } 143 else { 144 field.setIndex(key); 145 } 146 } 147 148 149 return field; 150 } 151 } 152 | Popular Tags |