1 27 28 package org.objectweb.speedo.mim.api; 29 30 34 public abstract class LifeCycle { 35 public static final byte NOT_APPLICABLE = -2; 36 public static final byte ERROR = -1; 37 public static final byte TRANSIENT = 0; 38 public static final byte TRANSIENT_CLEAN = 1; 39 public static final byte TRANSIENT_DIRTY = 2; 40 public static final byte PERSISTENT_NEW = 3; 41 public static final byte PERSISTENT_NONTRANSACTIONAL = 4; 42 public static final byte PERSISTENT_CLEAN = 5; 43 public static final byte PERSISTENT_DIRTY = 6; 44 public static final byte HOLLOW = 7; 45 public static final byte PERSISTENT_DELETED = 8; 46 public static final byte PERSISTENT_NEW_DELETED = 9; 47 48 public static final byte ACTION_MAKEPERSISTENT = 0; 49 public static final byte ACTION_DELETEPERSISTENT = 1; 50 public static final byte ACTION_MAKETRANSACTIONAL = 2; 51 public static final byte ACTION_MAKENONTRANSACTIONAL = 3; 52 public static final byte ACTION_MAKETRANSIENT = 4; 53 public static final byte ACTION_COMMIT = 5; 54 public static final byte ACTION_COMMIT_RETAINVALUES = 6; 55 public static final byte ACTION_ROLLBACK = 7; 56 public static final byte ACTION_ROLLBACK_RETAINVALUES = 8; 57 public static final byte ACTION_REFRESH_ACTIVEDATASTORETRANSACTION = 9; 58 public static final byte ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION = 10; 59 public static final byte ACTION_EVICT = 11; 60 public static final byte ACTION_READFIELD_OUTSIDETRANSACTION = 12; 61 public static final byte ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION = 13; 62 public static final byte ACTION_READFIELD_ACTIVEDATASTORETRANSACTION = 14; 63 public static final byte ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION = 15; 64 public static final byte ACTION_WRITEFIELD_OUTSIDETRANSACTION = 16; 65 66 public static String actionToString(byte action) { 67 switch (action) { 68 case ACTION_MAKEPERSISTENT: 69 return "MAKEPERSISTENT"; 70 case ACTION_MAKETRANSACTIONAL: 71 return "MAKETRANSACTIONAL"; 72 case ACTION_MAKETRANSIENT: 73 return "MAKETRANSIENT"; 74 case ACTION_COMMIT: 75 return "COMMIT"; 76 case ACTION_COMMIT_RETAINVALUES: 77 return "COMMIT_RETAINVALUES"; 78 case ACTION_ROLLBACK: 79 return "ROLLBACK"; 80 case ACTION_ROLLBACK_RETAINVALUES: 81 return "ROLLBACK_RETAINVALUES"; 82 case ACTION_READFIELD_OUTSIDETRANSACTION: 83 return "READFIELD_OUTSIDETRANSACTION"; 84 case ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION: 85 return "READFIELD_ACTIVEOPTIMISTICTRANSACTION"; 86 case ACTION_READFIELD_ACTIVEDATASTORETRANSACTION: 87 return "READFIELD_ACTIVEDATASTORETRANSACTION"; 88 case ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION: 89 return "WRITEFIELD_ACTIVEDATASTORETRANSACTION"; 90 case ACTION_WRITEFIELD_OUTSIDETRANSACTION: 91 return "WRITEFIELD_OUTSIDETRANSACTION"; 92 case ACTION_MAKENONTRANSACTIONAL: 93 return "MAKENONTRANSACTIONAL"; 94 case ACTION_REFRESH_ACTIVEDATASTORETRANSACTION: 95 return "REFRESH_ACTIVEDATASTORETRANSACTION"; 96 case ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION: 97 return "REFRESH_ACTIVEOPTIMISTICTRANSACTION"; 98 case ACTION_EVICT: 99 return "EVICT"; 100 case ACTION_DELETEPERSISTENT: 101 return "DELETEPERSISTENT"; 102 default : return "ERROR"; 103 } 104 } 105 106 public static String statusToString(byte status) { 107 switch (status) { 108 case TRANSIENT: 109 return "TRANSIENT"; 110 case TRANSIENT_CLEAN: 111 return "TRANSIENT_CLEAN"; 112 case TRANSIENT_DIRTY: 113 return "TRANSIENT_DIRTY"; 114 case PERSISTENT_NEW: 115 return "PERSISTENT_NEW"; 116 case PERSISTENT_NONTRANSACTIONAL: 117 return "PERSISTENT_NONTRANSACTIONAL"; 118 case PERSISTENT_CLEAN: 119 return "PERSISTENT_CLEAN"; 120 case PERSISTENT_DIRTY: 121 return "PERSISTENT_DIRTY"; 122 case HOLLOW: 123 return "HOLLOW"; 124 case PERSISTENT_DELETED: 125 return "PERSISTENT_DELETED"; 126 case PERSISTENT_NEW_DELETED: 127 return "PERSISTENT_NEW_DELETED"; 128 case ERROR: 129 default : return "ERROR"; 130 } 131 } 132 133 139 public static byte nextStatePersistenceCapable(byte status, byte action) { 140 switch (status) { 141 case (TRANSIENT): 142 switch (action) { 143 case (ACTION_MAKEPERSISTENT): 144 return PERSISTENT_NEW; 145 case (ACTION_MAKETRANSACTIONAL): 146 return TRANSIENT_CLEAN; 147 case (ACTION_MAKETRANSIENT): 148 case (ACTION_COMMIT): 149 case (ACTION_COMMIT_RETAINVALUES): 150 case (ACTION_ROLLBACK): 151 case (ACTION_ROLLBACK_RETAINVALUES): 152 case (ACTION_READFIELD_OUTSIDETRANSACTION): 153 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 154 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 155 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 156 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 157 return TRANSIENT; 158 case (ACTION_MAKENONTRANSACTIONAL): 159 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 160 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 161 case (ACTION_EVICT): 162 return NOT_APPLICABLE; 163 case (ACTION_DELETEPERSISTENT): 164 default : 165 return ERROR; 166 } 167 case (TRANSIENT_CLEAN): 168 switch (action) { 169 case (ACTION_MAKEPERSISTENT): 170 return PERSISTENT_NEW; 171 case (ACTION_MAKENONTRANSACTIONAL): 172 return TRANSIENT; 173 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 174 return TRANSIENT_DIRTY; 175 case (ACTION_MAKETRANSACTIONAL): 176 case (ACTION_MAKETRANSIENT): 177 case (ACTION_COMMIT): 178 case (ACTION_COMMIT_RETAINVALUES): 179 case (ACTION_ROLLBACK): 180 case (ACTION_ROLLBACK_RETAINVALUES): 181 case (ACTION_EVICT): 182 case (ACTION_READFIELD_OUTSIDETRANSACTION): 183 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 184 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 185 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 186 return TRANSIENT_CLEAN; 187 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 188 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 189 return NOT_APPLICABLE; 190 case (ACTION_DELETEPERSISTENT): 191 default : 192 return ERROR; 193 } 194 case (TRANSIENT_DIRTY): 195 switch (action) { 196 case (ACTION_MAKEPERSISTENT): 197 return PERSISTENT_NEW; 198 case (ACTION_COMMIT): 199 case (ACTION_COMMIT_RETAINVALUES): 200 case (ACTION_ROLLBACK): 201 case (ACTION_ROLLBACK_RETAINVALUES): 202 return TRANSIENT_CLEAN; 203 case (ACTION_MAKETRANSACTIONAL): 204 case (ACTION_MAKETRANSIENT): 205 case (ACTION_EVICT): 206 case (ACTION_READFIELD_OUTSIDETRANSACTION): 207 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 208 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 209 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 210 return TRANSIENT_DIRTY; 211 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 212 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 213 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 214 return NOT_APPLICABLE; 215 case (ACTION_DELETEPERSISTENT): 216 case (ACTION_MAKENONTRANSACTIONAL): 217 default : 218 return ERROR; 219 } 220 case (PERSISTENT_NEW): 221 switch (action) { 222 case (ACTION_DELETEPERSISTENT): 223 return PERSISTENT_NEW_DELETED; 224 case (ACTION_COMMIT): 225 return HOLLOW; 226 case (ACTION_COMMIT_RETAINVALUES): 227 return PERSISTENT_NONTRANSACTIONAL; 228 case (ACTION_ROLLBACK): 229 case (ACTION_ROLLBACK_RETAINVALUES): 230 return TRANSIENT; 231 case (ACTION_MAKEPERSISTENT): 232 case (ACTION_MAKETRANSACTIONAL): 233 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 234 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 235 case (ACTION_EVICT): 236 case (ACTION_READFIELD_OUTSIDETRANSACTION): 237 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 238 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 239 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 240 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 241 return PERSISTENT_NEW; 242 case (ACTION_MAKENONTRANSACTIONAL): 243 return NOT_APPLICABLE; 244 case (ACTION_MAKETRANSIENT): 245 default : 246 return ERROR; 247 } 248 case (PERSISTENT_NONTRANSACTIONAL): 249 switch (action) { 250 case (ACTION_DELETEPERSISTENT): 251 return PERSISTENT_DELETED; 252 case (ACTION_MAKETRANSACTIONAL): 253 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 254 return PERSISTENT_CLEAN; 255 case (ACTION_MAKETRANSIENT): 256 return TRANSIENT; 257 case (ACTION_EVICT): 258 return HOLLOW; 259 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 260 return PERSISTENT_DIRTY; 261 case (ACTION_MAKEPERSISTENT): 262 case (ACTION_MAKENONTRANSACTIONAL): 263 case (ACTION_COMMIT): 264 case (ACTION_COMMIT_RETAINVALUES): 265 case (ACTION_ROLLBACK): 266 case (ACTION_ROLLBACK_RETAINVALUES): 267 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 268 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 269 case (ACTION_READFIELD_OUTSIDETRANSACTION): 270 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 271 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 272 return PERSISTENT_NONTRANSACTIONAL; 273 default : 274 return ERROR; 275 } 276 case (PERSISTENT_CLEAN): 277 switch (action) { 278 case (ACTION_DELETEPERSISTENT): 279 return PERSISTENT_DELETED; 280 case (ACTION_MAKENONTRANSACTIONAL): 281 return PERSISTENT_NONTRANSACTIONAL; 282 case (ACTION_MAKETRANSIENT): 283 return TRANSIENT; 284 case (ACTION_COMMIT): 285 case (ACTION_ROLLBACK): 286 case (ACTION_EVICT): 287 return HOLLOW; 288 case (ACTION_COMMIT_RETAINVALUES): 289 case (ACTION_ROLLBACK_RETAINVALUES): 290 return PERSISTENT_NONTRANSACTIONAL; 291 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 292 return PERSISTENT_DIRTY; 293 case (ACTION_MAKEPERSISTENT): 294 case (ACTION_MAKETRANSACTIONAL): 295 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 296 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 297 case (ACTION_READFIELD_OUTSIDETRANSACTION): 298 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 299 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 300 return PERSISTENT_CLEAN; 301 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 302 return NOT_APPLICABLE; 303 default : 304 return ERROR; 305 } 306 case (PERSISTENT_DIRTY): 307 switch (action) { 308 case (ACTION_DELETEPERSISTENT): 309 return PERSISTENT_DELETED; 310 case (ACTION_COMMIT): 311 case (ACTION_ROLLBACK): 312 return HOLLOW; 313 case (ACTION_COMMIT_RETAINVALUES): 314 case (ACTION_ROLLBACK_RETAINVALUES): 315 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 316 return PERSISTENT_NONTRANSACTIONAL; 317 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 318 return PERSISTENT_CLEAN; 319 case (ACTION_MAKEPERSISTENT): 320 case (ACTION_MAKETRANSACTIONAL): 321 case (ACTION_EVICT): 322 case (ACTION_READFIELD_OUTSIDETRANSACTION): 323 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 324 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 325 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 326 return PERSISTENT_DIRTY; 327 case (ACTION_MAKENONTRANSACTIONAL): 328 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 329 return NOT_APPLICABLE; 330 case (ACTION_MAKETRANSIENT): 331 default : 332 return ERROR; 333 } 334 case (HOLLOW): 335 switch (action) { 336 case (ACTION_DELETEPERSISTENT): 337 return PERSISTENT_DELETED; 338 case (ACTION_MAKETRANSIENT): 339 return TRANSIENT; 340 case (ACTION_READFIELD_OUTSIDETRANSACTION): 341 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 342 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 343 return PERSISTENT_NONTRANSACTIONAL; 344 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 345 return PERSISTENT_CLEAN; 346 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 347 return PERSISTENT_DIRTY; 348 case (ACTION_MAKEPERSISTENT): 349 case (ACTION_MAKETRANSACTIONAL): 350 case (ACTION_MAKENONTRANSACTIONAL): 351 case (ACTION_COMMIT): 352 case (ACTION_COMMIT_RETAINVALUES): 353 case (ACTION_ROLLBACK): 354 case (ACTION_ROLLBACK_RETAINVALUES): 355 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 356 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 357 case (ACTION_EVICT): 358 return HOLLOW; 359 default : 360 return ERROR; 361 } 362 case (PERSISTENT_DELETED): 363 switch (action) { 364 case (ACTION_COMMIT): 365 case (ACTION_COMMIT_RETAINVALUES): 366 return TRANSIENT; 367 case (ACTION_ROLLBACK): 368 return HOLLOW; 369 case (ACTION_ROLLBACK_RETAINVALUES): 370 return PERSISTENT_NONTRANSACTIONAL; 371 case (ACTION_MAKEPERSISTENT): 372 case (ACTION_DELETEPERSISTENT): 373 case (ACTION_MAKETRANSACTIONAL): 374 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 375 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 376 case (ACTION_EVICT): 377 case (ACTION_READFIELD_OUTSIDETRANSACTION): 378 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 379 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 380 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 381 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 382 return PERSISTENT_DELETED; 383 case (ACTION_MAKENONTRANSACTIONAL): 384 case (ACTION_MAKETRANSIENT): 385 default : 386 return ERROR; 387 } 388 case (PERSISTENT_NEW_DELETED): 389 switch (action) { 390 case (ACTION_COMMIT): 391 case (ACTION_COMMIT_RETAINVALUES): 392 case (ACTION_ROLLBACK): 393 case (ACTION_ROLLBACK_RETAINVALUES): 394 return TRANSIENT; 395 case (ACTION_MAKEPERSISTENT): 396 case (ACTION_DELETEPERSISTENT): 397 case (ACTION_MAKETRANSACTIONAL): 398 case (ACTION_REFRESH_ACTIVEDATASTORETRANSACTION): 399 case (ACTION_REFRESH_ACTIVEOPTIMISTICTRANSACTION): 400 case (ACTION_EVICT): 401 case (ACTION_READFIELD_OUTSIDETRANSACTION): 402 case (ACTION_READFIELD_ACTIVEOPTIMISTICTRANSACTION): 403 case (ACTION_READFIELD_ACTIVEDATASTORETRANSACTION): 404 case (ACTION_WRITEFIELD_ACTIVEDATASTORETRANSACTION): 405 case (ACTION_WRITEFIELD_OUTSIDETRANSACTION): 406 return PERSISTENT_NEW_DELETED; 407 case (ACTION_MAKENONTRANSACTIONAL): 408 case (ACTION_MAKETRANSIENT): 409 default : 410 return ERROR; 411 } 412 default : 413 return ERROR; 414 } 415 } 416 417 422 public static byte makeDirty(byte status) { 423 switch (status) { 424 case (TRANSIENT): 425 return TRANSIENT; 426 case (PERSISTENT_NEW): 427 return PERSISTENT_NEW; 428 case (PERSISTENT_CLEAN): 429 case (PERSISTENT_DIRTY): 430 case (HOLLOW): 431 case (PERSISTENT_NONTRANSACTIONAL): 432 return PERSISTENT_DIRTY; 433 case (TRANSIENT_CLEAN): 434 case (TRANSIENT_DIRTY): 435 return TRANSIENT_DIRTY; 436 case (PERSISTENT_NEW_DELETED): 437 return PERSISTENT_NEW_DELETED; 438 case (PERSISTENT_DELETED): 439 return PERSISTENT_DELETED; 440 } 441 return ERROR; 442 } 443 444 450 public static boolean isPersistent(byte status) { 451 return status == PERSISTENT_NEW 452 || status == PERSISTENT_CLEAN 453 || status == PERSISTENT_DIRTY 454 || status == HOLLOW 455 || status == PERSISTENT_NONTRANSACTIONAL 456 || status == PERSISTENT_NEW_DELETED 457 || status == PERSISTENT_DELETED; 458 } 459 460 466 public static boolean isTransactional(byte status) { 467 return status == PERSISTENT_NEW 468 || status == TRANSIENT_CLEAN 469 || status == TRANSIENT_DIRTY 470 || status == PERSISTENT_CLEAN 471 || status == PERSISTENT_DIRTY 472 || status == PERSISTENT_NEW_DELETED 473 || status == PERSISTENT_DELETED; 474 } 475 476 482 public static boolean isNew(byte status) { 483 return status == PERSISTENT_NEW || status == PERSISTENT_NEW_DELETED; 484 } 485 486 492 public static boolean isDirty(byte status) { 493 return status == PERSISTENT_NEW 494 || status == TRANSIENT_DIRTY 495 || status == PERSISTENT_DIRTY 496 || status == PERSISTENT_NEW_DELETED 497 || status == PERSISTENT_DELETED; 498 } 499 500 506 public static boolean isDeleted(byte status) { 507 return status == PERSISTENT_NEW_DELETED || status == PERSISTENT_DELETED; 508 } 509 510 515 public static byte initState() { 516 return TRANSIENT; 517 } 518 519 525 public static boolean isTransient(byte status) { 526 return status == TRANSIENT 527 || status == TRANSIENT_CLEAN 528 || status == TRANSIENT_DIRTY; 529 } 530 } 531 | Popular Tags |