001 package org.apache.ojb.odmg.states;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ojb.odmg.ObjectEnvelope;
019
020 /**
021 * this state represents old objects which have been altered during tx.
022 */
023 public class StateOldDirty extends ModificationState
024 {
025
026 /**
027 * return resulting state after marking clean
028 */
029 public ModificationState markClean()
030 {
031 return this;
032 }
033
034 /**
035 * return resulting state after marking delete
036 */
037 public ModificationState markDelete()
038 {
039 return StateOldDelete.getInstance();
040 }
041
042 /**
043 * return resulting state after marking dirty
044 */
045 public ModificationState markDirty()
046 {
047 return this;
048 }
049
050 /**
051 * return resulting state after marking new
052 */
053 public ModificationState markNew()
054 {
055 return this;
056 }
057
058 /**
059 * return resulting state after marking old
060 */
061 public ModificationState markOld()
062 {
063 return this;
064 }
065
066 private static StateOldDirty _instance = new StateOldDirty();
067
068 /**
069 * private constructor: use singleton instance
070 */
071 private StateOldDirty()
072 {
073 }
074
075 /**
076 * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
077 */
078 public static StateOldDirty getInstance()
079 {
080 return _instance;
081 }
082
083 /**
084 * checkpoint the transaction
085 */
086 public void checkpoint(ObjectEnvelope mod)
087 throws org.apache.ojb.broker.PersistenceBrokerException
088 {
089 mod.doUpdate();
090 }
091
092
093 /**
094 * commit the associated transaction
095 */
096 public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
097 {
098 mod.doUpdate();
099 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 }