KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IRowLockingRR
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 **/

53
54 class B2IRowLockingRR extends B2IRowLocking3 implements BTreeLockingPolicy
55 {
56
57     /**************************************************************************
58      * Constructors for This class:
59      **************************************************************************
60      */

61     B2IRowLockingRR(
62     Transaction rawtran,
63     int lock_level,
64     LockingPolicy locking_policy,
65     ConglomerateController base_cc,
66     OpenBTree open_btree)
67     {
68         super(rawtran, lock_level, locking_policy, base_cc, open_btree);
69     }
70
71     /**************************************************************************
72      * Public Methods of This class:
73      **************************************************************************
74      */

75
76     /**
77      * Lock a row as part of doing the scan.
78      * <p>
79      * Lock the row at the given slot (or the previous row if slot is 0).
80      * Get the scan lock on the page if "request_scan_lock" is true.
81      * <p>
82      * If this routine returns true all locks were acquired while maintaining
83      * the latch on leaf. If this routine returns false, locks may or may
84      * not have been acquired, and the routine should be called again after
85      * the client has researched the tree to reget the latch on the
86      * appropriate page.
87      * (p>
88      * As a side effect stores the value of the record handle of the current
89      * scan lock.
90      *
91      * @return Whether locks were acquired without releasing latch on leaf.
92      *
93      * @param open_btree The open_btree to associate latches with -
94      * used if routine has to scan backward.
95      * @param btree the conglomerate info.
96      * @param pos The position of the row to lock.
97      * @param request_scan_lock Whether to request the page scan lock, should
98      * only be requested once per page in the scan.
99      * @param lock_template A scratch area to use to read in rows.
100      * @param previous_key_lock Is this a previous key lock call?
101      * @param forUpdate Is the scan for update or for read only.
102      *
103      * @exception StandardException Standard exception policy.
104      **/

105     public boolean lockScanRow(
106     OpenBTree open_btree,
107     BTree btree,
108     BTreeRowPosition pos,
109     boolean request_scan_lock,
110     FetchDescriptor lock_fetch_desc,
111     DataValueDescriptor[] lock_template,
112     RowLocation lock_row_loc,
113     boolean previous_key_lock,
114     boolean forUpdate,
115     int lock_operation)
116         throws StandardException
117     {
118         // don't request row lock if this a previous key lock request, previous
119
// key lock is not required in isolation level 2.
120
return(
121             _lockScanRow(
122                 open_btree,
123                 btree,
124                 pos,
125                 !previous_key_lock, // request row lock iff not prev key lock
126
request_scan_lock,
127                 lock_fetch_desc, lock_template, lock_row_loc,
128                 previous_key_lock,
129                 forUpdate,
130                 lock_operation));
131     }
132
133     /**
134      * Unlock a record after it has been locked for read.
135      * <p>
136      * In repeatable read only unlock records which "did not qualify". For
137      * example in a query like "select * from foo where a = 1" on a table
138      * with no index it is only necessary to hold locks on rows where a=1, but
139      * in the process of finding those rows the system will get locks on other
140      * rows to verify they are committed before applying the qualifier. Those
141      * locks can be released under repeatable read isolation.
142      * <p>
143      * if it is forUpdate then get S lock and release U lock, else there is
144      * nothing to do in serializable - we keep the S locks until end of
145      * transaction.
146      *
147      * @param forUpdate Is the scan for update or for read only.
148      *
149      **/

150     public void unlockScanRecordAfterRead(
151     BTreeRowPosition pos,
152     boolean forUpdate)
153         throws StandardException
154     {
155         if (!pos.current_rh_qualified)
156         {
157             if (SanityManager.DEBUG)
158             {
159                 SanityManager.ASSERT(pos.current_leaf != null , "leaf is null");
160
161                 SanityManager.ASSERT(
162                     pos.current_lock_row_loc != null , "row_loc is null");
163             }
164
165             base_cc.unlockRowAfterRead(
166                 pos.current_lock_row_loc, forUpdate, pos.current_rh_qualified);
167         }
168     }
169 }
170
Popular Tags