KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > PersistenceState


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

19
20 package org.apache.cayenne;
21
22 /**
23  * Defines a set of object states from the point of view of persistence. I.e.
24  * PersistenceState is the state of data stored in an object relative to the external
25  * persistence store. If an object's state matches the state of the persistence store, the
26  * object is COMMITTED. If object is not intended to be persistent or is not explicitly
27  * made persistent, the state is TRANSIENT, and so on.
28  * <p>
29  * Object persistence states should not be modified directly. Rather it is a
30  * responsibility of a ObjectContext/DataContext to maintain correct state of the managed
31  * objects.
32  *
33  * @author Andrus Adamchik
34  */

35 public class PersistenceState {
36
37     /**
38      * Returns String label for persistence state. Used for debugging.
39      */

40     public static String JavaDoc persistenceStateName(int persistenceState) {
41         switch (persistenceState) {
42             case PersistenceState.TRANSIENT:
43                 return "transient";
44             case PersistenceState.NEW:
45                 return "new";
46             case PersistenceState.MODIFIED:
47                 return "modified";
48             case PersistenceState.COMMITTED:
49                 return "committed";
50             case PersistenceState.HOLLOW:
51                 return "hollow";
52             case PersistenceState.DELETED:
53                 return "deleted";
54             default:
55                 return "unknown";
56         }
57     }
58
59     /**
60      * Describes a state of an object not registered with DataContext/ObjectContext, and
61      * therefore having no persistence features.
62      */

63     public static final int TRANSIENT = 1;
64
65     /**
66      * Describes a state of an object freshly registered with DataContext/ObjectContext,
67      * but not committed to the database yet. So there is no corresponding database record
68      * for this object just yet.
69      */

70     public static final int NEW = 2;
71
72     /**
73      * Describes a state of an object registered with DataContext/ObjectContext, whose
74      * fields exactly match the state of a corresponding database row. This state is not
75      * fully "clean", since database record may have been externally modified.
76      */

77     public static final int COMMITTED = 3;
78
79     /**
80      * Describes a state of an object registered with DataContext/ObjectContext, and
81      * having a corresponding database row. This object state is known to be locally
82      * modified and different from the database state.
83      */

84     public static final int MODIFIED = 4;
85
86     /**
87      * Describes a state of an object registered with DataContext/ObjectContext, and
88      * having a corresponding database row. This object does not store any fields except
89      * for its id (it is "hollow"), so next time it is accessed, it will be populated from
90      * the database by the context. In this respect this is a real "clean" object.
91      */

92     public static final int HOLLOW = 5;
93
94     /**
95      * Describes a state of an object registered with DataContext/ObjectContext, that will
96      * be deleted from the database on the next commit.
97      */

98     public static final int DELETED = 6;
99 }
100
Popular Tags