Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StateOldDirty |
|
| 1.0;1 |
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 | ||
20 | /** | |
21 | * this state represents old objects which have been altered during tx. | |
22 | */ | |
23 | public class StateOldDirty extends ModificationState | |
24 | { | |
25 | ||
26 | /** | |
27 | * return resulting state after marking clean | |
28 | */ | |
29 | public ModificationState markClean() | |
30 | { | |
31 | return this; | |
32 | } | |
33 | ||
34 | /** | |
35 | * return resulting state after marking delete | |
36 | */ | |
37 | public ModificationState markDelete() | |
38 | { | |
39 | return StateOldDelete.getInstance(); | |
40 | } | |
41 | ||
42 | /** | |
43 | * return resulting state after marking dirty | |
44 | */ | |
45 | public ModificationState markDirty() | |
46 | { | |
47 | return this; | |
48 | } | |
49 | ||
50 | /** | |
51 | * return resulting state after marking new | |
52 | */ | |
53 | public ModificationState markNew() | |
54 | { | |
55 | return this; | |
56 | } | |
57 | ||
58 | /** | |
59 | * return resulting state after marking old | |
60 | */ | |
61 | public ModificationState markOld() | |
62 | { | |
63 | return this; | |
64 | } | |
65 | ||
66 | private static StateOldDirty _instance = new StateOldDirty(); | |
67 | ||
68 | /** | |
69 | * private constructor: use singleton instance | |
70 | */ | |
71 | private StateOldDirty() | |
72 | { | |
73 | } | |
74 | ||
75 | /** | |
76 | * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects | |
77 | */ | |
78 | public static StateOldDirty getInstance() | |
79 | { | |
80 | return _instance; | |
81 | } | |
82 | ||
83 | /** | |
84 | * checkpoint the transaction | |
85 | */ | |
86 | public void checkpoint(ObjectEnvelope mod) | |
87 | throws org.apache.ojb.broker.PersistenceBrokerException | |
88 | { | |
89 | mod.doUpdate(); | |
90 | } | |
91 | ||
92 | ||
93 | /** | |
94 | * commit the associated transaction | |
95 | */ | |
96 | public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException | |
97 | { | |
98 | mod.doUpdate(); | |
99 | mod.setModificationState(StateOldClean.getInstance()); | |
100 | } | |
101 | ||
102 | /** | |
103 | * rollback transaction. | |
104 | */ | |
105 | public void rollback(ObjectEnvelope mod) | |
106 | { | |
107 | mod.doEvictFromCache(); | |
108 | /* | |
109 | arminw: we can't really restore object state with all dependencies and fields | |
110 | without having a deep copy of the clean object. To avoid side-effects disable this | |
111 | feature | |
112 | */ | |
113 | // // Call added to rollback the object itself so it has the previous values again when it is used further on. | |
114 | // mod.rollback(); | |
115 | } | |
116 | ||
117 | /* | |
118 | * @see ModificationState#needsUpdate() | |
119 | */ | |
120 | public boolean needsUpdate() | |
121 | { | |
122 | return true; | |
123 | } | |
124 | ||
125 | } |