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

📄 volatilerm.cs

📁 < SQL Server2005程序设计>
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;

namespace TheRM
{
    public class VolatileRM : IEnlistmentNotification
    {
        private string whoAmI = "";
        public VolatileRM(string WhoAmI)
        {
            whoAmI = WhoAmI;
        }

        private int memberValue = 0;
        private int oldMemberValue = 0;
        public int MemberValue
        {
            get { return memberValue; }
            set
            {
                Transaction currentTx = Transaction.Current;
                if (currentTx != null)
                {
                    Console.WriteLine(whoAmI + ": MemberValue setter - EnlistVolatile");
                    currentTx.EnlistVolatile(this, EnlistmentOptions.None);
                }
                oldMemberValue = memberValue;
                memberValue = value;
            }
        }

        #region IEnlistmentNotification Members
        public void Commit(Enlistment enlistment)
        {
            Console.WriteLine(whoAmI + ": Commit");
            // Clear out oldMemberValue
            oldMemberValue = 0;
            enlistment.Done();
        }

        public void InDoubt(Enlistment enlistment)
        {
            Console.WriteLine(whoAmI + ": InDoubt");
            enlistment.Done();
        }

        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Console.WriteLine(whoAmI + ": Prepare");
//            preparingEnlistment.Prepared();
            preparingEnlistment.ForceRollback();
        }

        public void Rollback(Enlistment enlistment)
        {
            Console.WriteLine(whoAmI + ": Rollback");
            // Restore previous state
            memberValue = oldMemberValue;
            oldMemberValue = 0;
            enlistment.Done();
        }
        #endregion
    }
}

⌨️ 快捷键说明

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