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