1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.raw.xact.RowLocking2nohold |
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 2, |
41 | never holding read locks after they are granted. |
42 | |
43 | Exactly the same as RowLocking2, except that read locks are acquired using |
44 | zeroDuration locks, which are immediately released by the lock manager |
45 | after they are granted. |
46 | |
47 | @see org.apache.derby.iapi.store.raw.LockingPolicy |
48 | */ |
49 | public class RowLocking2nohold extends RowLocking2 |
50 | { |
51 | protected RowLocking2nohold(LockFactory lf) |
52 | { |
53 | super(lf); |
54 | } |
55 | |
56 | /** |
57 | * Obtain lock on record being read. |
58 | * <p> |
59 | * Assumes that a table level IS has been acquired. Will acquire a Shared |
60 | * or Update lock on the row, depending on the "forUpdate" parameter. |
61 | * <p> |
62 | * Read lock will be acquired using zeroDuration lock. |
63 | * |
64 | * @param t The transaction to associate the lock with. |
65 | * @param record The record to be locked. |
66 | * @param waitForLock Should lock request wait until granted? |
67 | * @param forUpdate Whether to open for read or write access. |
68 | * |
69 | * @return true if the lock was granted, false if waitForLock was false |
70 | * and the lock could not be granted. |
71 | * |
72 | * @exception StandardException Standard exception policy. |
73 | **/ |
74 | public boolean lockRecordForRead( |
75 | Transaction t, |
76 | ContainerHandle container_handle, |
77 | RecordHandle record, |
78 | boolean waitForLock, |
79 | boolean forUpdate) |
80 | throws StandardException |
81 | { |
82 | // RESOLVE - figure out what is right for update locks, for now throw |
83 | // if they are used. |
84 | if (SanityManager.DEBUG) |
85 | { |
86 | SanityManager.ASSERT(!forUpdate); |
87 | } |
88 | |
89 | return(lf.zeroDurationlockObject( |
90 | t.getCompatibilitySpace(), |
91 | record, |
92 | (forUpdate ? RowLock.RU2 : RowLock.RS2), |
93 | waitForLock ? |
94 | C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); |
95 | } |
96 | |
97 | public void unlockRecordAfterRead( |
98 | Transaction t, |
99 | ContainerHandle container_handle, |
100 | RecordHandle record, |
101 | boolean forUpdate, |
102 | boolean row_qualified) |
103 | { |
104 | return; |
105 | } |
106 | } |