KickJava   Java API By Example, From Geeks To Geeks.

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


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.odmg.ObjectEnvelope;
19 import org.apache.ojb.broker.PersistenceBrokerException;
20
21 /**
22  * This state represents new objects which have been altered during tx.
23  */

24 public class StateNewDirty extends ModificationState
25 {
26
27     /**
28      * return resulting state after marking clean
29      */

30     public ModificationState markClean()
31     {
32         return StateNewClean.getInstance();
33     }
34
35     /**
36      * return resulting state after marking delete
37      */

38     public ModificationState markDelete()
39     {
40         return StateNewDelete.getInstance();
41     }
42
43     /**
44      * return resulting state after marking dirty
45      */

46     public ModificationState markDirty()
47     {
48         return this;
49     }
50
51     /**
52      * return resulting state after marking new
53      */

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

62     public ModificationState markOld()
63     {
64         return StateOldDirty.getInstance();
65     }
66
67     private static StateNewDirty _instance = new StateNewDirty();
68
69     /**
70      * private constructor: use singleton instance.
71      */

72     private StateNewDirty()
73     {
74     }
75
76     /**
77      * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
78      */

79     public static StateNewDirty getInstance()
80     {
81         return _instance;
82     }
83
84     /**
85      * object is new, thus we need an INSERT to store it
86      */

87     public boolean needsInsert()
88     {
89         return true;
90     }
91
92     /**
93      * checkpoint the ObjectModification
94      */

95     public void checkpoint(ObjectEnvelope mod) throws PersistenceBrokerException
96     {
97         mod.doInsert();
98         mod.setModificationState(StateOldClean.getInstance());
99     }
100
101     /**
102      * commit the associated transaction
103      */

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

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