KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > otm > states > State


1 package org.apache.ojb.otm.states;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.util.ObjectModification;
19
20 /**
21  * Represents the state of object.
22  */

23 public abstract class State implements ObjectModification
24 {
25     public static final State TRANSIENT = new Transient();
26
27     public static final State PERSISTENT_CLEAN = new PersistentClean();
28
29     public static final State PERSISTENT_DIRTY = new PersistentDirty();
30
31     public static final State PERSISTENT_NEW = new PersistentNew();
32
33     public static final State PERSISTENT_DELETED = new PersistentDeleted();
34
35     public static final State PERSISTENT_NEW_DELETED = new PersistentNewDeleted();
36
37     public static final State HOLLOW = new Hollow();
38
39     //-------------- State transitions --------------------
40

41     /**
42      * Describes the state transition when object is gotten from the cache
43      * or is loaded from database (once per transaction).
44      */

45     public State getObject()
46             throws IllegalObjectStateException
47     {
48         throw new IllegalObjectStateException(this + " during getObject");
49     }
50
51     /**
52      * Describes the state transition when user modifies object
53      */

54     public State markDirty()
55             throws IllegalObjectStateException
56     {
57         throw new IllegalObjectStateException(this + " during markDirty()");
58     }
59
60     /**
61      * Describes the state transition on makePersistent()
62      */

63     public State makePersistent()
64             throws IllegalObjectStateException
65     {
66         throw new IllegalObjectStateException(this + " during makePersistent()");
67     }
68
69     /**
70      * Describes the state transition on deletePersistent()
71      */

72     public State deletePersistent()
73             throws IllegalObjectStateException
74     {
75         throw new IllegalObjectStateException(this + " during deletePersistent()");
76     }
77
78     /**
79      * Describes the state transition on commit()
80      */

81     public State commit()
82             throws IllegalObjectStateException
83     {
84         throw new IllegalObjectStateException(this + " during commit()");
85     }
86
87     /**
88      * Describes the state transition on rollback()
89      */

90     public State rollback()
91             throws IllegalObjectStateException
92     {
93         throw new IllegalObjectStateException(this + " during rollback()");
94     }
95
96     /**
97      * Describes the state transition on refresh()
98      */

99     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 }
141
Popular Tags