1 23 24 27 28 package com.sun.jdo.spi.persistence.support.sqlstore.state; 29 30 import com.sun.jdo.api.persistence.support.JDOUserException; 31 import com.sun.jdo.spi.persistence.utility.I18NHelper; 32 import com.sun.jdo.spi.persistence.utility.logging.Logger; 33 import com.sun.jdo.spi.persistence.support.sqlstore.LogHelperStateManager; 34 35 import java.util.ResourceBundle ; 36 37 38 public abstract class LifeCycleState { 39 40 43 protected final static ResourceBundle messages = I18NHelper.loadBundle( 44 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", LifeCycleState.class.getClassLoader()); 46 47 protected boolean isPersistent; 48 protected boolean isAutoPersistent; 49 protected boolean isPersistentInDataStore; 50 protected boolean isTransactional; 51 protected boolean isDirty; 52 protected boolean isNew; 53 protected boolean isDeleted; 54 protected boolean isFlushed; 55 protected boolean isNavigable; 56 protected boolean isRefreshable; 57 protected boolean isBeforeImageUpdatable; 58 59 protected boolean needsRegister; 61 62 protected boolean needsReload; 64 65 protected boolean needsRestoreOnRollback; 68 69 70 protected boolean needMerge = true; 72 73 protected int updateAction; 74 protected int stateType; 75 76 77 80 final static protected int 81 NO_OP = 0, 82 INSERT_OP = 1, 83 UPDATE_OP = 2, 84 DELETE_OP = 3; 85 86 89 final static public int 90 HOLLOW = 0, 91 P_NON_TX = 1, 92 P_CLEAN = 2, 93 P_DIRTY = 3, 94 P_NEW = 4, 95 P_NEW_FLUSHED = 5, 96 P_NEW_FLUSHED_DELETED = 6, 97 P_NEW_DELETED = 7, 98 P_DELETED = 8, 99 P_DELETED_FLUSHED = 9, 100 AP_NEW = 10, 101 AP_NEW_PENDING = 11, 102 AP_NEW_FLUSHED = 12, 103 AP_NEW_FLUSHED_PENDING = 13, 104 AP_NEW_FLUSHED_DELETED = 14, 105 AP_NEW_DELETED = 15, 106 TRANSIENT = 16, 107 TOTAL = 17; 108 109 private static LifeCycleState stateTypes[]; 110 111 private static Logger logger = LogHelperStateManager.getLogger(); 113 114 118 122 static { 123 initLifeCycleState(); 124 } 125 126 129 130 133 136 protected static void initLifeCycleState() { 137 stateTypes = new LifeCycleState[TOTAL]; 138 stateTypes[HOLLOW] = new Hollow(); 139 stateTypes[P_NON_TX] = new PersistentNonTransactional(); 140 stateTypes[P_CLEAN] = new PersistentClean(); 141 stateTypes[P_DIRTY] = new PersistentDirty(); 142 stateTypes[P_NEW] = new PersistentNew(); 143 stateTypes[P_NEW_FLUSHED] = new PersistentNewFlushed(); 144 stateTypes[P_NEW_DELETED] = new PersistentNewDeleted(); 145 stateTypes[P_NEW_FLUSHED_DELETED] = new PersistentNewFlushedDeleted(); 146 stateTypes[P_DELETED] = new PersistentDeleted(); 147 stateTypes[P_DELETED_FLUSHED] = new PersistentDeletedFlushed(); 148 stateTypes[AP_NEW] = new AutoPersistentNew(); 149 stateTypes[AP_NEW_PENDING] = new AutoPersistentNewPending(); 150 stateTypes[AP_NEW_FLUSHED] = new AutoPersistentNewFlushed(); 151 stateTypes[AP_NEW_FLUSHED_PENDING] = new AutoPersistentNewFlushedPending(); 152 stateTypes[AP_NEW_FLUSHED_DELETED] = new AutoPersistentNewFlushedDeleted(); 153 stateTypes[AP_NEW_DELETED] = new AutoPersistentNewDeleted(); 154 stateTypes[TRANSIENT] = null; 155 } 156 157 185 186 187 193 public static LifeCycleState getLifeCycleState(int state) { 194 if (logger.isLoggable(Logger.FINER)) { 195 logger.finer("sqlstore.state.lifecyclestate.initial",stateTypes[state]); } 197 198 return stateTypes[state]; 199 } 200 201 207 public int stateType() { 208 return stateType; 209 } 210 211 212 public LifeCycleState transitionMakePersistent() { 213 return this; 214 } 215 216 public LifeCycleState transitionDeletePersistent() { 217 return this; 218 } 219 220 public LifeCycleState transitionRefreshPersistent() { 221 return this; 222 } 223 224 public LifeCycleState transitionReload(boolean transactionActive) { 225 return this; 226 } 227 228 public LifeCycleState transitionCommit(boolean retainValues) { 229 return this; 230 } 231 232 public LifeCycleState transitionRollback(boolean retainValues) { 233 return this; 234 } 235 236 public LifeCycleState transitionFlushed() { 237 return this; 238 } 239 240 public LifeCycleState transitionMakePending() { 241 return this; 242 } 243 244 public LifeCycleState transitionReadField(boolean optimisitic, 245 boolean nontransactionalRead, 246 boolean transactionActive) { 247 if (!nontransactionalRead) { 248 assertTransaction(transactionActive); 249 } 250 251 return this; 252 } 253 254 public LifeCycleState transitionWriteField(boolean transactionActive) { 255 assertTransaction(transactionActive); 256 return this; 257 } 258 259 protected void assertTransaction(boolean transactionActive) { 260 if (!transactionActive) { 261 throw new JDOUserException(I18NHelper.getMessage(messages, 262 "jdo.lifecycle.xactnotactive")); } 264 } 265 266 267 268 269 270 271 274 public boolean isPersistent() { 275 return isPersistent; 276 } 277 278 281 public boolean isAutoPersistent() { 282 return isAutoPersistent; 283 } 284 285 288 public boolean isPersistentInDataStore() { 289 return isPersistentInDataStore; 290 } 291 292 293 296 public boolean isTransactional() { 297 return isTransactional; 298 } 299 300 304 public boolean isDirty() { 305 return isDirty; 306 } 307 308 311 public boolean isNew() { 312 return isNew; 313 } 314 315 318 public boolean isDeleted() { 319 return isDeleted; 320 } 321 322 325 public boolean needsRegister() { 326 return needsRegister; 327 } 328 329 333 public boolean isNavigable() { 334 return isNavigable; 335 } 336 337 340 public boolean isRefreshable() { 341 return isRefreshable; 342 } 343 344 public boolean isBeforeImageUpdatable() { 345 return isBeforeImageUpdatable; 346 } 347 348 349 public boolean needsReload(boolean optimistic, 350 boolean nontransactionalRead, 351 boolean transactionActive) { 352 return needsReload; 353 } 354 355 public boolean needsRestoreOnRollback(boolean retainValues) { 356 if (retainValues) { 362 return true; 363 } 364 365 return needsRestoreOnRollback; 366 } 367 368 public boolean needMerge() { 369 return needMerge; 370 } 371 372 public int getUpdateAction() { 373 return updateAction; 374 } 375 376 377 378 379 380 381 384 public LifeCycleState changeState(int newStateType) { 385 if (logger.isLoggable(Logger.FINER)) { 386 Object [] items = new Object [] {this,stateTypes[newStateType]}; 387 logger.finer("sqlstore.state.lifecyclestate.changestate",items); } 389 390 return (stateTypes[newStateType]); 391 } 392 393 public String toString() { 394 switch (stateType) { 395 case HOLLOW: 396 return "HOLLOW"; case P_NON_TX: 398 return "P_NON_TX"; case P_CLEAN: 400 return "P_CLEAN"; case P_DIRTY: 402 return "P_DIRTY"; case P_NEW: 404 return "P_NEW"; case P_NEW_FLUSHED: 406 return "P_NEW_FLUSHED"; case P_NEW_FLUSHED_DELETED: 408 return "P_NEW_FLUSHED_DELETED"; case P_NEW_DELETED: 410 return "P_NEW_DELETED"; case P_DELETED: 412 return "P_DELETED"; case P_DELETED_FLUSHED: 414 return "P_DELETED_FLUSHED"; case AP_NEW: 416 return "AP_NEW"; case AP_NEW_PENDING: 418 return "AP_NEW_PENDING"; case AP_NEW_FLUSHED: 420 return "AP_NEW_FLUSHED"; case AP_NEW_FLUSHED_PENDING: 422 return "AP_NEW_FLUSHED_PENDING"; case AP_NEW_FLUSHED_DELETED: 424 return "AP_NEW_FLUSHED_DELETED"; case AP_NEW_DELETED: 426 return "AP_NEW_DELETED"; } 428 429 return null; 430 } 431 432 } 433 434 435 | Popular Tags |