1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: LockMode.java,v 12.9 2008/04/14 15:31:27 bschmeck Exp $ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbConstants; 12 13/** 14Locking modes for database operations. Locking modes are required 15parameters for operations that retrieve data or modify the database. 16*/ 17public final class LockMode { 18 private String lockModeName; 19 private int flag; 20 21 private LockMode(String lockModeName, int flag) { 22 this.lockModeName = lockModeName; 23 this.flag = flag; 24 } 25 26 /** 27 Acquire read locks for read operations and write locks for write 28 operations. 29 */ 30 public static final LockMode DEFAULT = 31 new LockMode("DEFAULT", 0); 32 /** 33 Read modified but not yet committed data. 34 */ 35 public static final LockMode READ_UNCOMMITTED = 36 new LockMode("READ_UNCOMMITTED", DbConstants.DB_READ_UNCOMMITTED); 37 /** 38 Read committed isolation provides for cursor stability but not repeatable 39 reads. Data items which have been previously read by this transaction may 40 be deleted or modified by other transactions before the cursor is closed or 41 the transaction completes. 42 <p> 43 Note that this LockMode may only be passed to {@link Database} get 44 methods, not to {@link Cursor} methods. To configure a cursor for 45 Read committed isolation, use {@link CursorConfig#setReadCommitted}. 46 */ 47 public static final LockMode READ_COMMITTED = 48 new LockMode("READ_COMMITTED", DbConstants.DB_READ_COMMITTED); 49 /** 50 Acquire write locks instead of read locks when doing the retrieval. 51 Setting this flag can eliminate deadlock during a read-modify-write 52 cycle by acquiring the write lock during the read part of the cycle 53 so that another thread of control acquiring a read lock for the same 54 item, in its own read-modify-write cycle, will not result in deadlock. 55 */ 56 public static final LockMode RMW = 57 new LockMode("RMW", DbConstants.DB_RMW); 58 59 /** 60 Read modified but not yet committed data. 61 <p> 62 @deprecated This has been replaced by {@link #READ_UNCOMMITTED} to conform to ANSI 63 database isolation terminology. 64 */ 65 public static final LockMode DIRTY_READ = READ_UNCOMMITTED; 66 /** 67 Read committed isolation provides for cursor stability but not repeatable 68 reads. Data items which have been previously read by this transaction may 69 be deleted or modified by other transactions before the cursor is closed or 70 the transaction completes. 71 <p> 72 Note that this LockMode may only be passed to {@link Database} get 73 methods, not to {@link Cursor} methods. To configure a cursor for 74 Read committed isolation, use {@link CursorConfig#setReadCommitted}. 75 <p> 76 @deprecated This has been replaced by {@link #READ_COMMITTED} to conform to ANSI 77 database isolation terminology. 78 */ 79 public static final LockMode DEGREE_2 = READ_COMMITTED; 80 81 /** 82 Return the data item irrespective of the state of master leases. The item 83 will be returned under all conditions: if master leases are not configured, 84 if the request is made to a client, if the request is made to a master with 85 a valid lease, or if the request is made to a master without a valid lease. 86 */ 87 public static final LockMode IGNORE_LEASES = 88 new LockMode("IGNORE_LEASES", DbConstants.DB_IGNORE_LEASE); 89 90 /** {@inheritDoc} */ 91 public String toString() { 92 return "LockMode." + lockModeName; 93 } 94 95 /* package */ 96 static int getFlag(LockMode mode) { 97 return ((mode == null) ? DEFAULT : mode).flag; 98 } 99} 100