KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.RowLocking2nohold
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
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 /**
41     A locking policy that implements row level locking with isolation degree 2,
42     never holding read locks after they are granted.
43
44     Exactly the same as RowLocking2, except that read locks are acquired using
45     zeroDuration locks, which are immediately released by the lock manager
46     after they are granted.
47
48     @see org.apache.derby.iapi.store.raw.LockingPolicy
49 */

50 public class RowLocking2nohold extends RowLocking2
51 {
52     protected RowLocking2nohold(LockFactory lf)
53     {
54         super(lf);
55     }
56
57     /**
58      * Obtain lock on record being read.
59      * <p>
60      * Assumes that a table level IS has been acquired. Will acquire a Shared
61      * or Update lock on the row, depending on the "forUpdate" parameter.
62      * <p>
63      * Read lock will be acquired using zeroDuration lock.
64      *
65      * @param t The transaction to associate the lock with.
66      * @param record The record to be locked.
67      * @param waitForLock Should lock request wait until granted?
68      * @param forUpdate Whether to open for read or write access.
69      *
70      * @return true if the lock was granted, false if waitForLock was false
71      * and the lock could not be granted.
72      *
73      * @exception StandardException Standard exception policy.
74      **/

75     public boolean lockRecordForRead(
76     Transaction t,
77     ContainerHandle container_handle,
78     RecordHandle record,
79     boolean waitForLock,
80     boolean forUpdate)
81         throws StandardException
82     {
83         // RESOLVE - figure out what is right for update locks, for now throw
84
// if they are used.
85
if (SanityManager.DEBUG)
86         {
87             SanityManager.ASSERT(!forUpdate);
88         }
89
90         return(lf.zeroDurationlockObject(
91                 t.getCompatibilitySpace(),
92                 record,
93                 (forUpdate ? RowLock.RU2 : RowLock.RS2),
94                 waitForLock ?
95                     C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT));
96     }
97
98     public void unlockRecordAfterRead(
99     Transaction t,
100     ContainerHandle container_handle,
101     RecordHandle record,
102     boolean forUpdate,
103     boolean row_qualified)
104     {
105         return;
106     }
107 }
108
Popular Tags