001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence.kernel.common.apps;
020:
021: import java.io.Serializable;
022: import java.util.ArrayList;
023: import java.util.List;
024: import java.util.StringTokenizer;
025:
026: import javax.persistence.DiscriminatorValue;
027: import javax.persistence.Embedded;
028: import javax.persistence.Entity;
029: import javax.persistence.Id;
030: import javax.persistence.IdClass;
031: import javax.persistence.JoinColumn;
032: import javax.persistence.ManyToOne;
033:
034: import org.apache.openjpa.persistence.FetchAttribute;
035: import org.apache.openjpa.persistence.FetchGroup;
036: import org.apache.openjpa.persistence.FetchGroups;
037: import org.apache.openjpa.persistence.PersistentCollection;
038:
039: @Entity
040: @DiscriminatorValue("ATTACH_F")
041: @IdClass(AttachF.ID.class)
042: @FetchGroups({@FetchGroup(name="all",attributes={@FetchAttribute(name="e",recursionDepth=0),@FetchAttribute(name="strings"),@FetchAttribute(name="embeddedC",recursionDepth=0)})})
043: public class AttachF implements Serializable {
044:
045: @Id
046: private int id1;
047:
048: @Id
049: private String id2;
050:
051: private String fstr;
052: private int fint;
053: private double fdbl;
054:
055: @ManyToOne
056: @JoinColumn(name="ATT_E")
057: private AttachE e;
058:
059: @PersistentCollection
060: private List<String> strings = new ArrayList();
061:
062: @Embedded
063: private AttachC embeddedC;
064:
065: public void setFstr(String fstr) {
066: this .fstr = fstr;
067: }
068:
069: public String getFstr() {
070: return this .fstr;
071: }
072:
073: public void setFint(int fint) {
074: this .fint = fint;
075: }
076:
077: public int getFint() {
078: return this .fint;
079: }
080:
081: public void setFdbl(double fdbl) {
082: this .fdbl = fdbl;
083: }
084:
085: public double getFdbl() {
086: return this .fdbl;
087: }
088:
089: public void setE(AttachE e) {
090: this .e = e;
091: }
092:
093: public AttachE getE() {
094: return this .e;
095: }
096:
097: public void setStrings(List strings) {
098: this .strings = strings;
099: }
100:
101: public List getStrings() {
102: return this .strings;
103: }
104:
105: public static class ID {
106:
107: public int id1;
108: public String id2;
109:
110: public ID() {
111: }
112:
113: public ID(String str) {
114: StringTokenizer tok = new StringTokenizer(str, ":");
115: id1 = Integer.parseInt(tok.nextToken());
116: id2 = tok.nextToken();
117: }
118:
119: @Override
120: public int hashCode() {
121: return id1 + (id2 == null ? 0 : id2.hashCode());
122: }
123:
124: public String toString() {
125: return id1 + ":" + id2;
126: }
127:
128: @Override
129: public boolean equals(Object other) {
130: return other instanceof ID
131: && ((ID) other).id1 == id1
132: && (id2 == null ? ((ID) other).id2 == null : id2
133: .equals(((ID) other).id2));
134: }
135: }
136:
137: public void setId1(int id1) {
138: this .id1 = id1;
139: }
140:
141: public int getId1() {
142: return this .id1;
143: }
144:
145: public void setId2(String id2) {
146: this .id2 = id2;
147: }
148:
149: public String getId2() {
150: return this .id2;
151: }
152:
153: public void setEmbeddedC(AttachC embeddedC) {
154: this .embeddedC = embeddedC;
155: }
156:
157: public AttachC getEmbeddedC() {
158: return this.embeddedC;
159: }
160: }
|