usablity in transaction for LLBLGEN

Posts   
 
    
Hooman
User
Posts: 9
Joined: 24-Aug-2007
# Posted on: 24-Aug-2007 13:02:32   

Hi,

I came across a problem in the usage of adapter. Apparently, If I dont define any transaction assign to an adapter, I still can call the dispose method. However, it neither does have any effect on the database nor raise an exception for using rollback for undeclared transaction. Can you please clear the case for me.

Thanks, Hooman

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Aug-2007 15:31:11   

When you call Dispose for a DataAccessAdapter, if and only if there are transactions in progress, they will be rolled back.

And here is the DataAccessAdapter implementation of the IDisposable:

        #region IDisposable
        /// <summary>
        /// Implements the IDispose' method Dispose.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }


        /// <summary>
        /// Implements the Dispose functionality. If a transaction is in progress, it will rollback that transaction.
        /// </summary>
        /// <param name="isDisposing">Flag which signals this routine if a dispose action should take place (true) or not (false)</param>
        protected virtual void Dispose(bool isDisposing)
        {
            // Check to see if Dispose has already been called.
            if(!_isDisposed)
            {
                if(isDisposing)
                {
                    // Dispose managed resources.
                    if(_physicalTransaction != null)
                    {
                        if(_isTransactionInProgress)
                        {
                            Rollback();
                        }
                        else
                        {
#if !CF
                            _physicalTransaction.Dispose();
#endif
                            _physicalTransaction = null;
                        }
                    }

                    DisposePostponedDisposeCandidates();

                    if(_activeConnection != null)
                    {
                        // closing the connection will abort (rollback) any pending transactions
                        if(_activeConnection.State == ConnectionState.Open)
                        {
                            _activeConnection.Close();
                        }
#if !CF 
                        _activeConnection.Dispose();
#endif
                        _activeConnection = null;
                    }
                    if( this.InSystemTransaction )
                    {
#if !CF && !MONO
                        // set transaction and resource manager to null, so the adapter goes out of scope as soon as the System.Transactions.Transaction is going out of scope
                        _systemTransactionResourceManager = null;
                        _systemTransaction = null;
                        _systemTransactionEnlistment = null;
#endif
                    }
                    _isDisposed = true;
                }
            }
        }
        #endregion
Hooman
User
Posts: 9
Joined: 24-Aug-2007
# Posted on: 25-Aug-2007 17:54:11   

Thanks for your reply. The other thing is when I have not defined any transaction, calling the rollback method should cause an exception. dont you think so? I can imagine that a coder may easily call rollback while s/he forget to define a transaction and llblgen doesnt throw any exception to inform the develper. I think stored procedures in sql server support this functionality and if you rollback a transaction while you havent define it initially, you will get an exception

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 25-Aug-2007 21:50:31   

It will simply not rollback a transaction, so there's no harm done. the thing is that an exception is occuring at runtime, so this can be harmful and will probably be caught in production, and as it isn't harmfull to simply return if there's no transaction going on, it won't throw an exception.

Frans Bouma | Lead developer LLBLGen Pro