1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2014 Oracle and/or its affiliates.  All rights reserved.
5  *
6  */
7 
8 package com.sleepycat.je.txn;
9 
10 import com.sleepycat.je.utilint.DbLsn;
11 
12 /**
13  * LockResult is the return type of Locker.lock(). It encapsulates a
14  * LockGrantType (the return type of LockManager.lock()) and a WriteLockInfo.
15  *
16  * The WriteLockInfo field is non-null if (a) the locker is transactional, and
17  * (b) the request was for a WRITE or WRITE_RANGE lock, and (c) the request was
18  * not a non-blocking request that got denied. If so, the WriteLockInfo is
19  * either a newly created one or a pre-existing one if the same locker had
20  * write-locked the same LSN before.
21  */
22 public class LockResult {
23     private LockGrantType grant;
24     private WriteLockInfo info;
25 
26     /* Made public for unittests */
LockResult(LockGrantType grant, WriteLockInfo info)27     public LockResult(LockGrantType grant, WriteLockInfo info) {
28         this.grant = grant;
29         this.info = info;
30     }
31 
getLockGrant()32     public LockGrantType getLockGrant() {
33         return grant;
34     }
35 
getWriteLockInfo()36     public WriteLockInfo getWriteLockInfo() {
37         return info;
38     }
39 
setAbortLsn(long abortLsn, boolean abortKnownDeleted)40     public void setAbortLsn(long abortLsn, boolean abortKnownDeleted) {
41         /* Do not overwrite abort info if this locker previously . */
42         if (info != null && info.getNeverLocked()) {
43             if (abortLsn != DbLsn.NULL_LSN) {
44                 info.setAbortLsn(abortLsn);
45                 info.setAbortKnownDeleted(abortKnownDeleted);
46             }
47             info.setNeverLocked(false);
48         }
49     }
50 
51     /**
52      * Used to copy write lock info when an LSN is changed.
53      */
copyWriteLockInfo(WriteLockInfo fromInfo)54     public void copyWriteLockInfo(WriteLockInfo fromInfo) {
55         if (fromInfo != null && info != null) {
56             setAbortLsn(fromInfo.getAbortLsn(),
57                         fromInfo.getAbortKnownDeleted());
58             info.copyAbortInfo(fromInfo);
59         }
60     }
61 }
62