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.jdbc.annotations;
020:
021: import java.util.*;
022:
023: import javax.persistence.*;
024:
025: @Entity
026: // non-psql/ora dbs cause issues with SequenceGenerator in auto-mapping
027: //@SequenceGenerator(name="seq", sequenceName="ejb_sequence")
028: @TableGenerator(name="tab")
029: @IdClass(Generator.Oid.class)
030: public class Generator {
031:
032: @Id
033: protected int pk;
034:
035: @Id
036: @GeneratedValue(strategy=GenerationType.TABLE,generator="tab")
037: protected Integer pk2;
038:
039: @Id
040: @GeneratedValue
041: protected long pk3;
042:
043: @Basic
044: protected String stringField;
045:
046: // for non-seq
047: public void setPk(int pk) {
048: this .pk = pk;
049: }
050:
051: public int getPk() {
052: return pk;
053: }
054:
055: public Integer getPk2() {
056: return pk2;
057: }
058:
059: public long getPk3() {
060: return pk3;
061: }
062:
063: public String getStringField() {
064: return stringField;
065: }
066:
067: public void setStringField(String s) {
068: stringField = s;
069: }
070:
071: public static class Oid {
072:
073: public int pk;
074: public Integer pk2;
075: public long pk3;
076:
077: public Oid() {
078: }
079:
080: public Oid(String str) {
081: StringTokenizer tok = new StringTokenizer(str, ",");
082: pk = Integer.parseInt(tok.nextToken());
083: pk2 = Integer.valueOf(tok.nextToken());
084: pk3 = Long.valueOf(tok.nextToken());
085: }
086:
087: public boolean equals(Object o) {
088: if (o == null || !(o instanceof Oid))
089: return false;
090: Oid other = (Oid) o;
091: if (pk != other.pk)
092: return false;
093: if (pk3 != other.pk3)
094: return false;
095: if (pk2 == null)
096: return other.pk2 == null;
097: return pk2.equals(other.pk2);
098: }
099:
100: public int hashCode() {
101: return pk + (pk2 == null ? 0 : pk2.hashCode())
102: + (int) (pk3 % Integer.MAX_VALUE);
103: }
104:
105: public String toString() {
106: return pk + "," + pk2 + "," + pk3;
107: }
108: }
109: }
|