01: /*
02:
03: Derby - Class org.apache.derby.impl.store.raw.xact.RowLockingRR
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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: A locking policy that implements row level locking with repeatable read
40: isolation. Since phantom protection with previous key locking is actually
41: handled by the upper level access methods, the only difference in repeatable
42: read is that read locks are of type RowLock.RS2. This type will not
43: conflict with a previous key insert lock.
44:
45: @see org.apache.derby.iapi.store.raw.LockingPolicy
46: */
47: public class RowLockingRR extends RowLocking3 {
48:
49: protected RowLockingRR(LockFactory lf) {
50: super (lf);
51: }
52:
53: protected RowLock getReadLockType() {
54: return (RowLock.RS2);
55: }
56:
57: protected RowLock getUpdateLockType() {
58: return (RowLock.RU2);
59: }
60:
61: protected RowLock getWriteLockType() {
62: return (RowLock.RX2);
63: }
64:
65: /**
66: * Unlock a record after it has been locked for read.
67: * <p>
68: * In repeatable read only unlock records which "did not qualify". For
69: * example in a query like "select * from foo where a = 1" on a table
70: * with no index it is only necessary to hold locks on rows where a=1, but
71: * in the process of finding those rows the system will get locks on other
72: * rows to verify they are committed before applying the qualifier. Those
73: * locks can be released under repeatable read isolation.
74: * <p>
75: *
76: * @exception StandardException Standard exception policy.
77: **/
78: public void unlockRecordAfterRead(Transaction t,
79: ContainerHandle container_handle, RecordHandle record,
80: boolean forUpdate, boolean row_qualified)
81: throws StandardException {
82: if (!row_qualified) {
83: Object qualifier = forUpdate ? RowLock.RU2 : RowLock.RS2;
84:
85: int count = lf.unlock(t.getCompatibilitySpace(), t, record,
86: qualifier);
87:
88: if (SanityManager.DEBUG) {
89: // in the case of lock escalation the count could be 0.
90: if (!(count == 1 || count == 0)) {
91: SanityManager.THROWASSERT("count = " + count
92: + "record.getContainerId() = "
93: + record.getContainerId());
94: }
95: }
96: }
97: }
98:
99: }
|