1 6 7 8 package org.objectweb.speedo.pobjects.tck; 9 10 import java.io.Serializable ; 11 import java.util.ArrayList ; 12 import java.util.Date ; 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 16 import javax.jdo.Extent; 17 import javax.jdo.InstanceCallbacks; 18 import javax.jdo.PersistenceManager; 19 20 class InstanceCallbackNonPersistFdsClass implements InstanceCallbacks { 21 public int i; public char c; double d; short s; HashSet children; Date loadTime; 28 private int keyValue; float floatValue; int intValue; 32 static private int nextKeyValue = 1; 33 34 static int savedIntValue; 35 static float savedFloatValue; 36 37 static Date savedLoadTime; 38 static String member1 = "one"; 39 static String member2 = "two"; 40 static String member3 = "three"; 41 42 static boolean preClearCalled = false; 43 static boolean preStoreCalled = false; 44 static boolean preDeleteCalled = false; 45 static boolean postloadCalled = false; 46 static boolean postloadCalledMultipleTimes = false; 47 48 static int beforeGetObjectById = 1; 50 static int afterGetObjectById = 2; 51 static int savedApplicationStep; 52 static int applicationStep; 54 static ArrayList exceptions = new ArrayList (); 56 static ArrayList callbackCalled = new ArrayList (); 57 static ArrayList attributeOpCausingExceptions = new ArrayList (); 58 59 static void initializeStaticsForTest() 60 { 61 savedIntValue = 0; 62 savedFloatValue = 0.0f; 63 savedLoadTime = null; 64 preClearCalled = false; 65 preStoreCalled = false; 66 preDeleteCalled = false; 67 postloadCalled = false; 68 postloadCalledMultipleTimes = false; 69 savedApplicationStep = 0; 70 applicationStep = 0; 71 72 exceptions = new ArrayList (); 73 callbackCalled = new ArrayList (); 74 attributeOpCausingExceptions = new ArrayList (); 75 } 76 77 static void removeAllInstances(PersistenceManager pm) 78 { 79 Extent e = pm.getExtent(org.objectweb.speedo.pobjects.tck.InstanceCallbackNonPersistFdsClass.class, true); 80 Iterator it = e.iterator(); 81 while( it.hasNext() ){ 82 pm.deletePersistent(it.next()); 83 } 84 } 85 86 InstanceCallbackNonPersistFdsClass() 87 { 88 } 89 90 InstanceCallbackNonPersistFdsClass(float floatValue,int intValue) { 91 keyValue = nextKeyValue++; 92 this.floatValue = floatValue; 93 this.intValue = intValue; 94 } 95 96 void setNonPersist(int i, char c, double d, short s) { 97 this.i = i; 98 this.c = c; 99 this.d = d; 100 this.s = s; 101 } 102 void setNonManaged(int i, char c) { 103 this.i = i; 104 this.c = c; 105 } 106 107 int calcIntValue() { 108 return i * c; 109 } 110 111 float calcFloatValue () { 112 return (float)(d * s); 113 } 114 115 void incrementIntValue() { 116 intValue++; 117 } 118 119 public void jdoPreStore() { 120 preStoreCalled = true; 121 intValue = calcIntValue(); 122 floatValue = calcFloatValue(); 123 124 try { 125 i = -30; 126 }catch(Exception e) { 127 callbackCalled.add("jdoPreStore "); 128 exceptions.add(e); 129 attributeOpCausingExceptions.add("i = -30;"); 130 } 131 try { 132 c = '\u0000'; 133 }catch(Exception e) { 134 callbackCalled.add("jdoPreStore "); 135 exceptions.add(e); 136 attributeOpCausingExceptions.add("c = '\u0000';"); 137 } 138 try { 139 d = 362.5; 140 }catch(Exception e) { 141 callbackCalled.add("jdoPreStore "); 142 exceptions.add(e); 143 attributeOpCausingExceptions.add("d = 362.5;"); 144 } 145 try { 146 s = 0; 147 }catch(Exception e) { 148 callbackCalled.add("jdoPreStore "); 149 exceptions.add(e); 150 attributeOpCausingExceptions.add("s = 0;"); 151 } 152 try { 153 loadTime = null; 154 }catch(Exception e) { 155 callbackCalled.add("jdoPreStore "); 156 exceptions.add(e); 157 attributeOpCausingExceptions.add("loadTime = null;"); 158 } 159 try { 160 children = null; 161 }catch(Exception e) { 162 callbackCalled.add("jdoPreStore "); 163 exceptions.add(e); 164 attributeOpCausingExceptions.add("children = null;"); 165 } 166 } 167 168 public void jdoPreDelete() { 169 preDeleteCalled = true; 170 try { 171 i = 0; 172 }catch(Exception e) { 173 callbackCalled.add("jdoPreDelete "); 174 exceptions.add(e); 175 attributeOpCausingExceptions.add("i = 0;"); 176 } 177 try { 178 c = 'x'; 179 }catch(Exception e) { 180 callbackCalled.add("jdoPreDelete "); 181 exceptions.add(e); 182 attributeOpCausingExceptions.add("c = 'x';"); 183 } 184 try { 185 d = 0.0; 186 }catch(Exception e) { 187 callbackCalled.add("jdoPreDelete "); 188 exceptions.add(e); 189 attributeOpCausingExceptions.add("d = 0.0;"); 190 } 191 try { 192 s = -5; 193 }catch(Exception e) { 194 callbackCalled.add("jdoPreDelete "); 195 exceptions.add(e); 196 attributeOpCausingExceptions.add("s = -5;"); 197 } 198 try { 199 loadTime = null; 200 }catch(Exception e) { 201 callbackCalled.add("jdoPreDelete "); 202 exceptions.add(e); 203 attributeOpCausingExceptions.add("loadTime = null;"); 204 } 205 try { 206 children = null; 207 }catch(Exception e) { 208 callbackCalled.add("jdoPreDelete "); 209 exceptions.add(e); 210 attributeOpCausingExceptions.add("children = null;"); 211 } 212 } 213 214 public void jdoPostLoad() { 215 postloadCalled = true; 216 savedApplicationStep = applicationStep; 217 i = -10; 218 c = '2'; 219 d = 30.0; 220 s = 40; 221 savedIntValue = intValue; 222 savedFloatValue = floatValue; 223 loadTime = new Date (); 224 savedLoadTime = loadTime; 225 children = new HashSet (); 226 children.add(member1); 227 children.add(member2); 228 children.add(member3); 229 } 230 231 public void jdoPreClear() { 232 preClearCalled = true; 233 try { 234 i = 1; 235 }catch(Exception e) { 236 callbackCalled.add("jdoPreClear "); 237 exceptions.add(e); 238 attributeOpCausingExceptions.add("i = 1;"); 239 } 240 try { 241 c = '2'; 242 }catch(Exception e) { 243 callbackCalled.add("jdoPreClear "); 244 exceptions.add(e); 245 attributeOpCausingExceptions.add("c = '2';"); 246 } 247 try { 248 d = 3.0; 249 }catch(Exception e) { 250 callbackCalled.add("jdoPreClear "); 251 exceptions.add(e); 252 attributeOpCausingExceptions.add("d = 3.0;"); 253 } 254 try { 255 s = 4; 256 }catch(Exception e) { 257 callbackCalled.add("jdoPreClear "); 258 exceptions.add(e); 259 attributeOpCausingExceptions.add("s = 4;"); 260 } 261 try { 262 loadTime = null; 263 }catch(Exception e) { 264 callbackCalled.add("jdoPreClear "); 265 exceptions.add(e); 266 attributeOpCausingExceptions.add("loadTime = null;"); 267 } 268 try { 269 children = null; 270 }catch(Exception e) { 271 callbackCalled.add("jdoPreClear "); 272 exceptions.add(e); 273 attributeOpCausingExceptions.add("children = null;"); 274 } 275 } 276 277 public static class KeyClass implements Serializable { 278 public int keyValue; 279 280 public KeyClass() { 281 } 282 283 public KeyClass(String s) { 284 try{ keyValue = Integer.parseInt(s);} 285 catch(NumberFormatException e){ 286 keyValue = 0;} 287 } 288 289 public boolean equals(Object obj) { 290 if( obj == null || !this.getClass().equals(obj.getClass()) ) return false; 291 else return keyValue == ((KeyClass)obj).keyValue; 292 } 293 294 public int hashCode() { 295 return keyValue; 296 } 297 298 public String toString() { 299 return Integer.toString(keyValue); 300 } 301 } 302 } 303 | Popular Tags |