KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > descriptors > OptimisticLockingPolicy


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.descriptors;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.Vector JavaDoc;
26 import oracle.toplink.essentials.expressions.*;
27 import oracle.toplink.essentials.internal.helper.DatabaseField;
28 import oracle.toplink.essentials.internal.sessions.ObjectChangeSet;
29 import oracle.toplink.essentials.queryframework.*;
30 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
31 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl;
32 import oracle.toplink.essentials.internal.sessions.AbstractSession;
33 import oracle.toplink.essentials.descriptors.ClassDescriptor;
34
35 public interface OptimisticLockingPolicy extends Cloneable JavaDoc, Serializable JavaDoc {
36
37     /**
38      * INTERNAL:
39      * Add update fields for template row.
40      * These are any unmapped fields required to write in an update.
41      *
42      * #see this method in VersionLockingPolicy
43      */

44     public void addLockFieldsToUpdateRow(AbstractRecord databaseRow, AbstractSession session);
45
46     /**
47      * INTERNAL:
48      * The method should update the translation row with the
49      * correct write lock values. This method is called on a delete.
50      *
51      * #see this method in VersionLockingPolicy
52      */

53     public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query);
54
55     /**
56      * INTERNAL:
57      * When given an expression, this method will return a new expression with
58      * the optimistic locking values included. This expression will be used
59      * in a delete call.
60      *
61      * #see this method in VersionLockingPolicy
62      */

63     public Expression buildDeleteExpression(oracle.toplink.essentials.internal.helper.DatabaseTable table, Expression mainExpression, AbstractRecord row);
64
65     /**
66      * INTERNAL:
67      * When given an expression, this method will return a new expression with
68      * the optimistic locking values included. This expression will be used in
69      * an update call.
70      *
71      * #see this method in VersionLockingPolicy
72      */

73     public Expression buildUpdateExpression(oracle.toplink.essentials.internal.helper.DatabaseTable table, Expression mainExpression, AbstractRecord translationRow, AbstractRecord modifyRow);
74
75     public Object JavaDoc clone();
76
77     /**
78      * INTERNAL:
79      * This method compares two writeLockValues.
80      * The writeLockValues should be non-null and of the correct type.
81      * Returns:
82      * -1 if value1 is less (older) than value2;
83      * 0 if value1 equals value2;
84      * 1 if value1 is greater (newer) than value2.
85      * Throws:
86      * NullPointerException if the passed value is null;
87      * ClassCastException if the passed value is of a wrong type.
88      */

89     public int compareWriteLockValues(Object JavaDoc value1, Object JavaDoc value2);
90
91     /**
92      * INTERNAL:
93      * This is the base value that is older than all other values, it is used in the place of
94      * null in some situations.
95      */

96     abstract public Object JavaDoc getBaseValue();
97
98     /**
99      * INTERNAL:
100      * Return the value that should be stored in the identity map.
101      * If the value is not stored in the cache, then return a null.
102      *
103      * #see this method in VersionLockingPolicy
104      */

105     public Object JavaDoc getValueToPutInCache(AbstractRecord row, AbstractSession session);
106
107     /**
108      * PUBLIC:
109      * Return the number of versions different between these objects.
110      */

111     public int getVersionDifference(Object JavaDoc currentValue, Object JavaDoc domainObject, Vector JavaDoc primaryKeys, AbstractSession session);
112
113     /**
114      * INTERNAL:
115      * Return the write lock field.
116     *
117     * #see this method in VersionLockingPolicy
118      */

119     public DatabaseField getWriteLockField();
120
121     /**
122      * INTERNAL:
123      * This method will return the optimistic lock value for the object
124      *
125      * #see this method in VersionLockingPolicy
126      */

127     public Object JavaDoc getWriteLockValue(Object JavaDoc domainObject, java.util.Vector JavaDoc primaryKey, AbstractSession session);
128
129     /**
130        * INTERNAL:
131        * This method will return an expression that is used to update its optimistic
132      * locking field.
133      *
134      * #see this method in VersionLockingPolicy
135        */

136     public Expression getWriteLockUpdateExpression(ExpressionBuilder builder);
137
138     /**
139      * INTERNAL:
140      * It is responsible for initializing the policy.
141      *
142      * #see this method in VersionLockingPolicy
143      */

144     public void initialize(AbstractSession session);
145
146     /**
147      * INTERNAL:
148      * Responsible for pre-initializing.
149      *
150      * #see this method in VersionLockingPolicy
151      */

152     public void initializeProperties();
153     
154     /**
155      * INTERNAL:
156      * Update the parent write lock value if the changeSet's is newer
157      */

158     public boolean isChildWriteLockValueGreater(AbstractSession session, java.util.Vector JavaDoc primaryKey, Class JavaDoc original, ObjectChangeSet changeSet);
159
160     /**
161      * INTERNAL:
162      * Update the parent write lock value if the unit of works has been incremented
163      */

164     public boolean isChildWriteLockValueGreater(UnitOfWorkImpl uow, java.util.Vector JavaDoc primaryKey, Class JavaDoc original);
165
166     /**
167      * INTERNAL:
168      * Returns true if the value stored with the domainObject is more recent
169      * than the value . Returns false otherwise.
170      *
171      * #see this method in VersionLockingPolicy
172      */

173     public boolean isNewerVersion(Object JavaDoc currentValue, Object JavaDoc domainObject, java.util.Vector JavaDoc primaryKey, AbstractSession session);
174
175     /**
176      * INTERNAL:
177      * Returns true if the value stored with the domainObject is more recent
178      * than the value in the row. Returns false otherwise.
179      * NOTE: This method will only be called if the shouldOnlyRefreshCacheIfNewerVersion()
180      * flag is set on descriptor.
181      *
182      * #see this method in VersionLockingPolicy
183      */

184     public boolean isNewerVersion(AbstractRecord databaseRow, Object JavaDoc domainObject, java.util.Vector JavaDoc primaryKey, AbstractSession session);
185
186     /**
187      * INTERNAL:
188      * This method should merge changes from the parent into the child.
189      *
190      * #see this method in VersionLockingPolicy
191      */

192     public void mergeIntoParentCache(UnitOfWorkImpl uow, java.util.Vector JavaDoc primaryKey, Object JavaDoc object);
193
194     /**
195      * INTERNAL:
196      * provide a way to set the descriptor for this policy
197      */

198     public void setDescriptor(ClassDescriptor descriptor);
199
200     /**
201      * INTERNAL:
202      * Add the initial right lock values to the modify
203      * row in the query. This method will only be called
204      * on insert.
205      *
206      * #see this method in VersionLockingPolicy
207      */

208     public void setupWriteFieldsForInsert(ObjectLevelModifyQuery query);
209
210     /**
211      * INTERNAL:
212      * This method should update the translation row, the modify
213      * row and the domain object with th lock value.
214      *
215      * #see this method in VersionLockingPolicy
216      */

217     public void updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, Object JavaDoc object);
218
219     public void validateDelete(int rowCount, Object JavaDoc object, DeleteObjectQuery query);
220
221     public void validateUpdate(int rowCount, Object JavaDoc object, WriteObjectQuery query);
222
223     /**
224      * INTERNAL:
225      * Prepare fetch group for read query
226      */

227     public void prepareFetchGroupForReadQuery(FetchGroup fetchGroup, ObjectLevelReadQuery query);
228 }
229
Popular Tags