KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > state > PersistentNontransactional


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: PersistentNontransactional.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.state;
12
13 import com.triactive.jdo.TransactionNotActiveException;
14 import javax.jdo.Transaction;
15
16
17 class PersistentNontransactional extends LifeCycleState
18 {
19     protected PersistentNontransactional()
20     {
21         isPersistent = true;
22         isTransactional = false;
23         isDirty = false;
24         isNew = false;
25         isDeleted = false;
26
27         stateType = P_NONTRANS;
28     }
29
30     public LifeCycleState transitionDeletePersistent(StateManagerImpl sm, Transaction tx)
31     {
32         if (!tx.isActive())
33             throw new TransactionNotActiveException();
34
35         sm.preDelete();
36         sm.enlistInTransaction();
37         return changeState(sm, P_DELETED);
38     }
39
40     public LifeCycleState transitionMakeTransactional(StateManagerImpl sm, Transaction tx)
41     {
42         if (!tx.isActive())
43             throw new TransactionNotActiveException();
44
45         sm.refreshLoadedFields();
46         sm.enlistInTransaction();
47         return changeState(sm, P_CLEAN);
48     }
49
50     public LifeCycleState transitionMakeTransient(StateManagerImpl sm)
51     {
52         sm.disconnect();
53         return changeState(sm, TRANSIENT);
54     }
55
56     public LifeCycleState transitionCommit(StateManagerImpl sm, Transaction tx)
57     {
58         throw new IllegalStateTransitionException(this, "commit", sm);
59     }
60
61     public LifeCycleState transitionRollback(StateManagerImpl sm, Transaction tx)
62     {
63         throw new IllegalStateTransitionException(this, "rollback", sm);
64     }
65
66     public LifeCycleState transitionRefresh(StateManagerImpl sm)
67     {
68         sm.refreshLoadedFields();
69         return this;
70     }
71
72     public LifeCycleState transitionEvict(StateManagerImpl sm)
73     {
74         sm.clearPersistentFields();
75         return changeState(sm, HOLLOW);
76     }
77
78     public LifeCycleState transitionReadField(StateManagerImpl sm, Transaction tx)
79     {
80         if (tx.isActive())
81         {
82             sm.refreshLoadedFields();
83             sm.enlistInTransaction();
84             return changeState(sm, P_CLEAN);
85         }
86         else
87             return this;
88     }
89
90     public LifeCycleState transitionWriteField(StateManagerImpl sm, Transaction tx)
91     {
92         if (tx.isActive())
93         {
94             sm.refreshLoadedFields();
95             sm.saveFields(); // save the fields for rollback
96
sm.enlistInTransaction();
97             return changeState(sm, P_DIRTY);
98         }
99         else
100             return this;
101     }
102
103     public LifeCycleState transitionRetrieve(StateManagerImpl sm, Transaction tx, boolean DFGOnly)
104     {
105         sm.clearPersistentFields();
106
107         if (DFGOnly)
108             sm.loadDFGFields();
109         else
110             sm.loadUnloadedFields();
111
112         if (tx.isActive())
113         {
114             sm.enlistInTransaction();
115             return changeState(sm, P_CLEAN);
116         }
117         else
118             return this;
119     }
120
121     public String JavaDoc toString()
122     {
123         return "P_NONTRANS";
124     }
125 }
126
Popular Tags