01: /*
02:
03: Derby - Class org.apache.derby.impl.store.raw.xact.RowLocking2nohold
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:
22: package org.apache.derby.impl.store.raw.xact;
23:
24: import org.apache.derby.iapi.services.locks.LockFactory;
25: import org.apache.derby.iapi.services.locks.C_LockFactory;
26: import org.apache.derby.iapi.services.locks.Latch;
27:
28: import org.apache.derby.iapi.services.sanity.SanityManager;
29:
30: import org.apache.derby.iapi.store.raw.ContainerHandle;
31: import org.apache.derby.iapi.store.raw.ContainerLock;
32: import org.apache.derby.iapi.store.raw.LockingPolicy;
33: import org.apache.derby.iapi.store.raw.RecordHandle;
34: import org.apache.derby.iapi.store.raw.RowLock;
35: import org.apache.derby.iapi.store.raw.Transaction;
36:
37: import org.apache.derby.iapi.error.StandardException;
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: protected RowLocking2nohold(LockFactory lf) {
51: super (lf);
52: }
53:
54: /**
55: * Obtain lock on record being read.
56: * <p>
57: * Assumes that a table level IS has been acquired. Will acquire a Shared
58: * or Update lock on the row, depending on the "forUpdate" parameter.
59: * <p>
60: * Read lock will be acquired using zeroDuration lock.
61: *
62: * @param t The transaction to associate the lock with.
63: * @param record The record to be locked.
64: * @param waitForLock Should lock request wait until granted?
65: * @param forUpdate Whether to open for read or write access.
66: *
67: * @return true if the lock was granted, false if waitForLock was false
68: * and the lock could not be granted.
69: *
70: * @exception StandardException Standard exception policy.
71: **/
72: public boolean lockRecordForRead(Transaction t,
73: ContainerHandle container_handle, RecordHandle record,
74: boolean waitForLock, boolean forUpdate)
75: throws StandardException {
76: // RESOLVE - figure out what is right for update locks, for now throw
77: // if they are used.
78: if (SanityManager.DEBUG) {
79: SanityManager.ASSERT(!forUpdate);
80: }
81:
82: return (lf.zeroDurationlockObject(t.getCompatibilitySpace(),
83: record, (forUpdate ? RowLock.RU2 : RowLock.RS2),
84: waitForLock ? C_LockFactory.TIMED_WAIT
85: : C_LockFactory.NO_WAIT));
86: }
87:
88: public void unlockRecordAfterRead(Transaction t,
89: ContainerHandle container_handle, RecordHandle record,
90: boolean forUpdate, boolean row_qualified) {
91: return;
92: }
93: }
|