KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > accessors > OneToOneAccessor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
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 /**
31  * A one to one relationship accessor.
32  *
33  * @author Guy Pelletier
34  * @since TopLink EJB 3.0 Reference Implementation
35  */

36 public class OneToOneAccessor extends ObjectAccessor {
37     /**
38      * INTERNAL:
39      */

40     public OneToOneAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) {
41         super(accessibleObject, classAccessor);
42         
43         // Process the annotation specifics if there is one, otherwise the
44
// defaults use the defaults which are initialized in the super class.
45
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     /**
57      * INTERNAL:
58      */

59     public boolean isOneToOne() {
60         return true;
61     }
62     
63     /**
64      * INTERNAL:
65      * Process a @OneToOne or one-to-one element into a TopLink OneToOne
66      * mapping.
67      */

68     public void process() {
69         // Figure out the referenceClass and set it on the mapping.
70
setReferenceClass(getTargetEntity(), m_logger.ONE_TO_ONE_MAPPING_REFERENCE_CLASS);
71         
72         // Initialize our mapping now with what we found.
73
OneToOneMapping mapping = initOneToOneMapping();
74         
75         if (m_mappedBy.equals("")) {
76             // Owning side, look for JoinColumns or PrimaryKeyJoinColumns.
77
processOwningMappingKeys(mapping);
78         } else {
79             
80             // Non-owning side, process the foreign keys from the owner.
81
OneToOneMapping ownerMapping = null;
82             if (getOwningMapping().isOneToOneMapping()){
83                 ownerMapping = (OneToOneMapping)getOwningMapping();
84             }else {
85                 //gf730 - If improper mapping encountered, throw an exception
86
getValidator().throwIvalidMappingEncountered(getJavaClass(), getReferenceClass());
87             }
88
89             mapping.setSourceToTargetKeyFields(ownerMapping.getTargetToSourceKeyFields());
90             mapping.setTargetToSourceKeyFields(ownerMapping.getSourceToTargetKeyFields());
91         }
92         
93         // Add the mapping to the descriptor.
94
m_descriptor.addMapping(mapping);
95     }
96 }
97
Popular Tags