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: PersistentClean.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.state;
12:
13: import javax.jdo.Transaction;
14:
15: class PersistentClean extends LifeCycleState {
16: protected PersistentClean() {
17: isPersistent = true;
18: isTransactional = true;
19: isDirty = false;
20: isNew = false;
21: isDeleted = false;
22:
23: stateType = P_CLEAN;
24: }
25:
26: public LifeCycleState transitionDeletePersistent(
27: StateManagerImpl sm, Transaction tx) {
28: sm.preDelete();
29: return changeState(sm, P_DELETED);
30: }
31:
32: public LifeCycleState transitionMakeNontransactional(
33: StateManagerImpl sm) {
34: sm.evictFromTransaction();
35: return changeState(sm, P_NONTRANS);
36: }
37:
38: public LifeCycleState transitionMakeTransient(StateManagerImpl sm) {
39: sm.evictFromTransaction();
40: sm.disconnect();
41: return changeState(sm, TRANSIENT);
42: }
43:
44: public LifeCycleState transitionCommit(StateManagerImpl sm,
45: Transaction tx) {
46: if (tx.getRetainValues()) {
47: sm.evictFromTransaction();
48: return changeState(sm, P_NONTRANS);
49: } else {
50: sm.clearPersistentFields();
51: sm.evictFromTransaction();
52: return changeState(sm, HOLLOW);
53: }
54: }
55:
56: public LifeCycleState transitionRollback(StateManagerImpl sm,
57: Transaction tx) {
58: if (tx.getRestoreValues()) {
59: sm.evictFromTransaction();
60: return changeState(sm, P_NONTRANS);
61: } else {
62: sm.clearPersistentFields();
63: sm.evictFromTransaction();
64: return changeState(sm, HOLLOW);
65: }
66: }
67:
68: public LifeCycleState transitionEvict(StateManagerImpl sm) {
69: sm.clearPersistentFields();
70: sm.evictFromTransaction();
71: return changeState(sm, HOLLOW);
72: }
73:
74: public LifeCycleState transitionWriteField(StateManagerImpl sm,
75: Transaction tx) {
76: if (tx.getRestoreValues())
77: sm.saveFields();
78:
79: return changeState(sm, P_DIRTY);
80: }
81:
82: public String toString() {
83: return "P_CLEAN";
84: }
85: }
|