KickJava   Java API By Example, From Geeks To Geeks.

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


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