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: Hollow.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.state;
12:
13: import com.triactive.jdo.TransactionNotActiveException;
14: import javax.jdo.JDOFatalInternalException;
15: import javax.jdo.Transaction;
16:
17: class Hollow extends LifeCycleState {
18: protected Hollow() {
19: isPersistent = true;
20: isTransactional = false;
21: isDirty = false;
22: isNew = false;
23: isDeleted = false;
24:
25: stateType = HOLLOW;
26: }
27:
28: public LifeCycleState transitionDeletePersistent(
29: StateManagerImpl sm, Transaction tx) {
30: if (!tx.isActive())
31: throw new TransactionNotActiveException();
32:
33: sm.preDelete();
34: sm.enlistInTransaction();
35: return changeState(sm, P_DELETED);
36: }
37:
38: public LifeCycleState transitionMakeTransactional(
39: StateManagerImpl sm, Transaction tx) {
40: if (!tx.isActive())
41: throw new TransactionNotActiveException();
42:
43: sm.loadDFGFields();
44: sm.enlistInTransaction();
45: return changeState(sm, P_CLEAN);
46: }
47:
48: public LifeCycleState transitionMakeTransient(StateManagerImpl sm) {
49: sm.disconnect();
50: return changeState(sm, TRANSIENT);
51: }
52:
53: public LifeCycleState transitionCommit(StateManagerImpl sm,
54: Transaction tx) {
55: throw new IllegalStateTransitionException(this , "commit", sm);
56: }
57:
58: public LifeCycleState transitionRollback(StateManagerImpl sm,
59: Transaction tx) {
60: throw new IllegalStateTransitionException(this , "rollback", sm);
61: }
62:
63: public LifeCycleState transitionReadField(StateManagerImpl sm,
64: Transaction tx) {
65: if (tx.isActive()) {
66: sm.enlistInTransaction();
67: return changeState(sm, P_CLEAN);
68: } else
69: return changeState(sm, P_NONTRANS);
70: }
71:
72: public LifeCycleState transitionWriteField(StateManagerImpl sm,
73: Transaction tx) {
74: if (tx.isActive()) {
75: if (tx.getRestoreValues())
76: sm.saveFields();
77:
78: sm.enlistInTransaction();
79: return changeState(sm, P_DIRTY);
80: } else
81: return changeState(sm, P_NONTRANS);
82: }
83:
84: public LifeCycleState transitionRetrieve(StateManagerImpl sm,
85: Transaction tx, boolean DFGOnly) {
86: if (DFGOnly)
87: sm.loadDFGFields();
88: else
89: sm.loadUnloadedFields();
90:
91: return transitionReadField(sm, tx);
92: }
93:
94: public String toString() {
95: return "HOLLOW";
96: }
97: }
|