1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.raw.xact.RowLocking1 |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
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 isolation degree 1. |
41 | |
42 | This is an implementation of Gray's degree 1 isolation, read uncommitted, |
43 | or often referred to as dirty reads. Basically read operations are |
44 | done with no locking. |
45 | |
46 | This locking policy is only to be used for read operations. |
47 | |
48 | The approach is to place all "write" container and row locks on the |
49 | transaction group lock list. Locks on this group will last until end |
50 | of transaction. |
51 | |
52 | This implementation will still get table level intent locks. This is to |
53 | prevent hard cases where the container otherwise could be deleted while |
54 | read uncommitted reader is still accessing it. In order to not get table |
55 | level intent locks some sort of other ddl level lock would have to be |
56 | implemented. |
57 | |
58 | All "read" row locks will be not be requested. |
59 | |
60 | Note that write operations extend from the RowLocking3 implementations. |
61 | |
62 | @see org.apache.derby.iapi.store.raw.LockingPolicy |
63 | */ |
64 | public class RowLocking1 extends RowLocking2 |
65 | { |
66 | |
67 | protected RowLocking1(LockFactory lf) |
68 | { |
69 | super(lf); |
70 | } |
71 | |
72 | /** |
73 | * Obtain lock on record being read. |
74 | * <p> |
75 | * Assumes that a table level IS has been acquired. Will acquire a Shared |
76 | * or Update lock on the row, depending on the "forUpdate" parameter. |
77 | * <p> |
78 | * Read lock will be placed on separate group from transaction. |
79 | * |
80 | * @param t The transaction to associate the lock with. |
81 | * @param record The record to be locked. |
82 | * @param waitForLock Should lock request wait until granted? |
83 | * @param forUpdate Whether to open for read or write access. |
84 | * |
85 | * @return true if the lock was granted, false if waitForLock was false |
86 | * and the lock could not be granted. |
87 | * |
88 | * @exception StandardException Standard exception policy. |
89 | **/ |
90 | public boolean lockRecordForRead( |
91 | Transaction t, |
92 | ContainerHandle container_handle, |
93 | RecordHandle record, |
94 | boolean waitForLock, |
95 | boolean forUpdate) |
96 | throws StandardException |
97 | { |
98 | |
99 | return( |
100 | !forUpdate ? |
101 | true : |
102 | super.lockRecordForRead( |
103 | t, container_handle, record, waitForLock, forUpdate)); |
104 | } |
105 | |
106 | /** |
107 | * Obtain lock on record being read while holding a latch. |
108 | * <p> |
109 | * Assumes that a table level IS has been acquired. Will acquire a Shared |
110 | * or Update lock on the row, depending on the "forUpdate" parameter. |
111 | * <p> |
112 | * |
113 | * @param latch The latch being held. |
114 | * @param record The record to be locked. |
115 | * @param forUpdate Whether to open for read or write access. |
116 | * |
117 | * @exception StandardException Standard exception policy. |
118 | **/ |
119 | public void lockRecordForRead( |
120 | Latch latch, |
121 | RecordHandle record, |
122 | boolean forUpdate) |
123 | throws StandardException |
124 | { |
125 | if (forUpdate) |
126 | super.lockRecordForRead(latch, record, forUpdate); |
127 | } |
128 | |
129 | public void unlockRecordAfterRead( |
130 | Transaction t, |
131 | ContainerHandle container_handle, |
132 | RecordHandle record, |
133 | boolean forUpdate, |
134 | boolean row_qualified) |
135 | throws StandardException |
136 | { |
137 | if (forUpdate) |
138 | { |
139 | super.unlockRecordAfterRead( |
140 | t, container_handle, record, forUpdate, row_qualified); |
141 | } |
142 | return; |
143 | } |
144 | } |