KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > states > StateOldDelete


1 package org.apache.ojb.odmg.states;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.PersistenceBrokerException;
19 import org.apache.ojb.odmg.ObjectEnvelope;
20
21 /**
22  * this state represents old objects which have been marked for deletion during tx.
23  */

24 public class StateOldDelete extends ModificationState
25 {
26     private static StateOldDelete _instance = new StateOldDelete();
27
28     /**
29      * private constructor: use singleton instance
30      */

31     private StateOldDelete()
32     {
33     }
34
35     /**
36      * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
37      */

38     public static StateOldDelete getInstance()
39     {
40         return _instance;
41     }
42
43     /**
44      * return resulting state after marking clean
45      */

46     public ModificationState markClean()
47     {
48         return StateOldClean.getInstance();
49     }
50
51     /**
52      * return resulting state after marking delete
53      */

54     public ModificationState markDelete()
55     {
56         return this;
57     }
58
59     /**
60      * return resulting state after marking dirty
61      */

62     public ModificationState markDirty()
63     {
64         return this;
65     }
66
67     /**
68      * return resulting state after marking new
69      */

70     public ModificationState markNew()
71     {
72         return StateOldDirty.getInstance();
73     }
74
75     /**
76      * return resulting state after marking old
77      */

78     public ModificationState markOld()
79     {
80         return this;
81     }
82
83     /**
84      * returns true is this state requires DELETE
85      * @return boolean
86      */

87     public boolean needsDelete()
88     {
89         return true;
90     }
91
92     /**
93      * rollback the transaction
94      */

95     public void checkpoint(ObjectEnvelope mod)
96             throws org.apache.ojb.broker.PersistenceBrokerException
97     {
98         mod.doDelete();
99         mod.setModificationState(StateTransient.getInstance());
100     }
101
102     /**
103      * commit the associated transaction
104      */

105     public void commit(ObjectEnvelope mod) throws PersistenceBrokerException
106     {
107         mod.doDelete();
108         mod.setModificationState(StateTransient.getInstance());
109     }
110
111     /**
112      *
113      */

114     public void rollback(ObjectEnvelope mod)
115     {
116         mod.doEvictFromCache();
117     }
118 }
119
Popular Tags