@SuppressWarnings({ "rawtypes", "unchecked" })
	public void lock(TransactionId tid, Permissions permission) throws TransactionAbortedException
	{
		if (permission == Permissions.READ_ONLY)
		{
			if (lock.getReadHoldCount() == 0)
			{
				try
				{
					while(!lock.readLock().tryLock())
					{
						wait();
					}
				}
				catch(InterruptedException e)
				{
					throw new TransactionAbortedException(tid + " aborted");
				}
			}
		}
		else
		{
			if (lock.getWriteHoldCount() == 0)
			{
				if (!lock.writeLock().tryLock())
				{
					if (!tryUpgradeLock(tid))
					{
						try
						{
							while(!lock.writeLock().tryLock())
							{
								wait();
							}
						}
						catch(InterruptedException e)
						{
							throw new TransactionAbortedException(tid + " aborted");
						}
					}
				}
			}
		}
	}