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 javax.persistence.Entity;
023: import javax.persistence.Id;
024: import javax.persistence.IdClass;
025: import javax.persistence.Table;
026:
027: @Entity
028: @Table(name="aimplb")
029: @IdClass(AImplB.Idkey.class)
030: public class AImplB implements AIntf {
031:
032: private String name;
033: @Id
034: private int pk1;
035: @Id
036: private String pk2;
037:
038: protected AImplB() {
039: }
040:
041: public AImplB(String name, int pk1, String pk2) {
042: setName(name);
043: this .pk1 = pk1;
044: this .pk2 = pk2;
045: }
046:
047: public void setName(String name) {
048: this .name = name;
049: }
050:
051: public String getName() {
052: return this .name;
053: }
054:
055: public void setPK1(int pk1) {
056: this .pk1 = pk1;
057: }
058:
059: public int getPK1() {
060: return this .pk1;
061: }
062:
063: public void setPK2(String pk2) {
064: this .pk2 = pk2;
065: }
066:
067: public String getPK2() {
068: return this .pk2;
069: }
070:
071: public static class Idkey implements Serializable {
072:
073: public int pk1;
074: public String pk2;
075:
076: public Idkey() {
077: }
078:
079: public Idkey(String str) {
080: int index = str.indexOf("/");
081: if (index != -1) {
082: pk1 = Integer.parseInt(str.substring(0, index));
083: pk2 = str.substring(index + 1);
084: }
085: }
086:
087: public String toString() {
088: return pk1 + "/" + pk2;
089: }
090:
091: @Override
092: public boolean equals(Object other) {
093: if (!(other instanceof Idkey))
094: return false;
095:
096: Idkey id = (Idkey) other;
097: if (pk2 == null && id.pk2 != null)
098: return false;
099: if (pk2 != null && id.pk2 == null)
100: return false;
101: if (!(pk1 == id.pk1))
102: return false;
103: if (!(pk2.equals(id.pk2)))
104: return false;
105:
106: return true;
107: }
108:
109: @Override
110: public int hashCode() {
111: return (pk1 + pk2).hashCode();
112: }
113: }
114: }
|