01: /*
02: * Copyright 2004 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: PersistentDirty.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.state;
12:
13: import javax.jdo.JDOUserException;
14: import javax.jdo.Transaction;
15:
16: class PersistentDirty extends LifeCycleState {
17: protected PersistentDirty() {
18: isPersistent = true;
19: isTransactional = true;
20: isDirty = true;
21: isNew = false;
22: isDeleted = false;
23:
24: stateType = P_DIRTY;
25: }
26:
27: public LifeCycleState transitionDeletePersistent(
28: StateManagerImpl sm, Transaction tx) {
29: sm.preDelete();
30: return changeState(sm, P_DELETED);
31: }
32:
33: public LifeCycleState transitionMakeNontransactional(
34: StateManagerImpl sm) {
35: throw new JDOUserException(
36: "Cannot make object non-transactional: object is dirty",
37: sm.getObject());
38: }
39:
40: public LifeCycleState transitionMakeTransient(StateManagerImpl sm) {
41: throw new JDOUserException(
42: "Cannot make object transient: object is dirty", sm
43: .getObject());
44: }
45:
46: public LifeCycleState transitionCommit(StateManagerImpl sm,
47: Transaction tx) {
48: sm.discardSavedFields();
49:
50: if (tx.getRetainValues()) {
51: sm.evictFromTransaction();
52: return changeState(sm, P_NONTRANS);
53: } else {
54: sm.clearPersistentFields();
55: sm.evictFromTransaction();
56: return changeState(sm, HOLLOW);
57: }
58: }
59:
60: public LifeCycleState transitionRollback(StateManagerImpl sm,
61: Transaction tx) {
62: if (tx.getRestoreValues()) {
63: sm.restoreFields();
64: sm.replaceSCOFields();
65: sm.evictFromTransaction();
66: return changeState(sm, P_NONTRANS);
67: } else {
68: sm.clearPersistentFields();
69: sm.discardSavedFields();
70: sm.evictFromTransaction();
71: return changeState(sm, HOLLOW);
72: }
73: }
74:
75: public LifeCycleState transitionRefresh(StateManagerImpl sm,
76: Transaction tx) {
77: sm.discardSavedFields();
78: sm.refreshLoadedFields();
79: return changeState(sm, P_CLEAN);
80: }
81:
82: public String toString() {
83: return "P_DIRTY";
84: }
85: }
|