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