⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concurrencymgr.java

📁 用java语言简单实现数据库的初步功能
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -