1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbConstants; 12 13/** 14Operations that can be performed on locks. 15*/ 16public final class LockOperation { 17 /** 18 Get the lock defined by the values of the mode and obj fields, for 19 the specified locker. Upon return from {@link com.sleepycat.db.Environment#lockVector Environment.lockVector}, if the lock field is non-null, a reference to the 20 acquired lock is stored there. (This reference is invalidated by 21 any call to {@link com.sleepycat.db.Environment#lockVector Environment.lockVector} or {@link com.sleepycat.db.Environment#putLock Environment.putLock} that releases the lock.) 22 */ 23 public static final LockOperation GET = 24 new LockOperation("GET", DbConstants.DB_LOCK_GET); 25 /** 26 Identical to LockOperation GET except that the value in the timeout 27 field overrides any previously specified timeout value for this 28 lock. A value of 0 turns off any previously specified timeout. 29 */ 30 public static final LockOperation GET_TIMEOUT = 31 new LockOperation("GET_TIMEOUT", DbConstants.DB_LOCK_GET_TIMEOUT); 32 /** 33 The lock to which the lock field refers is released. The locker, 34 mode and obj fields are ignored. 35 */ 36 public static final LockOperation PUT = 37 new LockOperation("PUT", DbConstants.DB_LOCK_PUT); 38 /** 39 All locks held by the specified locker are released. The lock, 40 mode, and obj fields are ignored. Locks acquired in operations 41 performed by the current call to {@link com.sleepycat.db.Environment#lockVector Environment.lockVector} 42 which appear before the PUT_ALL operation are released; those 43 acquired in operations appearing after the PUT_ALL operation are not 44 released. 45 */ 46 public static final LockOperation PUT_ALL = 47 new LockOperation("PUT_ALL", DbConstants.DB_LOCK_PUT_ALL); 48 /** 49 All locks held on obj are released. The locker parameter and the 50 lock and mode fields are ignored. Locks acquired in operations 51 performed by the current call to {@link com.sleepycat.db.Environment#lockVector Environment.lockVector} 52 that appear before the PUT_OBJ operation operation are released; 53 those acquired in operations appearing after the PUT_OBJ operation 54 are not released. 55 */ 56 public static final LockOperation PUT_OBJ = 57 new LockOperation("PUT_OBJ", DbConstants.DB_LOCK_PUT_OBJ); 58 /** 59 Cause the specified locker to timeout immediately. If the database 60 environment has not configured automatic deadlock detection, the 61 transaction will timeout the next time deadlock detection is 62 performed. As transactions acquire locks on behalf of a single 63 locker ID, timing out the locker ID associated with a transaction 64 will time out the transaction itself. 65 */ 66 public static final LockOperation TIMEOUT = 67 new LockOperation("TIMEOUT", DbConstants.DB_LOCK_TIMEOUT); 68 69 /* package */ 70 static LockOperation fromFlag(int flag) { 71 switch (flag) { 72 case DbConstants.DB_LOCK_GET: 73 return GET; 74 case DbConstants.DB_LOCK_GET_TIMEOUT: 75 return GET_TIMEOUT; 76 case DbConstants.DB_LOCK_PUT: 77 return PUT; 78 case DbConstants.DB_LOCK_PUT_ALL: 79 return PUT_ALL; 80 case DbConstants.DB_LOCK_PUT_OBJ: 81 return PUT_OBJ; 82 case DbConstants.DB_LOCK_TIMEOUT: 83 return TIMEOUT; 84 default: 85 throw new IllegalArgumentException( 86 "Unknown lock operation: " + flag); 87 } 88 } 89 90 private final String operationName; 91 private final int flag; 92 93 private LockOperation(final String operationName, final int flag) { 94 this.operationName = operationName; 95 this.flag = flag; 96 } 97 98 /** {@inheritDoc} */ 99 public String toString() { 100 return "LockOperation." + operationName; 101 } 102 103 /* package */ 104 int getFlag() { 105 return flag; 106 } 107} 108