KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > xact > RowLockingRR


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.RowLockingRR
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 package org.apache.derby.impl.store.raw.xact;
22
23 import org.apache.derby.iapi.services.locks.LockFactory;
24 import org.apache.derby.iapi.services.locks.C_LockFactory;
25 import org.apache.derby.iapi.services.locks.Latch;
26
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28
29 import org.apache.derby.iapi.store.raw.ContainerHandle;
30 import org.apache.derby.iapi.store.raw.ContainerLock;
31 import org.apache.derby.iapi.store.raw.LockingPolicy;
32 import org.apache.derby.iapi.store.raw.RecordHandle;
33 import org.apache.derby.iapi.store.raw.RowLock;
34 import org.apache.derby.iapi.store.raw.Transaction;
35
36 import org.apache.derby.iapi.error.StandardException;
37
38
39 /**
40     A locking policy that implements row level locking with repeatable read
41     isolation. Since phantom protection with previous key locking is actually
42     handled by the upper level access methods, the only difference in repeatable
43     read is that read locks are of type RowLock.RS2. This type will not
44     conflict with a previous key insert lock.
45
46     @see org.apache.derby.iapi.store.raw.LockingPolicy
47 */

48 public class RowLockingRR extends RowLocking3
49 {
50
51     protected RowLockingRR(LockFactory lf)
52     {
53             super(lf);
54     }
55
56     protected RowLock getReadLockType()
57     {
58         return(RowLock.RS2);
59     }
60
61     protected RowLock getUpdateLockType()
62     {
63         return(RowLock.RU2);
64     }
65
66     protected RowLock getWriteLockType()
67     {
68         return(RowLock.RX2);
69     }
70
71     /**
72      * Unlock a record after it has been locked for read.
73      * <p>
74      * In repeatable read only unlock records which "did not qualify". For
75      * example in a query like "select * from foo where a = 1" on a table
76      * with no index it is only necessary to hold locks on rows where a=1, but
77      * in the process of finding those rows the system will get locks on other
78      * rows to verify they are committed before applying the qualifier. Those
79      * locks can be released under repeatable read isolation.
80      * <p>
81      *
82      * @exception StandardException Standard exception policy.
83      **/

84     public void unlockRecordAfterRead(
85     Transaction t,
86     ContainerHandle container_handle,
87     RecordHandle record,
88     boolean forUpdate,
89     boolean row_qualified)
90         throws StandardException
91     {
92         if (!row_qualified)
93         {
94             Object JavaDoc qualifier = forUpdate ? RowLock.RU2 : RowLock.RS2;
95
96             int count =
97                 lf.unlock(t.getCompatibilitySpace(), t, record, qualifier);
98
99             if (SanityManager.DEBUG)
100             {
101                 // in the case of lock escalation the count could be 0.
102
if (!(count == 1 || count == 0))
103                 {
104                     SanityManager.THROWASSERT(
105                     "count = " + count +
106                     "record.getContainerId() = " + record.getContainerId());
107                 }
108             }
109         }
110     }
111
112 }
113
Popular Tags