Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LockEntry |
|
| 1.0;1 |
1 | package org.apache.ojb.odmg.locking; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | import org.apache.ojb.odmg.TransactionImpl; | |
19 | ||
20 | import java.io.Serializable; | |
21 | ||
22 | /** | |
23 | * a persistent entry for locks. All locks that are hold from | |
24 | * transaction on objects are represented by a LockENtry and made | |
25 | * persistent to the database. | |
26 | * @author Thomas Mahler | |
27 | */ | |
28 | public class LockEntry implements Serializable | |
29 | { | |
30 | static final long serialVersionUID = 8060850552557793930L; /** | |
31 | * marks a Read Lock. | |
32 | */ | |
33 | public static int LOCK_READ = 0; | |
34 | ||
35 | /** | |
36 | * marks a Write Lock. | |
37 | */ | |
38 | public static int LOCK_WRITE = 1; | |
39 | ||
40 | /** | |
41 | * the unique OID of the object to be locked. | |
42 | */ | |
43 | private String oidString; | |
44 | ||
45 | /** | |
46 | * the GUID of the transaction that holds the lock | |
47 | */ | |
48 | private String transactionId; | |
49 | ||
50 | /** | |
51 | * the timestamp marking the time of acquisition of this lock | |
52 | */ | |
53 | private long timestamp; | |
54 | ||
55 | /** | |
56 | * the isolationlevel for this lock. | |
57 | */ | |
58 | private int isolationLevel; | |
59 | ||
60 | /** | |
61 | * marks if this is a read or a write lock. | |
62 | * LOCK_READ = 0; | |
63 | * LOCK_WRITE = 1; | |
64 | */ | |
65 | private int lockType; | |
66 | ||
67 | /** | |
68 | * Multiargument constructor for fast loading of LockEntries by OJB. | |
69 | */ | |
70 | public LockEntry(String oidString, | |
71 | String transactionId, | |
72 | long timestamp, | |
73 | int isolationLevel, | |
74 | int lockType) | |
75 | { | |
76 | this.oidString = oidString; | |
77 | this.transactionId = transactionId; | |
78 | this.timestamp = timestamp; | |
79 | this.isolationLevel = isolationLevel; | |
80 | this.lockType = lockType; | |
81 | ||
82 | } | |
83 | ||
84 | /** | |
85 | * build a LockEntry from an OID and a Transaction ID | |
86 | */ | |
87 | public LockEntry(String oidString, String transactionId) | |
88 | { | |
89 | this.oidString = oidString; | |
90 | this.transactionId = transactionId; | |
91 | } | |
92 | ||
93 | /** | |
94 | * default constructor | |
95 | */ | |
96 | public LockEntry() | |
97 | { | |
98 | } | |
99 | ||
100 | /** | |
101 | * returns the OID STring of the locked object. | |
102 | */ | |
103 | public String getOidString() | |
104 | { | |
105 | return oidString; | |
106 | } | |
107 | ||
108 | /** | |
109 | * returns the GUID string of the locking transaction. | |
110 | */ | |
111 | public String getTransactionId() | |
112 | { | |
113 | return transactionId; | |
114 | } | |
115 | ||
116 | /** | |
117 | * returns the timestamp of the acqusition of the lock. | |
118 | */ | |
119 | public long getTimestamp() | |
120 | { | |
121 | return timestamp; | |
122 | } | |
123 | ||
124 | /** | |
125 | * returns the isolation level of this lock | |
126 | */ | |
127 | public int getIsolationLevel() | |
128 | { | |
129 | return isolationLevel; | |
130 | } | |
131 | ||
132 | /** | |
133 | * returns the locktype of this lock. | |
134 | * @return LOCK_READ if lock is a readlock, | |
135 | * LOCK_WRITE if lock is a Write lock. | |
136 | */ | |
137 | public int getLockType() | |
138 | { | |
139 | return lockType; | |
140 | } | |
141 | ||
142 | /** | |
143 | * sets the locktype of this lockentry. | |
144 | * @param locktype LOCK_READ for read, LOCK_WRITE for write lock. | |
145 | */ | |
146 | public void setLockType(int locktype) | |
147 | { | |
148 | this.lockType = locktype; | |
149 | } | |
150 | ||
151 | /** | |
152 | * returns true if this lock is owned by transaction tx, else false. | |
153 | */ | |
154 | public boolean isOwnedBy(TransactionImpl tx) | |
155 | { | |
156 | return this.getTransactionId().equals(tx.getGUID()); | |
157 | } | |
158 | ||
159 | ||
160 | /** | |
161 | * Sets the isolationLevel. | |
162 | * @param isolationLevel The isolationLevel to set | |
163 | */ | |
164 | public void setIsolationLevel(int isolationLevel) | |
165 | { | |
166 | this.isolationLevel = isolationLevel; | |
167 | } | |
168 | ||
169 | /** | |
170 | * Sets the oidString. | |
171 | * @param oidString The oidString to set | |
172 | */ | |
173 | public void setOidString(String oidString) | |
174 | { | |
175 | this.oidString = oidString; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Sets the timestamp. | |
180 | * @param timestamp The timestamp to set | |
181 | */ | |
182 | public void setTimestamp(long timestamp) | |
183 | { | |
184 | this.timestamp = timestamp; | |
185 | } | |
186 | ||
187 | /** | |
188 | * Sets the transactionId. | |
189 | * @param transactionId The transactionId to set | |
190 | */ | |
191 | public void setTransactionId(String transactionId) | |
192 | { | |
193 | this.transactionId = transactionId; | |
194 | } | |
195 | ||
196 | } |