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

📄 xact.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		setActiveState();		dataFactory.dropContainer(this, containerId); 	}	/**	    @exception StandardException  Standard cloudscape exception policy		@see Transaction#setSavePoint	*/	public int setSavePoint(String name, Object kindOfSavepoint)         throws StandardException     {		if (kindOfSavepoint != null && kindOfSavepoint instanceof String)          {            //that means we are trying to set a SQL savepoint            //error if this SQL savepoint is getting nested into other user             // defined savepoints			throwExceptionIfSQLSavepointNotAllowed(kindOfSavepoint);        }		// while setting a savepoint, we just want to see if there is a         // savepoint with the passed name already in the system.		if (getSavePointPosition(name, kindOfSavepoint, false) != -1)        {			throw StandardException.newException(                    SQLState.XACT_SAVEPOINT_EXISTS);        }		if (savePoints == null)			savePoints = new Stack();		savePoints.push(new SavePoint(name, kindOfSavepoint));		if (SanityManager.DEBUG) {			if (SanityManager.DEBUG_ON("memoryLeakTrace")) {				if (savePoints.size() > 20)					System.out.println("memoryLeakTrace:Xact:savepoints " + savePoints.size());			}		}		return savePoints.size();	}	// SQL savepoint can't be nested inside other user defined savepoints. To     // enforce this, we check if there are already user savepoint(SQL/JDBC)    // defined in the transaction. If yes, then throw an exception	/**	    @exception StandardException  Standard cloudscape exception policy		@see Transaction#setSavePoint	*/	private void throwExceptionIfSQLSavepointNotAllowed(Object kindOfSavepoint)        throws StandardException     {		boolean foundUserSavepoint = false;		if ((savePoints != null) && !savePoints.empty()) {			for (int i = savePoints.size() - 1; i >= 0; i--) {				SavePoint sp = (SavePoint) savePoints.elementAt(i);				if (sp.isThisUserDefinedsavepoint()) 				{                    //found a user defined savepoint					foundUserSavepoint = true;					break;				}			}		}		if (foundUserSavepoint) 			throw StandardException.newException(                    SQLState.XACT_MAX_SAVEPOINT_LEVEL_REACHED);	}	/**	    @exception StandardException  Standard cloudscape exception policy		@see Transaction#releaseSavePoint	*/	public int releaseSavePoint(String name, Object kindOfSavepoint)         throws StandardException     {		int position = getSavePointPosition(name, kindOfSavepoint, true);		if (position == -1)        {			// following means this is a JDBC savepoint.             // We prepend i./e. to JDBC savepoint names in JDBC layer.			// Need to trim that here before giving error			if (kindOfSavepoint != null && !(kindOfSavepoint instanceof String))            {                // this means this is a JDBC savepoint.                 // We append "i."/"e." to JDBC savepoint names.                 // Trimming that here before giving error				name = name.substring(2);             }			throw StandardException.newException(                        SQLState.XACT_SAVEPOINT_NOT_FOUND, name);        }		popSavePoints(position, true);		return savePoints.size();	}	/** 	    @exception StandardException  Standard cloudscape exception policy		@see Transaction#rollbackToSavePoint	*/	public int rollbackToSavePoint(String name, Object kindOfSavepoint)         throws StandardException     {		int position = getSavePointPosition(name, kindOfSavepoint, true);		if (position == -1)        {			// following means this is a JDBC savepoint.             // We append i./e. to JDBC savepoint names in JDBC layer.			// Need to trim that here before giving error			if (kindOfSavepoint != null && !(kindOfSavepoint instanceof String))				name = name.substring(2);			throw StandardException.newException(                        SQLState.XACT_SAVEPOINT_NOT_FOUND, name);        }		notifyObservers(SAVEPOINT_ROLLBACK);		popSavePoints(position, false);		return savePoints.size();	}	/*	**	Implementation specific methods	*/	/**		Get the Logger object used to write log records to the transaction log.	*/	private void getLogger() {		logger = logFactory.getLogger();	}	/**		Transform this identity to the one stored in transaction table entry.		Used by recovery only!	*/	protected void assumeIdentity(TransactionTableEntry ent)	{		if (ent != null)		{			if (SanityManager.DEBUG)			{				SanityManager.ASSERT(ent.getXid() != null, "TTE.xid is null");				SanityManager.ASSERT(                    ent.getFirstLog() != null, "TTE.firstLog is null");			}			// I am the transaction that is using this TransactionTableEntry			ent.setXact(this);			myId     = ent.getXid();			logStart = ent.getFirstLog();			logLast  = ent.getLastLog();            // This routine is only used by recovery to assume the identity            // of the transaction for each log record during redo and undo.            // For this purpose the transaction should act like a local             // transaction, and ignore the fact that it may or may not be            // an XA global transaction - this is necessary as global             // transactions can only be committed or aborted once, but             // recovery needs to reuse the same xact over and over again.              // For this purpose set myGlobalId to null so it is treated as            // a local xact - the entry in the transaction table will             // track that in reality it is a global id and remember it's            // value.			myGlobalId = null;			// I am very active			if (state == IDLE)				state = ACTIVE;			if (SanityManager.DEBUG)			{				if (state != ACTIVE && state != UPDATE && state != PREPARED)                    SanityManager.THROWASSERT(                        "recovery transaction have illegal state " + state +                        "xact = " + this);			}			if (logger == null)				getLogger();			savedEndStatus = 0;		}		else		{			myGlobalId = null;			myId = null;			logStart = null;			logLast = null;			state = IDLE;		}	}    /**     * Assume complete identity of the given Transaction Table Entry.     * <p>     * Used by the final phase of the recovery to create new real transactions     * to take on the identity of in-doubt prepared transactions found during     * redo.  Need to assume the globalId.     *	 * @return The identifier to be used to open the conglomerate later.     *     * @param ent The original entry we are assuming the identity of.     *     **/	protected void assumeGlobalXactIdentity(    TransactionTableEntry ent)	{        if (SanityManager.DEBUG)        {            SanityManager.ASSERT(ent != null);            SanityManager.ASSERT(ent.getXid() != null, "TTE.xid is null");            SanityManager.ASSERT(                ent.getFirstLog() != null, "TTE.firstLog is null");            SanityManager.ASSERT(ent.isPrepared());        }        myId        = ent.getXid();        myGlobalId  = ent.getGid();        logStart    = ent.getFirstLog();        logLast     = ent.getLastLog();        // I am very active        if (state == IDLE)		{			if (SanityManager.DEBUG)			{				if (SanityManager.DEBUG_ON("XATrace"))					SanityManager.DEBUG("XATrace","set active state in assume Global XactIdentity");			}            state = ACTIVE;		}        if (ent.isPrepared())            state = PREPARED;        // I am the transaction that is using this TransactionTableEntry        ent.setXact(this);        if (SanityManager.DEBUG)        {            if (state != ACTIVE && state != UPDATE && state != PREPARED)                SanityManager.THROWASSERT(                    "recovery transaction have illegal state " + state +                    "xact = " + this);        }        if (logger == null)            getLogger();		savedEndStatus = 0;        if (SanityManager.DEBUG)        {            SanityManager.ASSERT(myGlobalId != null);            // at least right now only prepared xact call this during recovery.            SanityManager.ASSERT(state == PREPARED);        }	}	/**		Move the transaction into the update state.		@exception StandardException problem setting a transaction id	*/	private final void setUpdateState() throws StandardException {        /*        System.out.println("calling setUpdateState() - readOnly = " + readOnly +                ";this = " + this);        System.out.println("calling setUpdateState():");                (new Throwable()).printStackTrace();        */		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(                state == ACTIVE,                 "setting update state without first going thru ACTIVE state");			SanityManager.ASSERT(                myId != null,                 "setting update state to a trasnaction with Null ID");		}		if (SanityManager.DEBUG)		{			if (SanityManager.DEBUG_ON("XATrace"))            {				SanityManager.DEBUG("XATrace","set update state");                SanityManager.showTrace(new Throwable());            }		}        if (readOnly)        {            throw StandardException.newException(                SQLState.XACT_PROTOCOL_VIOLATION);        }		state = UPDATE;	}	protected void setIdleState() {		if (SanityManager.DEBUG)			SanityManager.ASSERT(myId != null, "setIdleState got null ID");		if (SanityManager.DEBUG)        {            if (SanityManager.DEBUG_ON("TranTrace"))            {                SanityManager.DEBUG(                    "TranTrace", "transaction going idle " + myId);                SanityManager.showTrace(new Throwable("TranTrace"));            }		}		/* MT - single thread throught synchronizing this.  Even though no other		 * thread can call this, they may call isActive which needs to be		 * synchronized with state transaction into or out of the idle state		 */		// synchronized(this) -- int access, implicit synchronization		// due to atomic action		{			state = IDLE;		}				seenUpdates = false;		// these fields will NOT be accessed by the checkpoint thread at the		// same time because the doMe method of EndXact removed this		// transaction from the "update transaction" list, therefore when the		// checkpoint writes out the transaction table, this transaction will		// be skipped.  OK to just change it without synchronization here.		logStart = null;		logLast = null;		if (SanityManager.DEBUG)		{			if (SanityManager.DEBUG_ON("XATrace"))				SanityManager.DEBUG("XATrace","set idle state : " + state + " " + this);		}	}	protected final void setActiveState() throws StandardException {		if ((state == CLOSED) || (!inAbort() && (state == PREPARED)))        {            // This is where we catch attempted activity on a prepared xact.			throw StandardException.newException(                    SQLState.XACT_PROTOCOL_VIOLATION);        }		if (SanityManager.DEBUG)			SanityManager.ASSERT(myId != null, "setActiveState got null ID");		if (state == IDLE)		{			synchronized(this)			{				state = ACTIVE;			}			if (SanityManager.DEBUG)			{				if (SanityManager.DEBUG_ON("XATrace"))                {					SanityManager.DEBUG("XATrace","set active state " + this);                    SanityManager.showTrace(new Throwable("XATrace"));                }			}			if (!justCreated)				xactFactory.setNewTransactionId(myId, this);			justCreated = false;			if (SanityManager.DEBUG)            {				if (SanityManager.DEBUG_ON("TranTrace"))                {                    SanityManager.DEBUG(                        "TranTrace", "transaction going active " + myId);                    SanityManager.showTrace(new Throwable("TranTrace"));                }			}		}	}    /**     * Move the state of the transaction from UPDATE to PREPARE.     * <p>     * The state transition should only be from UPDATE to PREPARE.  Read-only     * transactions (IDLE and ACTIVE) will never be prepared, they will be     * commited when the prepare is requested.  Only Update transactions will     * be allowed to go to prepared state.     * <p>     *	 * @exception  StandardException  Standard exception policy.     **/	protected final void setPrepareState()         throws StandardException     {		if (state == PREPARED || state == CLOSED)        {			throw StandardException.newException(                    SQLState.XACT_PROTOCOL_VIOLATION);        }		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(                state == UPDATE,                 "setting PREPARED state without first going thru UPDATE state");			SanityManager.ASSERT(                myId != null,                 "setting PREPARED state to a transaction with Null ID");		}		state = PREPARED;	}	public final LockingPolicy defaultLockingPolicy() {		return defaultLocking;	}

⌨️ 快捷键说明

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