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: * return resulting state after marking clean
027: */
028: public ModificationState markClean() {
029: return this ;
030: }
031:
032: /**
033: * return resulting state after marking delete
034: */
035: public ModificationState markDelete() {
036: return StateOldDelete.getInstance();
037: }
038:
039: /**
040: * return resulting state after marking dirty
041: */
042: public ModificationState markDirty() {
043: return this ;
044: }
045:
046: /**
047: * return resulting state after marking new
048: */
049: public ModificationState markNew() {
050: return this ;
051: }
052:
053: /**
054: * return resulting state after marking old
055: */
056: public ModificationState markOld() {
057: return this ;
058: }
059:
060: private static StateOldDirty _instance = new StateOldDirty();
061:
062: /**
063: * private constructor: use singleton instance
064: */
065: private StateOldDirty() {
066: }
067:
068: /**
069: * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
070: */
071: public static StateOldDirty getInstance() {
072: return _instance;
073: }
074:
075: /**
076: * checkpoint the transaction
077: */
078: public void checkpoint(ObjectEnvelope mod)
079: throws org.apache.ojb.broker.PersistenceBrokerException {
080: mod.doUpdate();
081: }
082:
083: /**
084: * commit the associated transaction
085: */
086: public void commit(ObjectEnvelope mod)
087: throws org.apache.ojb.broker.PersistenceBrokerException {
088: mod.doUpdate();
089: mod.setModificationState(StateOldClean.getInstance());
090: }
091:
092: /**
093: * rollback transaction.
094: */
095: public void rollback(ObjectEnvelope mod) {
096: mod.doEvictFromCache();
097: /*
098: arminw: we can't really restore object state with all dependencies and fields
099: without having a deep copy of the clean object. To avoid side-effects disable this
100: feature
101: */
102: // // Call added to rollback the object itself so it has the previous values again when it is used further on.
103: // mod.rollback();
104: }
105:
106: /*
107: * @see ModificationState#needsUpdate()
108: */
109: public boolean needsUpdate() {
110: return true;
111: }
112:
113: }
|