1 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 key; 22 private String strField; 23 private Object objField; 24 25 28 protected InverseMapValue() {} 29 30 public InverseMapValue(String 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 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 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 toString() 101 { 102 StringBuffer s = new StringBuffer (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 |