Example #1
0
        /// <summary>
        /// Persist in disk all changed from last BeginTrans()
        /// Returns true if real commit was done (false to nested commit only)
        /// </summary>
        public bool Commit()
        {
            var commit = false;

            // only do "real commit" if is last transaction in stack or if autocommit = false
            if (_transactions.Count == 1)
            {
                _trans.Commit();
                commit = true;
            }

            // if contains transactions on stack, remove top and dispose (only last transaction will release lock)
            if (_transactions.Count > 0)
            {
                _transactions.Pop().Dispose();
            }

            return(commit);
        }
Example #2
0
        /// <summary>
        /// Encapsulate all transaction commands in same data structure
        /// </summary>
        private T Transaction <T>(string colName, bool addIfNotExists, Func <CollectionPage, T> action)
        {
            lock (_locker)
                try
                {
                    _transaction.Begin();

                    var col = this.GetCollectionPage(colName, addIfNotExists);

                    var result = action(col);

                    _transaction.Commit();

                    return(result);
                }
                catch (Exception ex)
                {
                    _log.Write(Logger.ERROR, ex.Message);
                    _transaction.Rollback();
                    throw;
                }
        }