1 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 54 public class RowLocking2 extends RowLockingRR 55 { 56 private static final LockingPolicy NO_LOCK = new NoLocking(); 59 60 protected RowLocking2(LockFactory lf) 61 { 62 super(lf); 63 } 64 65 90 public boolean lockContainer( 91 Transaction t, 92 ContainerHandle container, 93 boolean waitForLock, 94 boolean forUpdate) 95 throws StandardException 96 { 97 Object qualifier = forUpdate ? ContainerLock.CIX : ContainerLock.CIS; 98 99 Object group = 102 forUpdate ? ((Object ) t) : ((Object ) container.getUniqueId()); 103 104 boolean gotLock = 105 lf.lockObject( 106 t.getCompatibilitySpace(), group, container.getId(), qualifier, 107 waitForLock ? C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT); 108 109 if (gotLock) 110 { 111 118 119 if (lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(), 120 ContainerLock.CX)) 121 { 122 lf.unlockGroup(t.getCompatibilitySpace(), container.getUniqueId()); 124 container.setLockingPolicy(NO_LOCK); 125 }else if ((!forUpdate) && 126 lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(), ContainerLock.CS)) 127 { 128 lf.transfer(t.getCompatibilitySpace(), group, t); 130 container.setLockingPolicy(NO_LOCK); 131 } 132 } 133 134 return gotLock; 135 } 136 137 138 156 public boolean lockRecordForRead( 157 Transaction t, 158 ContainerHandle container_handle, 159 RecordHandle record, 160 boolean waitForLock, 161 boolean forUpdate) 162 throws StandardException 163 { 164 Object qualifier = forUpdate ? RowLock.RU2 : RowLock.RS2; 165 166 return( 167 lf.lockObject( 168 t.getCompatibilitySpace(), 169 container_handle.getUniqueId(), 170 record, 171 qualifier, 172 waitForLock ? 173 C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); 174 } 175 176 189 public void lockRecordForRead( 190 Latch latch, 191 RecordHandle record, 192 boolean forUpdate) 193 throws StandardException 194 { 195 199 Object qualifier = forUpdate ? RowLock.RU2 : RowLock.RS2; 200 201 lf.lockObject( 202 record.getContainerId(), record, qualifier, 203 C_LockFactory.TIMED_WAIT, latch); 204 } 205 206 public void unlockRecordAfterRead( 207 Transaction t, 208 ContainerHandle container_handle, 209 RecordHandle record, 210 boolean forUpdate, 211 boolean row_qualified) 212 throws StandardException 213 { 214 Object qualifier = forUpdate ? RowLock.RU2 : RowLock.RS2; 215 216 int count = 217 lf.unlock( 218 t.getCompatibilitySpace(), container_handle.getUniqueId(), 219 record, qualifier); 220 221 if (SanityManager.DEBUG) 222 { 223 if (!(count == 1 || count == 0)) 225 { 226 SanityManager.THROWASSERT( 227 "count = " + count + 228 "record.getContainerId() = " + record.getContainerId()); 229 } 230 } 231 } 232 233 243 public void unlockContainer( 244 Transaction t, 245 ContainerHandle container_handle) 246 { 247 lf.unlockGroup( 249 t.getCompatibilitySpace(), container_handle.getUniqueId()); 250 } 251 } 252 | Popular Tags |