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

📄 xact.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			//SanityManager.ASSERT(myGlobalId == null, "my globalId is not null");            if (!(state == IDLE || state == Xact.ACTIVE ||                   (state== CLOSED && justCreated)))            {                SanityManager.THROWASSERT(                    "my state is not idle nor active " + state);            }		}		myGlobalId = extid;		myId = localid;		if (SanityManager.DEBUG)		{			if (SanityManager.DEBUG_ON("XATrace") && extid != null)            {				SanityManager.DEBUG(                    "XATrace","setting xid: " + myId + " " + myGlobalId 							   + " state " + state + " " + this);                SanityManager.showTrace(new Throwable());                // Thread.dumpStack();            }		}	}	public void setTransactionId(Loggable beginXact, TransactionId localId)	{		if (SanityManager.DEBUG) {			// SanityManager.ASSERT(myId == null);			SanityManager.ASSERT((state == IDLE) || (state == ACTIVE));			SanityManager.ASSERT(beginXact instanceof BeginXact);		}		myId = localId;		myGlobalId = ((BeginXact)beginXact).getGlobalId();	}	/*	** Methods of Transaction	*/	/**		The default value for LOCKS_ESCALATION_THRESHOLD		@exception StandardException  Standard cloudscape exception policy	 */	public void setup(PersistentSet set)		throws StandardException {		int escalationThreshold = PropertyUtil.getServiceInt(set,			Property.LOCKS_ESCALATION_THRESHOLD,			Property.MIN_LOCKS_ESCALATION_THRESHOLD,			Integer.MAX_VALUE,			Property.DEFAULT_LOCKS_ESCALATION_THRESHOLD);		getLockFactory().setLimit(this, this, escalationThreshold, this);	}	/**		get the Global (external to raw store) transaction id that is unique		across all raw stores	*/	public final GlobalTransactionId getGlobalId()     {		return myGlobalId;	}	public final ContextManager getContextManager()     {		return(xc.getContextManager());	}    /**     * Get the compatibility space of the transaction.     * <p>     * Returns an object that can be used with the lock manager to provide     * the compatibility space of a transaction.  2 transactions with the     * same compatibility space will not conflict in locks.  The usual case     * is that each transaction has it's own unique compatibility space.     * <p>     *	 * @return The compatibility space of the transaction.     **/    public Object getCompatibilitySpace()    {        if (SanityManager.DEBUG)        {			SanityManager.ASSERT(                compatibilitySpace != null,                 "cannot have a null compatibilitySpace.");        }        return(this.compatibilitySpace);    }	/**		get the short (internal to raw store) transaction id that is unique		only for this raw store	*/	public final TransactionId getId() {		if (SanityManager.DEBUG)			SanityManager.ASSERT(                myId != null, "cannot have a transaction with null id");		return myId;	}	/**		Get the transaction id without sanity check, this should only be called		by a cloned TransactionTableEntry 	 */	protected final TransactionId getIdNoCheck()	{		return myId;	}	/**		Get my transaction context Id	*/	public final String getContextId() 	{		return (xc == null) ? null : xc.getIdName();	}	/**		Get the current default locking policy for all operations within this		transaction. The transaction is initially started with a default		locking policy equivalent to		<PRE>			 newLockingPolicy(              LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true);		</PRE>        This default can be changed by subsequent calls to         setDefaultLockingPolicy(LockingPolicy policy).	    @see Transaction#getDefaultLockingPolicy		@return The current default locking policy in this transaction.	*/	public LockingPolicy getDefaultLockingPolicy()    {        return(defaultLocking);    }	/** @see Transaction#newLockingPolicy */	public final LockingPolicy newLockingPolicy(int mode, int isolation, boolean stricterOk) {		return xactFactory.getLockingPolicy(mode, isolation, stricterOk);	}	/** @see Transaction#setDefaultLockingPolicy */	public final void setDefaultLockingPolicy(LockingPolicy policy) {		if (policy == null)			policy = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false);		defaultLocking = policy;	}		/** 	  @exception StandardException  Standard cloudscape exception policy	*/	public LogInstant commit() throws StandardException	{		return commit(COMMIT_SYNC);	}	/** 	  @exception StandardException  Standard cloudscape exception policy	*/	public LogInstant commitNoSync(int commitflag) throws StandardException	{		if (SanityManager.DEBUG)		{			int checkflag = Transaction.RELEASE_LOCKS|Transaction.KEEP_LOCKS;			SanityManager.ASSERT((commitflag & checkflag) != 0, 			  "commitNoSync must specify whether to keep or release locks");			SanityManager.ASSERT((commitflag & checkflag) != checkflag,			  "cannot set both RELEASE and KEEP LOCKS flag");             if ((commitflag &                  TransactionController.READONLY_TRANSACTION_INITIALIZATION)                     != 0)            {                SanityManager.ASSERT((state == IDLE) || (state == ACTIVE));            }		}		// Short circuit commit no sync if we are still initializing the		// transaction.  Before a new transaction object is returned to the		// user, it is "commit'ed" many times using commitNoSync with 		// TransactionController.READONLY_TRANSACTION_INITIALIZATION flag to		// release read locks and reset the transaction state back to Idle.  		// If nothing has actually happened to the transaction object, return		// right away and avoid the cost of going thru the commit logic.		//		if (state == IDLE && savePoints == null && 			((commitflag & TransactionController.READONLY_TRANSACTION_INITIALIZATION) != 0))			return null;		return commit(COMMIT_NO_SYNC | commitflag);	}	/** 	  @exception StandardException  Standard cloudscape exception policy	  @see Transaction#commit	*/    /**     * Do work of commit that is common to xa_prepare and commit.     * <p>     * Do all the work necessary as part of a commit up to and including     * writing the commit log record.  This routine is used by both prepare     * and commit.  The work post commit is done by completeCommit().     * <p>     *     * @param commitflag various flavors of commit.     *	 * @exception  StandardException  Standard exception policy.	 * @see Transaction#commit     **/	private LogInstant prepareCommit(int commitflag)         throws StandardException     {		LogInstant flushTo = null;		if (state == CLOSED)        {			throw StandardException.newException(                    SQLState.XACT_PROTOCOL_VIOLATION);        }		if (SanityManager.DEBUG)		{			if ((commitflag & Transaction.KEEP_LOCKS) != 0)			{                // RESOLVE (mikem) - prepare actually want's to keep locks                // during a prepare.				SanityManager.ASSERT(                    (((commitflag & COMMIT_NO_SYNC) != 0) ||                      ((commitflag & COMMIT_PREPARE) != 0)),                    "can keep locks around only in commitNoSync or prepare"); 				SanityManager.ASSERT(                    isUserTransaction(),                    "KEEP_LOCKS can only be set on user transaction commits");			}		}		try {			preComplete(COMMIT);			// flush the log.			if (seenUpdates) {				EndXact ex =                     new EndXact(                        getGlobalId(),                         ((commitflag & COMMIT_PREPARE) == 0 ?                              END_COMMITTED : END_PREPARED)                                | statusForEndXactLog());				flushTo = logger.logAndDo(this, ex);				if (xactFactory.flushLogOnCommit(xc.getIdName()))				{					if ((commitflag & COMMIT_SYNC) == 0)                    {                        // not flushing the log right now, subsequent commit                        // will need to flush the log						needSync = true;                     }					else					{						logger.flush(flushTo);						needSync = false;					}				}			}			else if (needSync && (commitflag & COMMIT_SYNC) != 0)			{				// this transaction object was used to lazily commit some				// previous transaction without syncing.  Now that we commit				// for real, make sure any outstanding log is flushed.				logger.flushAll();				needSync = false;			}		}         catch (StandardException se)         {			// This catches any exceptions that have Transaction severity			// or less (e.g. Statement exception). If we received any lesser			// error then we abort the transaction anyway.			if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY)            {				throw StandardException.newException(                        SQLState.XACT_COMMIT_EXCEPTION, se);            }			throw se;		}		return flushTo;	}    /**     * Do work to complete a commit which is not just a prepare.     * <p>     * Releases locks, does post commit work, and moves the state of the     * transaction to IDLE.     * <p>     *     * @param commitflag various flavors of commit.     *	 * @exception  StandardException  Standard exception policy.     **/	private void completeCommit(int commitflag)         throws StandardException     {		// this releases our logical locks if commitflag don't have KEEP_LOCKS.		postComplete(commitflag, COMMIT);		// this transfer postCommitWorks to PostCommit queue		if ((commitflag & Transaction.KEEP_LOCKS) == 0)		{			// if locks are released, start post commit processing			postTermination();		}		else		{			// RESOLVE: actually, this transaction may not have outstanding			// locks.  It didn't release them, but that doesn't mean it has got			// them.  This is mostly harmless.			if (SanityManager.DEBUG)				SanityManager.ASSERT(myGlobalId == null,				 "calling commit with KEEP_LOCKS on a global transaction");			// we have unreleased locks, the transaction has resource and			// therefore is "active"			setActiveState();		}		myGlobalId = null;		return;	}	/** 	  @exception StandardException  Standard cloudscape exception policy	  @see Transaction#commit	*/	private LogInstant commit(int commitflag)         throws StandardException     {		if (SanityManager.DEBUG)		{			if (SanityManager.DEBUG_ON("XATrace"))				SanityManager.DEBUG("XATrace","commiting ");		}        LogInstant flushTo = prepareCommit(commitflag);        completeCommit(commitflag);        return(flushTo);	}	/** 	    @exception StandardException  Standard cloudscape exception policy		@see Transaction#abort	*/	public void abort() throws StandardException {		if (SanityManager.DEBUG)		{			if (SanityManager.DEBUG_ON("XATrace"))				SanityManager.DEBUG("XATrace","aborting ");		}		if (state == CLOSED)		{			// I would have leave this in but close() nulls out myGlobalId			// if (myGlobalId == null)            // {			//   throw StandardException.newException(            //           SQLState.XACT_PROTOCOL_VIOLATION);            // }			if (SanityManager.DEBUG)			{				// Only global transaction is allowed to abort a closed				// transaction.				if (!sanityCheck_xaclosed)                {					throw StandardException.newException(                            SQLState.XACT_PROTOCOL_VIOLATION);                }			}			// In global transaction, the xact object is closed automatically			// on a transaction level rollback.  This cause error handling to			// fail because when upper level contexts in the context manager			// unwinds, it calls abort again, which would have caused a			// protocol violation.			return;		}		/* This routine is never called by recovery redo, only by runtime and		   recovery undo. During recovery undo, even though no log record has		   been written by this session, it still need to rollback the		   incomplete transaction.		   The way to tell if this trasanction has ever written a log record is		   by FirstLogInstant.		*/		try {			preComplete(ABORT);			// rollback the log - if logger is null, nothing I can do, crash.			if (getFirstLogInstant() != null) {				if (logger == null)                {					throw StandardException.newException(SQLState.XACT_CANNOT_ABORT_NULL_LOGGER);                }				logger.undo(                    this, getId(), getFirstLogInstant(), getLastLogInstant());				EndXact ex = new EndXact(getGlobalId(),										 END_ABORTED | statusForEndXactLog());				logger.flush(logger.logAndDo(this, ex));			}			else if (needSync)			{				// this transaction object was used to lazily commit some				// previous transaction without syncing.  Now that we abort				// for real, make sure any outstanding log is flushed.				logger.flushAll();			}			needSync = false;

⌨️ 快捷键说明

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