示例#1
0
        /// <summary>
        /// Enlists in the specified transaction.
        /// </summary>
        /// <param name="transaction">
        /// A reference to an existing <see cref="System.Transactions.Transaction"/> in which to enlist.
        /// </param>
        public override void EnlistTransaction(Transaction transaction)
        {
            // enlisting in the null transaction is a noop
            if (transaction == null)
            {
                return;
            }

            // guard against trying to enlist in more than one transaction
            if (driver.CurrentTransaction != null)
            {
                if (driver.CurrentTransaction.BaseTransaction == transaction)
                {
                    return;
                }

                Throw(new MySqlException("Already enlisted"));
            }

            // now see if we need to swap out drivers.  We would need to do this since
            // we have to make sure all ops for a given transaction are done on the
            // same physical connection.
            Driver existingDriver = DriverTransactionManager.GetDriverInTransaction(transaction);

            if (existingDriver != null)
            {
                // we can't allow more than one driver to contribute to the same connection
                if (existingDriver.IsInActiveUse)
                {
                    Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }

                // there is an existing driver and it's not being currently used.
                // now we need to see if it is using the same connection string
                string text1 = existingDriver.Settings.ConnectionString;
                string text2 = Settings.ConnectionString;
                if (String.Compare(text1, text2, true) != 0)
                {
                    Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }

                // close existing driver
                // set this new driver as our existing driver
                CloseFully();
                driver = existingDriver;
            }

            if (driver.CurrentTransaction == null)
            {
                MySqlPromotableTransaction t = new MySqlPromotableTransaction(this, transaction);
                if (!transaction.EnlistPromotableSinglePhase(t))
                {
                    Throw(new NotSupportedException(Resources.DistributedTxnNotSupported));
                }

                driver.CurrentTransaction = t;
                DriverTransactionManager.SetDriverInTransaction(driver);
                driver.IsInActiveUse = true;
            }
        }
示例#2
0
        /// <summary>
        /// Enlists in the specified transaction.
        /// </summary>
        /// <param name="transaction">
        /// A reference to an existing <see cref="System.Transactions.Transaction"/> in which to enlist.
        /// </param>
        public override void EnlistTransaction(System.Transactions.Transaction transaction)
        {
            if (currentTransaction != null)
            {
                if (currentTransaction.BaseTransaction == transaction)
                {
                    return;
                }

                throw new MySqlException("Already enlisted");
            }

            currentTransaction = new MySqlPromotableTransaction(this, transaction);
            transaction.EnlistPromotableSinglePhase(currentTransaction);
        }
示例#3
0
        public override void EnlistTransaction(Transaction transaction)
        {
            if (transaction == null)
            {
                return;
            }
            if (this.driver.CurrentTransaction != null)
            {
                if (this.driver.CurrentTransaction.BaseTransaction == transaction)
                {
                    return;
                }
                this.Throw(new MySqlException("Already enlisted"));
            }
            Driver driverInTransaction = DriverTransactionManager.GetDriverInTransaction(transaction);

            if (driverInTransaction != null)
            {
                if (driverInTransaction.IsInActiveUse)
                {
                    this.Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }
                string connectionString  = driverInTransaction.Settings.ConnectionString;
                string connectionString2 = this.Settings.ConnectionString;
                if (string.Compare(connectionString, connectionString2, true) != 0)
                {
                    this.Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }
                this.CloseFully();
                this.driver = driverInTransaction;
            }
            if (this.driver.CurrentTransaction == null)
            {
                MySqlPromotableTransaction mySqlPromotableTransaction = new MySqlPromotableTransaction(this, transaction);
                if (!transaction.EnlistPromotableSinglePhase(mySqlPromotableTransaction))
                {
                    this.Throw(new NotSupportedException(Resources.DistributedTxnNotSupported));
                }
                this.driver.CurrentTransaction = mySqlPromotableTransaction;
                DriverTransactionManager.SetDriverInTransaction(this.driver);
                this.driver.IsInActiveUse = true;
            }
        }
示例#4
0
        /// <summary>
        /// Enlists in the specified transaction.
        /// </summary>
        /// <param name="transaction">
        /// A reference to an existing <see cref="System.Transactions.Transaction"/> in which to enlist.
        /// </param>
        public override void EnlistTransaction(System.Transactions.Transaction transaction)
        {
            // if the transaction given to us is null, then there is nothing to do.
            if (transaction == null)
            {
                return;
            }

            if (currentTransaction != null)
            {
                if (currentTransaction.BaseTransaction == transaction)
                {
                    return;
                }

                throw new MySqlException("Already enlisted");
            }

            MySqlPromotableTransaction t = new MySqlPromotableTransaction(this, transaction);

            transaction.EnlistPromotableSinglePhase(t);
            currentTransaction = t;
        }
示例#5
0
        /// <summary>
        /// Enlists in the specified transaction. 
        /// </summary>
        /// <param name="transaction">
        /// A reference to an existing <see cref="System.Transactions.Transaction"/> in which to enlist.
        /// </param>
        public override void EnlistTransaction(Transaction transaction)
        {
            // enlisting in the null transaction is a noop
            if (transaction == null)
                return;

            // guard against trying to enlist in more than one transaction
            if (driver.CurrentTransaction != null)
            {
                if (driver.CurrentTransaction.BaseTransaction == transaction)
                    return;

                throw new MySqlException("Already enlisted");
            }

            // now see if we need to swap out drivers.  We would need to do this since
            // we have to make sure all ops for a given transaction are done on the
            // same physical connection.
            Driver existingDriver = DriverTransactionManager.GetDriverInTransaction(transaction);
            if (existingDriver != null)
            {
                // we can't allow more than one driver to contribute to the same connection
                if (existingDriver.IsInActiveUse)
                    throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);

                // there is an existing driver and it's not being currently used.
                // now we need to see if it is using the same connection string
                string text1 = existingDriver.Settings.GetConnectionString(true);
                string text2 = Settings.GetConnectionString(true);
                if (String.Compare(text1, text2, true) != 0)
                    throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);

                // close existing driver
                // set this new driver as our existing driver
                CloseFully();
                driver = existingDriver;
            }

            if (driver.CurrentTransaction == null)
            {
                MySqlPromotableTransaction t = new MySqlPromotableTransaction(this, transaction);
                if (!transaction.EnlistPromotableSinglePhase(t))
                    throw new NotSupportedException(Resources.DistributedTxnNotSupported);

                driver.CurrentTransaction = t;
                DriverTransactionManager.SetDriverInTransaction(driver);
                driver.IsInActiveUse = true;
            }
        }