KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > store > raw > LockingPolicy


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

21
22 package org.apache.derby.iapi.store.raw;
23
24 import org.apache.derby.iapi.services.locks.Latch;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 /**
29     Any object that implements this interface can be used as a locking
30     policy for accessing a container.
31     <P>
32     The locking policy must use the defined lock qualifiers
33     (ContainerLock.CIS, RowLock.RS, etc.) and the standard lock manager.
34     (A locking policy that just performs no locking wouldn't need to use
35     these :-)
36     <P>
37     A locking policy must use the object that is an instance of Transaction
38     (originally obtained via startTransaction() in RawStoreFactory) as the
39     compatibilitySpace for the LockFactory calls.
40     <BR>
41     A locking policy must use the passed in transaction as the
42     compatability space and the lock group.
43     This chain (group) of locks has the following defined behaviour
44         <UL>
45         <LI>Locks are released at transaction.commit()
46         <LI>Locks are released at transaction.abort()
47         </UL>
48
49
50     <BR>
51     MT - Thread Safe
52
53     @see ContainerHandle
54     @see RecordHandle
55     @see org.apache.derby.iapi.services.locks.LockFactory
56     @see org.apache.derby.iapi.services.locks.Lockable
57
58 */

59
60 public interface LockingPolicy {
61
62     /**
63         No locking what so ever, isolation parameter will be ignored by
64         getLockingPolicy().
65
66         @see RawStoreFactory
67     */

68     static final int MODE_NONE = 0;
69
70     /**
71         Record level locking.
72     */

73     static final int MODE_RECORD = 1;
74
75     /**
76         ContainerHandle level locking.
77     */

78     static final int MODE_CONTAINER = 2;
79
80     /**
81         Called when a container is opened.
82
83         @param t Transaction to associate lock with.
84         @param container Container to lock.
85         @param waitForLock Should lock request wait until granted?
86         @param forUpdate Should container be locked for update, or read?
87
88         @return true if the lock was obtained, false if it wasn't.
89         False should only be returned if the waitForLock policy was set to
90         "false," and the lock was unavailable.
91
92         @exception StandardException Standard Cloudscape error policy
93
94         @see ContainerHandle
95
96     */

97     public boolean lockContainer(
98     Transaction t,
99     ContainerHandle container,
100     boolean waitForLock,
101     boolean forUpdate)
102         throws StandardException;
103
104     /**
105         Called when a container is closed.
106
107         @see ContainerHandle
108         @see ContainerHandle#close
109     */

110     public void unlockContainer(
111     Transaction t,
112     ContainerHandle container);
113
114     /**
115         Called before a record is fetched.
116
117         @param t Transaction to associate lock with.
118         @param container Open Container used to get record. Will be used
119                             to row locks by the container they belong to.
120         @param record Record to lock.
121         @param waitForLock Should lock request wait until granted?
122         @param forUpdate Should container be locked for update, or read?
123
124
125         @exception StandardException Standard Cloudscape error policy
126
127         @see Page
128
129     */

130     public boolean lockRecordForRead(
131     Transaction t,
132     ContainerHandle container,
133     RecordHandle record,
134     boolean waitForLock,
135     boolean forUpdate)
136         throws StandardException;
137
138
139     /**
140         Lock a record while holding a page latch.
141
142         @param latch Latch held.
143         @param record Record to lock.
144         @param forUpdate Should container be locked for update, or read?
145
146
147         @exception StandardException Standard Cloudscape error policy
148
149         @see Page
150
151     */

152     public void lockRecordForRead(
153         Latch latch,
154         RecordHandle record,
155         boolean forUpdate)
156             throws StandardException;
157
158     /**
159         Request a write lock which will be released immediately upon grant.
160
161         @param t Transaction to associate lock with.
162         @param record Record to lock.
163         @param lockForPreviousKey Lock is for a previous key of a insert.
164         @param waitForLock Should lock request wait until granted?
165
166         @return true if the lock was obtained, false if it wasn't.
167         False should only be returned if the waitForLock argument was set to
168         "false," and the lock was unavailable.
169
170         @exception StandardException Standard Cloudscape error policy
171
172         @see Page
173     */

174     public boolean zeroDurationLockRecordForWrite(
175     Transaction t,
176     RecordHandle record,
177     boolean lockForPreviousKey,
178     boolean waitForLock)
179         throws StandardException;
180
181     /**
182         Called before a record is inserted, updated or deleted.
183
184         If zeroDuration is true then lock is released immediately after it
185         has been granted.
186
187         @param t Transaction to associate lock with.
188         @param record Record to lock.
189         @param lockForInsert Lock is for an insert.
190         @param waitForLock Should lock request wait until granted?
191
192         @return true if the lock was obtained, false if it wasn't.
193         False should only be returned if the waitForLock argument was set to
194         "false," and the lock was unavailable.
195
196         @exception StandardException Standard Cloudscape error policy
197
198         @see Page
199     */

200     public boolean lockRecordForWrite(
201     Transaction t,
202     RecordHandle record,
203     boolean lockForInsert,
204     boolean waitForLock)
205         throws StandardException;
206
207     /**
208         Lock a record for write while holding a page latch.
209
210
211         @param latch Page latch held.
212         @param record Record to lock.
213
214         @exception StandardException Standard Cloudscape error policy
215
216         @see Page
217     */

218     public void lockRecordForWrite(
219     Latch latch,
220     RecordHandle record)
221         throws StandardException;
222     /**
223         Called after a record has been fetched.
224
225         @exception StandardException Standard Cloudscape error policy
226
227         @see Page
228
229     */

230     public void unlockRecordAfterRead(
231     Transaction t,
232     ContainerHandle container,
233     RecordHandle record,
234     boolean forUpdate,
235     boolean row_qualified)
236         throws StandardException;
237
238
239     /**
240         Get the mode of this policy
241     */

242     public int getMode();
243 }
244
Popular Tags