001: package org.apache.ojb.odmg.locking;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.ojb.odmg.TransactionImpl;
019:
020: import java.io.Serializable;
021:
022: /**
023: * a persistent entry for locks. All locks that are hold from
024: * transaction on objects are represented by a LockENtry and made
025: * persistent to the database.
026: * @author Thomas Mahler
027: */
028: public class LockEntry implements Serializable {
029: static final long serialVersionUID = 8060850552557793930L;
030: /**
031: * marks a Read Lock.
032: */
033: public static int LOCK_READ = 0;
034:
035: /**
036: * marks a Write Lock.
037: */
038: public static int LOCK_WRITE = 1;
039:
040: /**
041: * the unique OID of the object to be locked.
042: */
043: private String oidString;
044:
045: /**
046: * the GUID of the transaction that holds the lock
047: */
048: private String transactionId;
049:
050: /**
051: * the timestamp marking the time of acquisition of this lock
052: */
053: private long timestamp;
054:
055: /**
056: * the isolationlevel for this lock.
057: */
058: private int isolationLevel;
059:
060: /**
061: * marks if this is a read or a write lock.
062: * LOCK_READ = 0;
063: * LOCK_WRITE = 1;
064: */
065: private int lockType;
066:
067: /**
068: * Multiargument constructor for fast loading of LockEntries by OJB.
069: */
070: public LockEntry(String oidString, String transactionId,
071: long timestamp, int isolationLevel, int lockType) {
072: this .oidString = oidString;
073: this .transactionId = transactionId;
074: this .timestamp = timestamp;
075: this .isolationLevel = isolationLevel;
076: this .lockType = lockType;
077:
078: }
079:
080: /**
081: * build a LockEntry from an OID and a Transaction ID
082: */
083: public LockEntry(String oidString, String transactionId) {
084: this .oidString = oidString;
085: this .transactionId = transactionId;
086: }
087:
088: /**
089: * default constructor
090: */
091: public LockEntry() {
092: }
093:
094: /**
095: * returns the OID STring of the locked object.
096: */
097: public String getOidString() {
098: return oidString;
099: }
100:
101: /**
102: * returns the GUID string of the locking transaction.
103: */
104: public String getTransactionId() {
105: return transactionId;
106: }
107:
108: /**
109: * returns the timestamp of the acqusition of the lock.
110: */
111: public long getTimestamp() {
112: return timestamp;
113: }
114:
115: /**
116: * returns the isolation level of this lock
117: */
118: public int getIsolationLevel() {
119: return isolationLevel;
120: }
121:
122: /**
123: * returns the locktype of this lock.
124: * @return LOCK_READ if lock is a readlock,
125: * LOCK_WRITE if lock is a Write lock.
126: */
127: public int getLockType() {
128: return lockType;
129: }
130:
131: /**
132: * sets the locktype of this lockentry.
133: * @param locktype LOCK_READ for read, LOCK_WRITE for write lock.
134: */
135: public void setLockType(int locktype) {
136: this .lockType = locktype;
137: }
138:
139: /**
140: * returns true if this lock is owned by transaction tx, else false.
141: */
142: public boolean isOwnedBy(TransactionImpl tx) {
143: return this .getTransactionId().equals(tx.getGUID());
144: }
145:
146: /**
147: * Sets the isolationLevel.
148: * @param isolationLevel The isolationLevel to set
149: */
150: public void setIsolationLevel(int isolationLevel) {
151: this .isolationLevel = isolationLevel;
152: }
153:
154: /**
155: * Sets the oidString.
156: * @param oidString The oidString to set
157: */
158: public void setOidString(String oidString) {
159: this .oidString = oidString;
160: }
161:
162: /**
163: * Sets the timestamp.
164: * @param timestamp The timestamp to set
165: */
166: public void setTimestamp(long timestamp) {
167: this .timestamp = timestamp;
168: }
169:
170: /**
171: * Sets the transactionId.
172: * @param transactionId The transactionId to set
173: */
174: public void setTransactionId(String transactionId) {
175: this.transactionId = transactionId;
176: }
177:
178: }
|