concurrencymgr.java

来自「用java语言简单实现数据库的初步功能」· Java 代码 · 共 58 行

JAVA
58
字号
package simpledb.tx.concurrency;import simpledb.file.Block;import java.util.*;/** * The concurrency manager for the transaction. * @author Edward Sciore */public class ConcurrencyMgr {		/**	 * The global lock table.  This variable is static because all transactions	 * share the same table.	 */	private static LockTable locktbl = new LockTable();	private Map<Block,String> locks  = new HashMap<Block,String>();	/**	 * Obtains an SLock on the block, if necessary.	 * @param blk a reference to the disk block	 */	public void sLock(Block blk) {		if (locks.get(blk) == null) {			locktbl.sLock(blk);			locks.put(blk, "S");		}	}	/**	 * Obtains an XLock on the block, if necessary.	 * An XLock is obtained by first getting an SLock	 * and then upgrading to an XLock.	 * @param blk a refrence to the disk block	 */	public void xLock(Block blk) {		if (!hasXLock(blk)) {			sLock(blk);			locktbl.xLock(blk);			locks.put(blk, "X");		}	}	/**	 * Releases all locks.	 */	public void release() {		for (Block blk : locks.keySet())			locktbl.unlock(blk);		locks.clear();	}	private boolean hasXLock(Block blk) {		String locktype = locks.get(blk);		return locktype != null && locktype.equals("X");	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?