001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.fkstackoverflow.ejb;
023:
024: /**
025: * Primary key for ComplexParent.
026: */
027: public class ComplexParentPK extends Object implements
028: java.io.Serializable {
029: private int _hashCode = 0;
030: private StringBuffer _toStringValue = null;
031:
032: public Long id1;
033: public Long id2;
034:
035: public ComplexParentPK() {
036: }
037:
038: public ComplexParentPK(Long id1, Long id2) {
039: this .id1 = id1;
040: this .id2 = id2;
041: }
042:
043: public Long getId1() {
044: return id1;
045: }
046:
047: public Long getId2() {
048: return id2;
049: }
050:
051: public void setId1(Long id1) {
052: this .id1 = id1;
053: _hashCode = 0;
054: }
055:
056: public void setId2(Long id2) {
057: this .id2 = id2;
058: _hashCode = 0;
059: }
060:
061: public int hashCode() {
062: if (_hashCode == 0) {
063: if (this .id1 != null)
064: _hashCode += this .id1.hashCode();
065: if (this .id2 != null)
066: _hashCode += this .id2.hashCode();
067: }
068:
069: return _hashCode;
070: }
071:
072: public boolean equals(Object obj) {
073: if (!(obj instanceof ComplexParentPK))
074: return false;
075:
076: ComplexParentPK pk = (ComplexParentPK) obj;
077: boolean eq = true;
078:
079: if (obj == null) {
080: eq = false;
081: } else {
082: if (this .id1 == null
083: && ((ComplexParentPK) obj).getId1() == null) {
084: eq = true;
085: } else {
086: if (this .id1 == null
087: || ((ComplexParentPK) obj).getId1() == null) {
088: eq = false;
089: } else {
090: eq = eq && this .id1.equals(pk.id1);
091: }
092: }
093: if (this .id2 == null
094: && ((ComplexParentPK) obj).getId2() == null) {
095: eq = true;
096: } else {
097: if (this .id2 == null
098: || ((ComplexParentPK) obj).getId2() == null) {
099: eq = false;
100: } else {
101: eq = eq && this .id2.equals(pk.id2);
102: }
103: }
104: }
105:
106: return eq;
107: }
108:
109: /** @return String representation of this pk in the form of [.field1.field2.field3]. */
110: public String toString() {
111: if (_toStringValue == null) {
112: _toStringValue = new StringBuffer("[.");
113: _toStringValue.append(this .id1).append('.');
114: _toStringValue.append(this .id2).append('.');
115: _toStringValue.append(']');
116: }
117:
118: return _toStringValue.toString();
119: }
120:
121: }
|