KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.RowLocking1
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 1.
42
43     This is an implementation of Gray's degree 1 isolation, read uncommitted,
44     or often referred to as dirty reads. Basically read operations are
45     done with no locking.
46
47     This locking policy is only to be used for read operations.
48
49     The approach is to place all "write" container and row locks on the
50     transaction group lock list. Locks on this group will last until end
51     of transaction.
52
53     This implementation will still get table level intent locks. This is to
54     prevent hard cases where the container otherwise could be deleted while
55     read uncommitted reader is still accessing it. In order to not get table
56     level intent locks some sort of other ddl level lock would have to be
57     implemented.
58
59     All "read" row locks will be not be requested.
60
61     Note that write operations extend from the RowLocking3 implementations.
62
63     @see org.apache.derby.iapi.store.raw.LockingPolicy
64 */

65 public class RowLocking1 extends RowLocking2
66 {
67
68     protected RowLocking1(LockFactory lf)
69     {
70         super(lf);
71     }
72
73     /**
74      * Obtain lock on record being read.
75      * <p>
76      * Assumes that a table level IS has been acquired. Will acquire a Shared
77      * or Update lock on the row, depending on the "forUpdate" parameter.
78      * <p>
79      * Read lock will be placed on separate group from transaction.
80      *
81      * @param t The transaction to associate the lock with.
82      * @param record The record to be locked.
83      * @param waitForLock Should lock request wait until granted?
84      * @param forUpdate Whether to open for read or write access.
85      *
86      * @return true if the lock was granted, false if waitForLock was false
87      * and the lock could not be granted.
88      *
89      * @exception StandardException Standard exception policy.
90      **/

91     public boolean lockRecordForRead(
92     Transaction t,
93     ContainerHandle container_handle,
94     RecordHandle record,
95     boolean waitForLock,
96     boolean forUpdate)
97         throws StandardException
98     {
99
100         return(
101             !forUpdate ?
102                 true :
103                 super.lockRecordForRead(
104                     t, container_handle, record, waitForLock, forUpdate));
105     }
106
107     /**
108      * Obtain lock on record being read while holding a latch.
109      * <p>
110      * Assumes that a table level IS has been acquired. Will acquire a Shared
111      * or Update lock on the row, depending on the "forUpdate" parameter.
112      * <p>
113      *
114      * @param latch The latch being held.
115      * @param record The record to be locked.
116      * @param forUpdate Whether to open for read or write access.
117      *
118      * @exception StandardException Standard exception policy.
119      **/

120     public void lockRecordForRead(
121     Latch latch,
122     RecordHandle record,
123     boolean forUpdate)
124         throws StandardException
125     {
126         if (forUpdate)
127             super.lockRecordForRead(latch, record, forUpdate);
128     }
129
130     public void unlockRecordAfterRead(
131     Transaction t,
132     ContainerHandle container_handle,
133     RecordHandle record,
134     boolean forUpdate,
135     boolean row_qualified)
136         throws StandardException
137     {
138         if (forUpdate)
139         {
140             super.unlockRecordAfterRead(
141                 t, container_handle, record, forUpdate, row_qualified);
142         }
143         return;
144     }
145 }
146
Popular Tags