1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors; 23 24 import javax.persistence.FetchType; 25 import javax.persistence.OneToOne; 26 27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject; 28 import oracle.toplink.essentials.mappings.OneToOneMapping; 29 30 36 public class OneToOneAccessor extends ObjectAccessor { 37 40 public OneToOneAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) { 41 super(accessibleObject, classAccessor); 42 43 OneToOne oneToOne = getAnnotation(OneToOne.class); 46 47 if (oneToOne != null) { 48 setFetchType(oneToOne.fetch()); 49 setMappedBy(oneToOne.mappedBy()); 50 setIsOptional(oneToOne.optional()); 51 setCascadeTypes(oneToOne.cascade()); 52 setTargetEntity(oneToOne.targetEntity()); 53 } 54 } 55 56 59 public boolean isOneToOne() { 60 return true; 61 } 62 63 68 public void process() { 69 setReferenceClass(getTargetEntity(), m_logger.ONE_TO_ONE_MAPPING_REFERENCE_CLASS); 71 72 OneToOneMapping mapping = initOneToOneMapping(); 74 75 if (m_mappedBy.equals("")) { 76 processOwningMappingKeys(mapping); 78 } else { 79 80 OneToOneMapping ownerMapping = null; 82 if (getOwningMapping().isOneToOneMapping()){ 83 ownerMapping = (OneToOneMapping)getOwningMapping(); 84 }else { 85 getValidator().throwIvalidMappingEncountered(getJavaClass(), getReferenceClass()); 87 } 88 89 mapping.setSourceToTargetKeyFields(ownerMapping.getTargetToSourceKeyFields()); 90 mapping.setTargetToSourceKeyFields(ownerMapping.getSourceToTargetKeyFields()); 91 } 92 93 m_descriptor.addMapping(mapping); 95 } 96 } 97 | Popular Tags |