KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > lock > HeldLock


1 package com.quadcap.sql.lock;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import com.quadcap.util.Debug;
42
43 /**
44  *
45  *
46  * @author Stan Bailes
47  */

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 JavaDoc("a is null");
71         if (b == null) throw new RuntimeException JavaDoc("b is null");
72         if (!a.live) throw new RuntimeException JavaDoc("a not live: " + a);
73         if (!b.live) throw new RuntimeException JavaDoc("b not live: " + b);
74         if (a.trans == null) throw new RuntimeException JavaDoc("a.trans is null");
75         if (b.trans == null) throw new RuntimeException JavaDoc("b.trans is null");
76         if (!a.trans.live) throw new RuntimeException JavaDoc("a trans not live: " + a);
77         if (!b.trans.live) throw new RuntimeException JavaDoc("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 JavaDoc toString() {
98 // StringBuffer sb = new StringBuffer("HeldLock");
99
// sb.append(super.toString());
100
// sb.append(String.valueOf(trans)).append(", ");
101
// sb.append(lock).append(", ");
102
// sb.append(LockMode.toString(mode)).append(" (W ");
103
// sb.append(LockMode.toString(waitMode)).append(")");
104
// return sb.toString();
105
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