KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > map > JpaOneToOne


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.jpa.map;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import javax.persistence.OneToOne;
26
27 import org.apache.cayenne.util.TreeNodeChild;
28
29 public class JpaOneToOne extends JpaRelationship {
30
31     protected String JavaDoc mappedBy;
32     protected boolean optional;
33
34     protected Collection JavaDoc<JpaPrimaryKeyJoinColumn> primaryKeyJoinColumns;
35     protected Collection JavaDoc<JpaJoinColumn> joinColumns;
36     protected JpaJoinTable joinTable;
37
38     public JpaOneToOne() {
39
40     }
41
42     public JpaOneToOne(OneToOne annotation) {
43         if (!Void.TYPE.equals(annotation.targetEntity())) {
44             this.targetEntityName = annotation.targetEntity().getName();
45         }
46
47         for (int i = 0; i < annotation.cascade().length; i++) {
48             if (cascade == null) {
49                 cascade = new JpaCascade();
50             }
51             cascade.getCascades().add(annotation.cascade()[i]);
52         }
53
54         fetch = annotation.fetch();
55         optional = annotation.optional();
56         mappedBy = annotation.mappedBy();
57     }
58
59     @Override JavaDoc
60     public boolean isToMany() {
61         return false;
62     }
63
64     public boolean isOptional() {
65         return optional;
66     }
67
68     public void setOptional(boolean optional) {
69         this.optional = optional;
70     }
71
72     public String JavaDoc getMappedBy() {
73         return mappedBy;
74     }
75
76     public void setMappedBy(String JavaDoc mappedBy) {
77         this.mappedBy = mappedBy;
78     }
79
80     @TreeNodeChild(type = JpaPrimaryKeyJoinColumn.class)
81     public Collection JavaDoc<JpaPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() {
82         if (primaryKeyJoinColumns == null) {
83             primaryKeyJoinColumns = new ArrayList JavaDoc<JpaPrimaryKeyJoinColumn>();
84         }
85         return primaryKeyJoinColumns;
86     }
87
88     @TreeNodeChild(type = JpaJoinColumn.class)
89     public Collection JavaDoc<JpaJoinColumn> getJoinColumns() {
90         if (joinColumns == null) {
91             joinColumns = new ArrayList JavaDoc<JpaJoinColumn>();
92         }
93         return joinColumns;
94     }
95
96     public JpaJoinTable getJoinTable() {
97         return joinTable;
98     }
99
100     public void setJoinTable(JpaJoinTable joinTable) {
101         this.joinTable = joinTable;
102     }
103 }
104
Popular Tags