KickJava   Java API By Example, From Geeks To Geeks.

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


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: TransientClean.java,v 1.1 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.JDOUserException;
15 import javax.jdo.Transaction;
16
17
18 class TransientClean extends LifeCycleState
19 {
20     protected TransientClean()
21     {
22         /*
23          * TransientClean is the only exception to the rule that all objects
24          * that are in a transactional state are in the PM's TX cache. TCleans
25          * are never in the cache, but they're still designated "transactional"
26          * objects as far as the user is concerned.
27          */

28         isPersistent = false;
29         isTransactional = true;
30         isDirty = false;
31         isNew = false;
32         isDeleted = false;
33
34         stateType = T_CLEAN;
35     }
36
37     public LifeCycleState transitionMakePersistent(StateManagerImpl sm, Transaction tx)
38     {
39         if (!tx.isActive())
40             throw new TransactionNotActiveException();
41
42         sm.saveFields();
43         sm.enlistInTransaction();
44         return changeState(sm, P_NEW);
45     }
46
47     public LifeCycleState transitionDeletePersistent(StateManagerImpl sm, Transaction tx)
48     {
49         throw new JDOUserException("Cannot delete, object is not persistent", sm.getObject());
50     }
51
52     public LifeCycleState transitionMakeNontransactional(StateManagerImpl sm)
53     {
54         sm.disconnect();
55         return changeState(sm, TRANSIENT);
56     }
57
58     public LifeCycleState transitionWriteField(StateManagerImpl sm, Transaction tx)
59     {
60         if (tx.isActive())
61         {
62             sm.saveFields();
63             sm.enlistInTransaction();
64             return changeState(sm, T_DIRTY);
65         }
66         else
67             return this;
68     }
69
70     public String JavaDoc toString()
71     {
72         return "T_CLEAN";
73     }
74 }
75
Popular Tags