1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors; 23 24 import java.util.Map ; 25 26 import javax.persistence.OneToMany; 27 28 import oracle.toplink.essentials.internal.helper.DatabaseField; 29 30 import oracle.toplink.essentials.mappings.OneToOneMapping; 31 import oracle.toplink.essentials.mappings.OneToManyMapping; 32 import oracle.toplink.essentials.mappings.ManyToManyMapping; 33 34 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor; 35 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor; 36 37 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor; 38 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject; 39 40 46 public class OneToManyAccessor extends CollectionAccessor { 47 50 public OneToManyAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) { 51 super(accessibleObject, classAccessor); 52 53 OneToMany oneToMany = getAnnotation(OneToMany.class); 56 57 if (oneToMany != null) { 58 setFetchType(oneToMany.fetch()); 59 setMappedBy(oneToMany.mappedBy()); 60 setCascadeTypes(oneToMany.cascade()); 61 setTargetEntity(oneToMany.targetEntity()); 62 } 63 } 64 65 68 public boolean isOneToMany() { 69 return true; 70 } 71 72 78 public void process() { 79 String mappedBy = getMappedBy(); 80 81 if (mappedBy.equals("")) { 83 if (hasJoinColumn() || hasJoinColumns()) { 85 getValidator().throwUniDirectionalOneToManyHasJoinColumnSpecified(getJavaClass(), getAttributeName()); 86 } 87 88 ManyToManyMapping mapping = new ManyToManyMapping(); 90 populateCollectionMapping(mapping, m_logger.ONE_TO_MANY_MAPPING_REFERENCE_CLASS); 91 92 processJoinTable(getJoinTable(), mapping); 94 95 m_descriptor.addMapping(mapping); 97 } else { 98 OneToManyMapping mapping = new OneToManyMapping(); 100 populateCollectionMapping(mapping, m_logger.ONE_TO_MANY_MAPPING_REFERENCE_CLASS); 101 102 OneToOneMapping ownerMapping = null; 104 if (getOwningMapping().isOneToOneMapping()){ 105 ownerMapping = (OneToOneMapping)getOwningMapping(); 106 }else { 107 getValidator().throwIvalidMappingEncountered(getJavaClass(), getReferenceClass()); 109 } 110 111 Map <DatabaseField, DatabaseField> keys = ownerMapping.getSourceToTargetKeyFields(); 112 for (DatabaseField fkField : keys.keySet()) { 113 mapping.addTargetForeignKeyField(fkField, keys.get(fkField)); 114 } 115 116 m_descriptor.addMapping(mapping); 118 } 119 } 120 } 121 | Popular Tags |