KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > btree > index > B2IRowLocking1


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IRowLocking1
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.impl.store.access.btree.index;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
29
30 import org.apache.derby.iapi.store.access.ConglomerateController;
31 import org.apache.derby.iapi.types.RowLocation;
32 import org.apache.derby.iapi.store.access.TransactionController;
33
34 import org.apache.derby.iapi.store.raw.FetchDescriptor;
35 import org.apache.derby.iapi.store.raw.LockingPolicy;
36 import org.apache.derby.iapi.store.raw.Page;
37 import org.apache.derby.iapi.store.raw.RecordHandle;
38 import org.apache.derby.iapi.store.raw.Transaction;
39
40 import org.apache.derby.iapi.types.DataValueDescriptor;
41
42 import org.apache.derby.impl.store.access.btree.BTree;
43 import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
44 import org.apache.derby.impl.store.access.btree.BTreeRowPosition;
45 import org.apache.derby.impl.store.access.btree.ControlRow;
46 import org.apache.derby.impl.store.access.btree.LeafControlRow;
47 import org.apache.derby.impl.store.access.btree.OpenBTree;
48 import org.apache.derby.impl.store.access.btree.WaitError;
49
50 /**
51
52 The btree locking policy which implements read uncommitted isolation level.
53
54 It inherits all functionality from B2IRowLocking2 except that it does not
55 get any read row locks (and thus does not release them). Note that table
56 level and table level intent locking remains the same as B2IRowLocking2 as
57 this is currently the way we prevent concurrent ddl from happening while a
58 read uncommitted scanner is operating in the btree.
59
60 **/

61
62 class B2IRowLocking1 extends B2IRowLocking2 implements BTreeLockingPolicy
63 {
64     /**************************************************************************
65      * Fields of the class
66      **************************************************************************
67      */

68
69     /**************************************************************************
70      * Constructors for This class:
71      **************************************************************************
72      */

73     B2IRowLocking1(
74     Transaction rawtran,
75     int lock_level,
76     LockingPolicy locking_policy,
77     ConglomerateController base_cc,
78     OpenBTree open_btree)
79     {
80         super(rawtran, lock_level, locking_policy, base_cc, open_btree);
81     }
82
83
84     /**************************************************************************
85      * Public Methods of This class:
86      **************************************************************************
87      */

88
89
90     /**************************************************************************
91      * Abstract Protected lockScan*() locking methods of BTree:
92      * lockScan - lock the scan page
93      * (inherit from B2IRowLocking2, we still
94      * get page control locks).
95      * lockScanForReclaimSpace - lock page for reclaiming deleted rows.
96      * (inherit from B2IRowLocking2, should never
97      * be called while in read uncommitted).
98      * lockScanRow - lock row and possibly the scan page, only
99      * if row is forUpdate and not a previous key
100      * lock.
101      * unlockScan - unlock the scan page
102      * (inherit from B2IRowLocking2, should never
103      * be called while in read uncommitted).
104      * unlockScanRecordAfterRead- unlock the scan record if we locked it in
105      * lockScanRow.
106      *
107      **************************************************************************
108      */

109
110
111
112     /**
113      * Lock a row as part of doing the scan.
114      * <p>
115      * Lock the row at the given slot (or the previous row if slot is 0).
116      * Get the scan lock on the page if "request_scan_lock" is true.
117      * <p>
118      * If this routine returns true all locks were acquired while maintaining
119      * the latch on leaf. If this routine returns false, locks may or may
120      * not have been acquired, and the routine should be called again after
121      * the client has researched the tree to reget the latch on the
122      * appropriate page.
123      * (p>
124      * As a side effect stores the value of the record handle of the current
125      * scan lock.
126      *
127      * @return Whether locks were acquired without releasing latch on leaf.
128      *
129      * @param open_btree The open_btree to associate latches with -
130      * used if routine has to scan backward.
131      * @param btree the conglomerate info.
132      * @param pos The position of the row to lock.
133      * @param request_scan_lock Whether to request the page scan lock, should
134      * only be requested once per page in the scan.
135      * @param lock_template A scratch area to use to read in rows.
136      * @param previous_key_lock Is this a previous key lock call?
137      * @param forUpdate Is the scan for update or for read only.
138      *
139      * @exception StandardException Standard exception policy.
140      **/

141     public boolean lockScanRow(
142     OpenBTree open_btree,
143     BTree btree,
144     BTreeRowPosition pos,
145     boolean request_scan_lock,
146     FetchDescriptor lock_fetch_desc,
147     DataValueDescriptor[] lock_template,
148     RowLocation lock_row_loc,
149     boolean previous_key_lock,
150     boolean forUpdate,
151     int lock_operation)
152         throws StandardException
153     {
154         // request the scan lock if necessary.
155
// only get the row lock if it is not a previous key lock and iff
156
// it is an update lock.
157
return(
158             _lockScanRow(
159                  open_btree,
160                  btree,
161                  pos,
162                  (forUpdate && !previous_key_lock), // only get update row lock
163
request_scan_lock,
164                  lock_fetch_desc, lock_template, lock_row_loc,
165                  previous_key_lock,
166                  forUpdate,
167                  lock_operation));
168     }
169
170     /**
171      * Release read lock on a row.
172      *
173      * Because this is read uncommitted no S row locks will have been requested,
174      * thus none need be released. The only locks that need to be released
175      * are U locks requested if the scan was opened for update.
176      *
177      * @param pos The position of the row to unlock.
178      * @param forUpdate Is the scan for update or for read only.
179      *
180      **/

181     public void unlockScanRecordAfterRead(
182     BTreeRowPosition pos,
183     boolean forUpdate)
184         throws StandardException
185     {
186         if (forUpdate)
187         {
188             super.unlockScanRecordAfterRead(pos, forUpdate);
189         }
190     }
191
192     /**************************************************************************
193      * Abstract Protected lockNonScan*() locking methods of BTree:
194      *
195      * lockNonScanPreviousRow - lock the row previous to the current
196      * (inherit from B2IRowLocking2, we still
197      * get page control locks) - only called
198      * by insert.
199      * lockNonScanRow - lock the input row
200      * (inherit from B2IRowLocking2, we still
201      * get page control locks) - only called
202      * by insert.
203      **************************************************************************
204      */

205
206 }
207
Popular Tags