KickJava   Java API By Example, From Geeks To Geeks.

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


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.ManyToOne;
26
27 import org.apache.cayenne.util.TreeNodeChild;
28
29 public class JpaManyToOne extends JpaRelationship {
30
31     protected boolean optional;
32     protected Collection JavaDoc<JpaJoinColumn> joinColumns;
33     protected JpaJoinTable joinTable;
34
35     public JpaManyToOne() {
36
37     }
38
39     public JpaManyToOne(ManyToOne annotation) {
40         if (!Void.TYPE.equals(annotation.targetEntity())) {
41             this.targetEntityName = annotation.targetEntity().getName();
42         }
43
44         for (int i = 0; i < annotation.cascade().length; i++) {
45             if (cascade == null) {
46                 cascade = new JpaCascade();
47             }
48             cascade.getCascades().add(annotation.cascade()[i]);
49         }
50
51         fetch = annotation.fetch();
52         optional = annotation.optional();
53     }
54
55     @Override JavaDoc
56     public boolean isToMany() {
57         return false;
58     }
59
60     public boolean isOptional() {
61         return optional;
62     }
63
64     public void setOptional(boolean optional) {
65         this.optional = optional;
66     }
67
68     @TreeNodeChild(type = JpaJoinColumn.class)
69     public Collection JavaDoc<JpaJoinColumn> getJoinColumns() {
70         if (joinColumns == null) {
71             joinColumns = new ArrayList JavaDoc<JpaJoinColumn>();
72         }
73         return joinColumns;
74     }
75
76     public JpaJoinTable getJoinTable() {
77         return joinTable;
78     }
79
80     public void setJoinTable(JpaJoinTable joinTable) {
81         this.joinTable = joinTable;
82     }
83 }
84
Popular Tags