KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > test > InverseMapValue


1 /**
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: InverseMapValue.java,v 1.3 2002/10/17 21:00:59 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.test;
12
13 import javax.jdo.InstanceCallbacks;
14 import javax.jdo.JDOHelper;
15 import javax.jdo.PersistenceManager;
16 import junit.framework.Assert;
17
18 class InverseMapValue extends TestObject implements InstanceCallbacks
19 {
20     private InverseMapFieldTester owner;
21     private String JavaDoc key;
22     private String JavaDoc strField;
23     private Object JavaDoc objField;
24
25     /**
26      * Default constructor required since this is a PersistenceCapable class.
27      */

28     protected InverseMapValue() {}
29
30     public InverseMapValue(String JavaDoc key)
31     {
32         this.owner = null;
33         this.key = key;
34         this.strField = null;
35         this.objField = null;
36     }
37
38
39     public void setOwner(InverseMapFieldTester owner)
40     {
41         this.owner = owner;
42     }
43
44
45     public InverseMapFieldTester getOwner()
46     {
47         return owner;
48     }
49
50
51     public String JavaDoc getKey()
52     {
53         return key;
54     }
55
56
57     public void fillRandom()
58     {
59         jdoPreDelete();
60
61         strField = nextNull() ? null : nextString(r.nextInt(21));
62
63         if (nextNull())
64             objField = null;
65         else
66         {
67             Widget w = new Widget();
68             w.fillRandom();
69             objField = w;
70         }
71
72     }
73
74
75     public boolean compareTo(Object JavaDoc obj)
76     {
77         if (obj == this)
78             return true;
79
80         if (!(obj instanceof InverseMapValue))
81             return false;
82
83         InverseMapValue imv = (InverseMapValue)obj;
84
85         return (owner == null ? imv.owner == null : owner.equals(imv.owner))
86             && key.equals(imv.key)
87             && (strField == null ? imv.strField == null : strField.equals(imv.strField))
88             && (objField == null ? imv.objField == null : objField.equals(imv.objField));
89     }
90
91
92     public void assertEquals(InverseMapValue imv)
93     {
94         Assert.assertEquals(key, imv.key);
95         Assert.assertEquals(strField, imv.strField);
96         Assert.assertEquals(objField, imv.objField);
97     }
98
99
100     public String JavaDoc toString()
101     {
102         StringBuffer JavaDoc s = new StringBuffer JavaDoc(super.toString());
103
104         s.append(" owner = ").append(JDOHelper.getObjectId(owner));
105         s.append('\n');
106         s.append(" key = ").append(key);
107         s.append('\n');
108         s.append(" strField = ").append(strField);
109         s.append('\n');
110         s.append(" objField = ").append(objField);
111         s.append('\n');
112
113         return s.toString();
114     }
115
116     public void jdoPostLoad() {}
117
118     public void jdoPreStore() {}
119
120     public void jdoPreClear() {}
121
122     public void jdoPreDelete()
123     {
124         PersistenceManager pm = JDOHelper.getPersistenceManager(this);
125
126         if (pm != null)
127         {
128             if (objField != null)
129                 pm.deletePersistent(objField);
130         }
131     }
132 }
133
Popular Tags