KickJava   Java API By Example, From Geeks To Geeks.

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


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: PersistentDirty.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.state;
12
13 import javax.jdo.JDOUserException;
14 import javax.jdo.Transaction;
15
16
17 class PersistentDirty extends LifeCycleState
18 {
19     protected PersistentDirty()
20     {
21         isPersistent = true;
22         isTransactional = true;
23         isDirty = true;
24         isNew = false;
25         isDeleted = false;
26
27         stateType = P_DIRTY;
28     }
29
30     public LifeCycleState transitionDeletePersistent(StateManagerImpl sm, Transaction tx)
31     {
32         sm.preDelete();
33         return changeState(sm, P_DELETED);
34     }
35
36     public LifeCycleState transitionMakeNontransactional(StateManagerImpl sm)
37     {
38         throw new JDOUserException("Cannot make object non-transactional: object is dirty", sm.getObject());
39     }
40
41     public LifeCycleState transitionMakeTransient(StateManagerImpl sm)
42     {
43         throw new JDOUserException("Cannot make object transient: object is dirty", sm.getObject());
44     }
45
46     public LifeCycleState transitionCommit(StateManagerImpl sm, Transaction tx)
47     {
48         sm.discardSavedFields();
49
50         if (tx.getRetainValues())
51         {
52             sm.evictFromTransaction();
53             return changeState(sm, P_NONTRANS);
54         }
55         else
56         {
57             sm.clearPersistentFields();
58             sm.evictFromTransaction();
59             return changeState(sm, HOLLOW);
60         }
61     }
62
63     public LifeCycleState transitionRollback(StateManagerImpl sm, Transaction tx)
64     {
65         if (tx.getRestoreValues())
66         {
67             sm.restoreFields();
68             sm.replaceSCOFields();
69             sm.evictFromTransaction();
70             return changeState(sm, P_NONTRANS);
71         }
72         else
73         {
74             sm.clearPersistentFields();
75             sm.discardSavedFields();
76             sm.evictFromTransaction();
77             return changeState(sm, HOLLOW);
78         }
79     }
80
81     public LifeCycleState transitionRefresh(StateManagerImpl sm, Transaction tx)
82     {
83         sm.discardSavedFields();
84         sm.refreshLoadedFields();
85         return changeState(sm, P_CLEAN);
86     }
87
88     public String JavaDoc toString()
89     {
90         return "P_DIRTY";
91     }
92 }
93
Popular Tags