1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors; 23 24 import javax.persistence.ManyToMany; 25 26 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor; 27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject; 28 29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataHelper; 30 31 import oracle.toplink.essentials.mappings.ManyToManyMapping; 32 33 39 public class ManyToManyAccessor extends CollectionAccessor { 40 43 public ManyToManyAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) { 44 super(accessibleObject, classAccessor); 45 46 ManyToMany manyToMany = getAnnotation(ManyToMany.class); 47 48 if (manyToMany != null) { 49 setFetchType(manyToMany.fetch()); 50 setMappedBy(manyToMany.mappedBy()); 51 setCascadeTypes(manyToMany.cascade()); 52 setTargetEntity(manyToMany.targetEntity()); 53 } 54 } 55 56 59 public boolean isManyToMany() { 60 return true; 61 } 62 63 68 public void process() { 69 ManyToManyMapping mapping = new ManyToManyMapping(); 71 populateCollectionMapping(mapping, m_logger.MANY_TO_MANY_MAPPING_REFERENCE_CLASS); 72 73 if (m_mappedBy.equals("")) { 74 processJoinTable(getJoinTable(), mapping); 76 } else { 77 mapping.setIsReadOnly(true); 80 81 ManyToManyMapping ownerMapping = null; 83 if (getOwningMapping().isManyToManyMapping()){ 84 ownerMapping = (ManyToManyMapping)getOwningMapping(); 85 }else { 86 getValidator().throwIvalidMappingEncountered(getJavaClass(), getReferenceClass()); 88 } 89 90 mapping.setRelationTableName(ownerMapping.getRelationTableName()); 92 93 mapping.setSourceKeyFields(ownerMapping.getTargetKeyFields()); 95 mapping.setSourceRelationKeyFields(ownerMapping.getTargetRelationKeyFields()); 96 97 mapping.setTargetKeyFields(ownerMapping.getSourceKeyFields()); 99 mapping.setTargetRelationKeyFields(ownerMapping.getSourceRelationKeyFields()); 100 } 101 102 m_descriptor.addMapping(mapping); 104 } 105 } 106 | Popular Tags |