001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.jee.jpa;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020: import javax.xml.bind.annotation.XmlAccessType;
021: import javax.xml.bind.annotation.XmlAccessorType;
022: import javax.xml.bind.annotation.XmlAttribute;
023: import javax.xml.bind.annotation.XmlElement;
024: import javax.xml.bind.annotation.XmlType;
025: import javax.xml.bind.annotation.XmlTransient;
026:
027: /**
028: *
029: *
030: * @Target({METHOD, FIELD}) @Retention(RUNTIME)
031: * public @interface ManyToOne {
032: * Class targetEntity() default void.class;
033: * CascadeType[] cascade() default {};
034: * FetchType fetch() default EAGER;
035: * boolean optional() default true;
036: * }
037: *
038: *
039: *
040: * <p>Java class for many-to-one complex type.
041: *
042: * <p>The following schema fragment specifies the expected content contained within this class.
043: *
044: * <pre>
045: * <complexType name="many-to-one">
046: * <complexContent>
047: * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
048: * <sequence>
049: * <choice>
050: * <element name="join-column" type="{http://java.sun.com/xml/ns/persistence/orm}join-column" maxOccurs="unbounded" minOccurs="0"/>
051: * <element name="join-table" type="{http://java.sun.com/xml/ns/persistence/orm}join-table" minOccurs="0"/>
052: * </choice>
053: * <element name="cascade" type="{http://java.sun.com/xml/ns/persistence/orm}cascade-type" minOccurs="0"/>
054: * </sequence>
055: * <attribute name="fetch" type="{http://java.sun.com/xml/ns/persistence/orm}fetch-type" />
056: * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
057: * <attribute name="optional" type="{http://www.w3.org/2001/XMLSchema}boolean" />
058: * <attribute name="target-entity" type="{http://www.w3.org/2001/XMLSchema}string" />
059: * </restriction>
060: * </complexContent>
061: * </complexType>
062: * </pre>
063: *
064: *
065: */
066: @XmlAccessorType(XmlAccessType.FIELD)
067: @XmlType(name="many-to-one",propOrder={"joinColumn","joinTable","cascade"})
068: public class ManyToOne implements RelationField {
069:
070: @XmlElement(name="join-column")
071: protected List<JoinColumn> joinColumn;
072: @XmlElement(name="join-table")
073: protected JoinTable joinTable;
074: protected CascadeType cascade;
075: @XmlAttribute
076: protected FetchType fetch;
077: @XmlAttribute(required=true)
078: protected String name;
079: @XmlAttribute
080: protected Boolean optional;
081: @XmlAttribute(name="target-entity")
082: protected String targetEntity;
083: @XmlTransient
084: protected RelationField relatedField;
085: @XmlTransient
086: protected boolean syntheticField;
087:
088: /**
089: * Gets the value of the joinColumn property.
090: *
091: * <p>
092: * This accessor method returns a reference to the live list,
093: * not a snapshot. Therefore any modification you make to the
094: * returned list will be present inside the JAXB object.
095: * This is why there is not a <CODE>set</CODE> method for the joinColumn property.
096: *
097: * <p>
098: * For example, to add a new item, do as follows:
099: * <pre>
100: * getJoinColumn().add(newItem);
101: * </pre>
102: *
103: *
104: * <p>
105: * Objects of the following type(s) are allowed in the list
106: * {@link JoinColumn }
107: *
108: *
109: */
110: public List<JoinColumn> getJoinColumn() {
111: if (joinColumn == null) {
112: joinColumn = new ArrayList<JoinColumn>();
113: }
114: return this .joinColumn;
115: }
116:
117: /**
118: * Gets the value of the joinTable property.
119: *
120: * @return
121: * possible object is
122: * {@link JoinTable }
123: *
124: */
125: public JoinTable getJoinTable() {
126: return joinTable;
127: }
128:
129: /**
130: * Sets the value of the joinTable property.
131: *
132: * @param value
133: * allowed object is
134: * {@link JoinTable }
135: *
136: */
137: public void setJoinTable(JoinTable value) {
138: this .joinTable = value;
139: }
140:
141: /**
142: * Gets the value of the cascade property.
143: *
144: * @return
145: * possible object is
146: * {@link CascadeType }
147: *
148: */
149: public CascadeType getCascade() {
150: return cascade;
151: }
152:
153: /**
154: * Sets the value of the cascade property.
155: *
156: * @param value
157: * allowed object is
158: * {@link CascadeType }
159: *
160: */
161: public void setCascade(CascadeType value) {
162: this .cascade = value;
163: }
164:
165: /**
166: * Gets the value of the fetch property.
167: *
168: * @return
169: * possible object is
170: * {@link FetchType }
171: *
172: */
173: public FetchType getFetch() {
174: return fetch;
175: }
176:
177: /**
178: * Sets the value of the fetch property.
179: *
180: * @param value
181: * allowed object is
182: * {@link FetchType }
183: *
184: */
185: public void setFetch(FetchType value) {
186: this .fetch = value;
187: }
188:
189: /**
190: * Gets the value of the name property.
191: *
192: * @return
193: * possible object is
194: * {@link String }
195: *
196: */
197: public String getName() {
198: return name;
199: }
200:
201: /**
202: * Sets the value of the name property.
203: *
204: * @param value
205: * allowed object is
206: * {@link String }
207: *
208: */
209: public void setName(String value) {
210: this .name = value;
211: }
212:
213: /**
214: * Gets the value of the optional property.
215: *
216: * @return
217: * possible object is
218: * {@link Boolean }
219: *
220: */
221: public Boolean isOptional() {
222: return optional;
223: }
224:
225: /**
226: * Sets the value of the optional property.
227: *
228: * @param value
229: * allowed object is
230: * {@link Boolean }
231: *
232: */
233: public void setOptional(Boolean value) {
234: this .optional = value;
235: }
236:
237: /**
238: * Gets the value of the targetEntity property.
239: *
240: * @return
241: * possible object is
242: * {@link String }
243: *
244: */
245: public String getTargetEntity() {
246: return targetEntity;
247: }
248:
249: /**
250: * Sets the value of the targetEntity property.
251: *
252: * @param value
253: * allowed object is
254: * {@link String }
255: *
256: */
257: public void setTargetEntity(String value) {
258: this .targetEntity = value;
259: }
260:
261: public String getMappedBy() {
262: throw new UnsupportedOperationException(
263: "Many to one element can not have mapped-by");
264: }
265:
266: public void setMappedBy(String value) {
267: throw new UnsupportedOperationException(
268: "Many to one element can not have mapped-by");
269: }
270:
271: /**
272: * This is only used for xml converters and will normally return null.
273: * Gets the field on the target entity for this relationship.
274: * @return the field on the target entity for this relationship.
275: */
276: public RelationField getRelatedField() {
277: return relatedField;
278: }
279:
280: /**
281: * Gets the field on the target entity for this relationship.
282: * @param value field on the target entity for this relationship.
283: */
284: public void setRelatedField(RelationField value) {
285: this .relatedField = value;
286: }
287:
288: /**
289: * This is only used for xml converters and will normally return false.
290: * A true value indicates that this field was generated for CMR back references.
291: * @return true if this field was generated for CMR back references.
292: */
293: public boolean isSyntheticField() {
294: return syntheticField;
295: }
296:
297: /**
298: * This is only used for xml converters and will normally return false.
299: * A true value indicates that this field was generated for CMR back references.
300: * @return true if this field was generated for CMR back references.
301: */
302: public void setSyntheticField(boolean syntheticField) {
303: this.syntheticField = syntheticField;
304: }
305: }
|