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 new objects which have been mrked for deletion during tx.
022 */
023 public class StateNewDelete extends ModificationState
024 {
025 private static StateNewDelete _instance = new StateNewDelete();
026
027 /**
028 * return resulting state after marking clean
029 */
030 public ModificationState markClean()
031 {
032 return StateNewClean.getInstance();
033 }
034
035 /**
036 * return resulting state after marking delete
037 */
038 public ModificationState markDelete()
039 {
040 return this;
041 }
042
043 /**
044 * return resulting state after marking dirty
045 */
046 public ModificationState markDirty()
047 {
048 return this;
049 }
050
051 /**
052 * return resulting state after marking new
053 */
054 public ModificationState markNew()
055 {
056 return StateNewDirty.getInstance();
057 }
058
059 /**
060 * return resulting state after marking old
061 */
062 public ModificationState markOld()
063 {
064 return StateOldDelete.getInstance();
065 }
066
067 /**
068 * returns true is this state requires DELETE
069 * @return boolean
070 */
071 public boolean needsDelete()
072 {
073 return true;
074 }
075
076 /**
077 * private constructor: use singleton instance
078 */
079 private StateNewDelete()
080 {
081 }
082
083 /**
084 * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
085 */
086 public static StateNewDelete getInstance()
087 {
088 return _instance;
089 }
090
091 /**
092 * rollback the ObjectModification
093 */
094 public void checkpoint(ObjectEnvelope mod)
095 {
096 }
097
098 /**
099 * commit ObjectModification
100 */
101 public void commit(ObjectEnvelope mod)
102 {
103 mod.doEvictFromCache();
104 mod.setModificationState(StateTransient.getInstance());
105 }
106
107 /**
108 *
109 */
110 public void rollback(ObjectEnvelope mod)
111 {
112 mod.doEvictFromCache();
113 mod.setModificationState(StateTransient.getInstance());
114 }
115 }