001: package org.apache.ojb.otm.states;
002:
003: /* Copyright 2003-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.broker.util.ObjectModification;
019:
020: /**
021: * Represents the state of object.
022: */
023: public abstract class State implements ObjectModification {
024: public static final State TRANSIENT = new Transient();
025:
026: public static final State PERSISTENT_CLEAN = new PersistentClean();
027:
028: public static final State PERSISTENT_DIRTY = new PersistentDirty();
029:
030: public static final State PERSISTENT_NEW = new PersistentNew();
031:
032: public static final State PERSISTENT_DELETED = new PersistentDeleted();
033:
034: public static final State PERSISTENT_NEW_DELETED = new PersistentNewDeleted();
035:
036: public static final State HOLLOW = new Hollow();
037:
038: //-------------- State transitions --------------------
039:
040: /**
041: * Describes the state transition when object is gotten from the cache
042: * or is loaded from database (once per transaction).
043: */
044: public State getObject() throws IllegalObjectStateException {
045: throw new IllegalObjectStateException(this
046: + " during getObject");
047: }
048:
049: /**
050: * Describes the state transition when user modifies object
051: */
052: public State markDirty() throws IllegalObjectStateException {
053: throw new IllegalObjectStateException(this
054: + " during markDirty()");
055: }
056:
057: /**
058: * Describes the state transition on makePersistent()
059: */
060: public State makePersistent() throws IllegalObjectStateException {
061: throw new IllegalObjectStateException(this
062: + " during makePersistent()");
063: }
064:
065: /**
066: * Describes the state transition on deletePersistent()
067: */
068: public State deletePersistent() throws IllegalObjectStateException {
069: throw new IllegalObjectStateException(this
070: + " during deletePersistent()");
071: }
072:
073: /**
074: * Describes the state transition on commit()
075: */
076: public State commit() throws IllegalObjectStateException {
077: throw new IllegalObjectStateException(this + " during commit()");
078: }
079:
080: /**
081: * Describes the state transition on rollback()
082: */
083: public State rollback() throws IllegalObjectStateException {
084: throw new IllegalObjectStateException(this
085: + " during rollback()");
086: }
087:
088: /**
089: * Describes the state transition on refresh()
090: */
091: public State refresh() throws IllegalObjectStateException {
092: return this ;
093: }
094:
095: //-------------- State semantics --------------------
096:
097: /**
098: * returns true is this state requires INSERT
099: */
100: public boolean needsInsert() {
101: return false;
102: }
103:
104: /**
105: * returns true is this state requires UPDATE
106: */
107: public boolean needsUpdate() {
108: return false;
109: }
110:
111: /**
112: * returns true is this state requires DELETE
113: */
114: public boolean needsDelete() {
115: return false;
116: }
117:
118: /**
119: * returns true is this state means that the object has been deleted
120: */
121: public boolean isDeleted() {
122: return false;
123: }
124:
125: }
|