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