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.annotations.common.apps.annotApp.annotype;
020:
021: import java.util.*;
022:
023: import javax.persistence.*;
024:
025: @Entity
026: @Table(name="ANNOTEST2")
027: @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
028: @DiscriminatorColumn(name="ANNOCLS")
029: @DiscriminatorValue("ANNO2")
030: @IdClass(AnnoTest2.Oid.class)
031: public class AnnoTest2 {
032:
033: @Id
034: @Column(name="PK1")
035: protected long pk1;
036:
037: @Id
038: @Column(name="PK2")
039: protected String pk2;
040:
041: @Version
042: @Column(name="ANNOVER")
043: protected Date version;
044:
045: @Basic
046: protected String basic;
047:
048: @OneToOne(fetch=FetchType.LAZY)
049: @JoinColumn(name="INVERSEONEONE_PK",referencedColumnName="PK")
050: protected AnnoTest1 inverseOneOne;
051:
052: @ManyToOne(fetch=FetchType.LAZY)
053: @JoinColumn(name="MANYONEONE_PK",referencedColumnName="PK")
054: protected AnnoTest1 oneManyOwner;
055:
056: @ManyToMany
057: @JoinTable(name="ANNOTEST2_MANYMANY",joinColumns={@JoinColumn(name="MANY_PK1",referencedColumnName="PK1"),@JoinColumn(name="MANY_PK2",referencedColumnName="PK2")},inverseJoinColumns=@JoinColumn(name="MANYE_PK",referencedColumnName="PK"))
058: protected Set<AnnoTest1> manyMany = new HashSet();
059:
060: public AnnoTest2() {
061: }
062:
063: public AnnoTest2(long pk1, String pk2) {
064: this .pk1 = pk1;
065: this .pk2 = pk2;
066: }
067:
068: public void setPk1(long val) {
069: pk1 = val;
070: }
071:
072: public long getPk1() {
073: return pk1;
074: }
075:
076: public void setPk2(String str) {
077: pk2 = str;
078: }
079:
080: public String getPk2() {
081: return pk2;
082: }
083:
084: public Date getVersion() {
085: return version;
086: }
087:
088: public void setBasic(String s) {
089: basic = s;
090: }
091:
092: public String getBasic() {
093: return basic;
094: }
095:
096: public void setInverseOneOne(AnnoTest1 other) {
097: inverseOneOne = other;
098: }
099:
100: public AnnoTest1 getInverseOneOne() {
101: return inverseOneOne;
102: }
103:
104: public void setOneManyOwner(AnnoTest1 other) {
105: oneManyOwner = other;
106: }
107:
108: public AnnoTest1 getOneManyOwner() {
109: return oneManyOwner;
110: }
111:
112: public Set getManyMany() {
113: return manyMany;
114: }
115:
116: public static class Oid {
117:
118: public long pk1;
119: public String pk2;
120:
121: public Oid() {
122: }
123:
124: public Oid(long pk1, String pk2) {
125: this .pk1 = pk1;
126: this .pk2 = pk2;
127: }
128:
129: public Oid(String str) {
130: if (str != null) {
131: int index = str.indexOf(",");
132: pk1 = Long.parseLong(str.substring(0, index));
133: pk2 = str.substring(index + 1);
134: if ("null".equals(pk2))
135: pk2 = null;
136: }
137: }
138:
139: public boolean equals(Object o) {
140: if (o == this )
141: return true;
142: if (!(o instanceof Oid))
143: return false;
144: Oid other = (Oid) o;
145: if (pk1 != other.pk1)
146: return false;
147: if (pk2 == null)
148: return other.pk2 == null;
149: return pk2.equals(other.pk2);
150: }
151:
152: public int hashCode() {
153: return ((int) pk1) + (pk2 == null ? 0 : pk2.hashCode());
154: }
155:
156: public String toString() {
157: return pk1 + "," + (pk2 == null ? "null" : pk2);
158: }
159: }
160: }
|