001: package com.quadcap.sql.lock;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import com.quadcap.util.Debug;
042:
043: /**
044: *
045: *
046: * @author Stan Bailes
047: */
048: class HeldLock extends PooledObject {
049: Lock lock;
050: Transaction trans;
051: int mode;
052: int waitMode;
053:
054: protected HeldLock() {
055: }
056:
057: public void init(Transaction trans, Lock lock, int mode) {
058: this .trans = trans;
059: this .lock = lock;
060: this .mode = mode;
061: this .waitMode = mode;
062: }
063:
064: final void setWaitMode(int mode) {
065: this .waitMode = mode;
066: }
067:
068: final int getWaitMode() {
069: return waitMode;
070: }
071:
072: final Transaction getTransaction() {
073: return trans;
074: }
075:
076: public final PooledObject create() {
077: return new HeldLock();
078: }
079:
080: static int compare(HeldLock a, HeldLock b) {
081: if (a == null)
082: throw new RuntimeException("a is null");
083: if (b == null)
084: throw new RuntimeException("b is null");
085: if (!a.live)
086: throw new RuntimeException("a not live: " + a);
087: if (!b.live)
088: throw new RuntimeException("b not live: " + b);
089: if (a.trans == null)
090: throw new RuntimeException("a.trans is null");
091: if (b.trans == null)
092: throw new RuntimeException("b.trans is null");
093: if (!a.trans.live)
094: throw new RuntimeException("a trans not live: " + a);
095: if (!b.trans.live)
096: throw new RuntimeException("b trans not live: " + b);
097: if (a.trans.getTransactionId() < b.trans.getTransactionId())
098: return -1;
099: if (a.trans.getTransactionId() > b.trans.getTransactionId())
100: return 1;
101: if (a.lock == null) {
102: return (b.lock == null) ? 0 : -1;
103: }
104: if (b.lock == null)
105: return 1;
106: if (a.lock.hashCode() < b.lock.hashCode())
107: return -1;
108: if (a.lock.hashCode() > b.lock.hashCode())
109: return 1;
110: if (a.mode < b.mode)
111: return -1;
112: if (a.mode > b.mode)
113: return 1;
114: if (a.waitMode < b.waitMode)
115: return -1;
116: if (a.waitMode > b.waitMode)
117: return 1;
118: return 0;
119: }
120:
121: public String toString() {
122: // StringBuffer sb = new StringBuffer("HeldLock");
123: // sb.append(super.toString());
124: // sb.append(String.valueOf(trans)).append(", ");
125: // sb.append(lock).append(", ");
126: // sb.append(LockMode.toString(mode)).append(" (W ");
127: // sb.append(LockMode.toString(waitMode)).append(")");
128: // return sb.toString();
129: if (lock == null) {
130: return "HeldLock{}";
131: } else {
132: return "HeldLock{" + lock.getName() + "," + trans + ","
133: + LockMode.toString(mode) + "}";
134: }
135: }
136: }
|