01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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: package org.apache.openjpa.persistence.kernel.common.apps;
20:
21: import javax.persistence.CascadeType;
22: import javax.persistence.Entity;
23: import javax.persistence.FetchType;
24: import javax.persistence.ManyToOne;
25:
26: import org.apache.openjpa.persistence.FetchAttribute;
27: import org.apache.openjpa.persistence.FetchGroup;
28:
29: /**
30: * @author <A HREF="mailto:pinaki.poddar@gmail.com>Pinaki Poddar</A>
31: */
32: @Entity
33: @FetchGroup(name="address.country",attributes=@FetchAttribute(name="country"))
34: public class PCAddress {
35:
36: private String street;
37: private String city;
38:
39: @ManyToOne(fetch=FetchType.LAZY,cascade=CascadeType.PERSIST)
40: private PCCountry country;
41:
42: protected PCAddress() {
43: super ();
44: }
45:
46: public PCAddress(String street, String city, PCCountry country) {
47: setStreet(street);
48: setCity(city);
49: setCountry(country);
50: }
51:
52: public String getCity() {
53: return city;
54: }
55:
56: public void setCity(String city) {
57: this .city = city;
58: }
59:
60: public PCCountry getCountry() {
61: return country;
62: }
63:
64: public void setCountry(PCCountry country) {
65: this .country = country;
66: }
67:
68: public String getStreet() {
69: return street;
70: }
71:
72: public void setStreet(String street) {
73: this .street = street;
74: }
75:
76: public static Object reflect(PCAddress instance, String name) {
77: if (instance == null)
78: return null;
79: try {
80: return PCAddress.class.getDeclaredField(name).get(instance);
81: } catch (Exception e) {
82: throw new RuntimeException(e);
83: }
84: }
85: }
|