1 package com.quadcap.sql.lock; 2 3 40 41 import com.quadcap.util.Debug; 42 43 48 class HeldLock extends PooledObject { 49 Lock lock; 50 Transaction trans; 51 int mode; 52 int waitMode; 53 54 protected HeldLock() {} 55 56 public void init(Transaction trans, Lock lock, int mode) { 57 this.trans = trans; 58 this.lock = lock; 59 this.mode = mode; 60 this.waitMode = mode; 61 } 62 63 final void setWaitMode(int mode) { this.waitMode = mode; } 64 final int getWaitMode() { return waitMode; } 65 final Transaction getTransaction() { return trans; } 66 67 public final PooledObject create() { return new HeldLock(); } 68 69 static int compare(HeldLock a, HeldLock b) { 70 if (a == null) throw new RuntimeException ("a is null"); 71 if (b == null) throw new RuntimeException ("b is null"); 72 if (!a.live) throw new RuntimeException ("a not live: " + a); 73 if (!b.live) throw new RuntimeException ("b not live: " + b); 74 if (a.trans == null) throw new RuntimeException ("a.trans is null"); 75 if (b.trans == null) throw new RuntimeException ("b.trans is null"); 76 if (!a.trans.live) throw new RuntimeException ("a trans not live: " + a); 77 if (!b.trans.live) throw new RuntimeException ("b trans not live: " + b); 78 if (a.trans.getTransactionId() 79 < b.trans.getTransactionId()) 80 return -1; 81 if (a.trans.getTransactionId() 82 > b.trans.getTransactionId()) 83 return 1; 84 if (a.lock == null) { 85 return (b.lock == null) ? 0 : -1; 86 } 87 if (b.lock == null) return 1; 88 if (a.lock.hashCode() < b.lock.hashCode()) return -1; 89 if (a.lock.hashCode() > b.lock.hashCode()) return 1; 90 if (a.mode < b.mode) return -1; 91 if (a.mode > b.mode) return 1; 92 if (a.waitMode < b.waitMode) return -1; 93 if (a.waitMode > b.waitMode) return 1; 94 return 0; 95 } 96 97 public String toString() { 98 if (lock == null) { 106 return "HeldLock{}"; 107 } else { 108 return "HeldLock{" + lock.getName() + "," + 109 trans + "," + LockMode.toString(mode) + "}"; 110 } 111 } 112 } 113 114 | Popular Tags |