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.RecordHandle; 33 import org.apache.derby.iapi.store.raw.RowLock; 34 import org.apache.derby.iapi.store.raw.Transaction; 35 import org.apache.derby.iapi.store.raw.LockingPolicy; 36 37 import org.apache.derby.iapi.error.StandardException; 38 39 40 45 public class RowLocking3 extends NoLocking 46 { 47 private static final LockingPolicy NO_LOCK = new NoLocking(); 50 51 protected final LockFactory lf; 52 53 protected RowLocking3(LockFactory lf) 54 { 55 this.lf = lf; 56 } 57 58 68 protected RowLock getReadLockType() 69 { 70 return(RowLock.RS3); 71 } 72 73 83 protected RowLock getUpdateLockType() 84 { 85 return(RowLock.RU3); 86 } 87 88 98 protected RowLock getWriteLockType() 99 { 100 return(RowLock.RX3); 101 } 102 103 104 126 public boolean lockContainer( 127 Transaction t, 128 ContainerHandle container, 129 boolean waitForLock, 130 boolean forUpdate) 131 throws StandardException 132 { 133 Object qualifier = forUpdate ? ContainerLock.CIX : ContainerLock.CIS; 134 135 boolean gotLock = 136 lf.lockObject( 137 t.getCompatibilitySpace(), t, container.getId(), qualifier, 138 waitForLock ? C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT); 139 140 if (gotLock) { 141 145 if (lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(), ContainerLock.CX) || 146 ((!forUpdate) && lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(), ContainerLock.CS))) { 147 148 149 container.setLockingPolicy(NO_LOCK); 150 } 151 } 152 153 return gotLock; 154 155 } 156 157 158 175 public boolean lockRecordForRead( 176 Transaction t, 177 ContainerHandle container_handle, 178 RecordHandle record, 179 boolean waitForLock, 180 boolean forUpdate) 181 throws StandardException 182 { 183 185 Object qualifier = forUpdate ? getUpdateLockType() : getReadLockType(); 187 188 return( 189 lf.lockObject( 190 t.getCompatibilitySpace(), t, record, qualifier, 191 waitForLock ? 192 C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); 193 } 194 195 208 public void lockRecordForRead( 209 Latch latch, 210 RecordHandle record, 211 boolean forUpdate) 212 throws StandardException 213 { 214 216 Object qualifier = forUpdate ? getUpdateLockType() : getReadLockType(); 218 219 lf.lockObject( 220 latch.getCompatabilitySpace(), record, qualifier, 221 C_LockFactory.TIMED_WAIT, latch); 222 } 223 224 241 public boolean zeroDurationLockRecordForWrite( 242 Transaction t, 243 RecordHandle record, 244 boolean lockForInsertPreviousKey, 245 boolean waitForLock) 246 throws StandardException 247 { 248 return(lf.zeroDurationlockObject( 249 t.getCompatibilitySpace(), record, 250 (lockForInsertPreviousKey ? RowLock.RIP : getWriteLockType()), 251 waitForLock ? C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); 252 } 253 254 271 public boolean lockRecordForWrite( 272 Transaction t, 273 RecordHandle record, 274 boolean lockForInsert, 275 boolean waitForLock) 276 throws StandardException 277 { 278 return(lf.lockObject( 279 t.getCompatibilitySpace(), t, record, 280 lockForInsert ? RowLock.RI : getWriteLockType(), 281 waitForLock ? C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); 282 } 283 284 296 public void lockRecordForWrite( 297 Latch latch, 298 RecordHandle record) 299 throws StandardException 300 { 301 lf.lockObject( 302 latch.getCompatabilitySpace(), 303 record, 304 getWriteLockType(), 305 C_LockFactory.TIMED_WAIT, 306 latch); 307 } 308 309 public int getMode() { 310 return MODE_RECORD; 311 } 312 313 314 318 } 319 | Popular Tags |