001: /**
002: * Copyright 2002 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: InverseMapValue.java,v 1.3 2002/10/17 21:00:59 pierreg0 Exp $
009: */package com.triactive.jdo.test;
010:
011: import javax.jdo.InstanceCallbacks;
012: import javax.jdo.JDOHelper;
013: import javax.jdo.PersistenceManager;
014: import junit.framework.Assert;
015:
016: class InverseMapValue extends TestObject implements InstanceCallbacks {
017: private InverseMapFieldTester owner;
018: private String key;
019: private String strField;
020: private Object objField;
021:
022: /**
023: * Default constructor required since this is a PersistenceCapable class.
024: */
025: protected InverseMapValue() {
026: }
027:
028: public InverseMapValue(String key) {
029: this .owner = null;
030: this .key = key;
031: this .strField = null;
032: this .objField = null;
033: }
034:
035: public void setOwner(InverseMapFieldTester owner) {
036: this .owner = owner;
037: }
038:
039: public InverseMapFieldTester getOwner() {
040: return owner;
041: }
042:
043: public String getKey() {
044: return key;
045: }
046:
047: public void fillRandom() {
048: jdoPreDelete();
049:
050: strField = nextNull() ? null : nextString(r.nextInt(21));
051:
052: if (nextNull())
053: objField = null;
054: else {
055: Widget w = new Widget();
056: w.fillRandom();
057: objField = w;
058: }
059:
060: }
061:
062: public boolean compareTo(Object obj) {
063: if (obj == this )
064: return true;
065:
066: if (!(obj instanceof InverseMapValue))
067: return false;
068:
069: InverseMapValue imv = (InverseMapValue) obj;
070:
071: return (owner == null ? imv.owner == null : owner
072: .equals(imv.owner))
073: && key.equals(imv.key)
074: && (strField == null ? imv.strField == null : strField
075: .equals(imv.strField))
076: && (objField == null ? imv.objField == null : objField
077: .equals(imv.objField));
078: }
079:
080: public void assertEquals(InverseMapValue imv) {
081: Assert.assertEquals(key, imv.key);
082: Assert.assertEquals(strField, imv.strField);
083: Assert.assertEquals(objField, imv.objField);
084: }
085:
086: public String toString() {
087: StringBuffer s = new StringBuffer(super .toString());
088:
089: s.append(" owner = ").append(JDOHelper.getObjectId(owner));
090: s.append('\n');
091: s.append(" key = ").append(key);
092: s.append('\n');
093: s.append(" strField = ").append(strField);
094: s.append('\n');
095: s.append(" objField = ").append(objField);
096: s.append('\n');
097:
098: return s.toString();
099: }
100:
101: public void jdoPostLoad() {
102: }
103:
104: public void jdoPreStore() {
105: }
106:
107: public void jdoPreClear() {
108: }
109:
110: public void jdoPreDelete() {
111: PersistenceManager pm = JDOHelper.getPersistenceManager(this);
112:
113: if (pm != null) {
114: if (objField != null)
115: pm.deletePersistent(objField);
116: }
117: }
118: }
|