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 17 18 public class OwnerWidget extends TestObject implements InstanceCallbacks 19 { 20 private Cloneable cloneable; 21 private TestObject testObject; 22 23 24 public OwnerWidget() 25 { 26 cloneable = null; 27 testObject = null; 28 } 29 30 31 public Object clone() 32 { 33 OwnerWidget ow = (OwnerWidget)super.clone(); 34 35 ow.cloneable = (Cloneable )((TestObject)cloneable).clone(); 36 ow.testObject = (TestObject)testObject.clone(); 37 38 return ow; 39 } 40 41 42 public Cloneable getCloneable() 43 { 44 return cloneable; 45 } 46 47 48 public TestObject getTestObject() 49 { 50 return testObject; 51 } 52 53 54 private Widget randomWidget() 55 { 56 Widget obj; 57 58 switch (r.nextInt(4)) 59 { 60 case 0: 61 default: 62 obj = new Widget(); 63 break; 64 65 case 1: 66 obj = new DateWidget(); 67 break; 68 69 case 2: 70 obj = new StringWidget(); 71 break; 72 73 case 3: 74 obj = new BinaryWidget(); 75 break; 76 } 77 78 obj.fillRandom(); 79 80 return obj; 81 } 82 83 84 87 88 public void fillRandom() 89 { 90 PersistenceManager myPM = JDOHelper.getPersistenceManager(this); 91 92 if (myPM != null) 93 { 94 myPM.deletePersistent(cloneable); 95 myPM.deletePersistent(testObject); 96 } 97 98 cloneable = randomWidget(); 99 testObject = randomWidget(); 100 } 101 102 103 114 115 public boolean compareTo(Object obj) 116 { 117 if (obj == this) 118 return true; 119 120 if (!(obj instanceof OwnerWidget)) 121 return false; 122 123 OwnerWidget w = (OwnerWidget)obj; 124 125 return ((TestObject)cloneable).compareTo(w.cloneable) 126 && testObject.compareTo(w.testObject); 127 } 128 129 130 136 137 public String toString() 138 { 139 StringBuffer s = new StringBuffer (super.toString()); 140 141 s.append(" cloneable = ").append(cloneable); 142 s.append('\n'); 143 s.append(" testObject = ").append(testObject); 144 s.append('\n'); 145 146 return s.toString(); 147 } 148 149 150 public void jdoPostLoad() 151 { 152 return; 153 } 154 155 public void jdoPreClear() 156 { 157 return; 158 } 159 160 public void jdoPreDelete() 161 { 162 PersistenceManager myPM = JDOHelper.getPersistenceManager(this); 163 164 myPM.deletePersistent(cloneable); 165 myPM.deletePersistent(testObject); 166 } 167 168 public void jdoPreStore() 169 { 170 return; 171 } 172 } 173 | Popular Tags |