Example #1
0
        /// <summary>
        ///   Adds a write action to the transaction
        /// </summary>
        /// <param name="writeAction"> The write action to be added </param>
        /// <param name="persistWriteAction"> To indicate if write action must be persisted </param>
        private void AddWriteAction(WriteAction writeAction, bool persistWriteAction)
        {
            if (OdbConfiguration.IsLoggingEnabled())
            {
                DLogger.Info(string.Format("OdbTransaction: Adding WriteAction in Transaction of session {0}", _session.GetId()));
            }

            if (writeAction.IsEmpty())
            {
                return;
            }

            CheckRollback();
            if (!_hasBeenPersisted && persistWriteAction)
            {
                Persist();
            }

            if (persistWriteAction)
            {
                writeAction.PersistMeTo(_fsi);
            }

            // Only adds the write action to the list if the transaction keeps all in
            // memory
            if (_hasAllWriteActionsInMemory)
            {
                _writeActions.Add(writeAction);
            }

            _numberOfWriteActions++;

            if (_hasAllWriteActionsInMemory &&
                _numberOfWriteActions > StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction)
            {
                _hasAllWriteActionsInMemory = false;

                foreach (var defaultWriteAction in _writeActions)
                {
                    defaultWriteAction.Clear();
                }

                _writeActions.Clear();

                if (OdbConfiguration.IsLoggingEnabled())
                {
                    var numberOfWriteActions = _numberOfWriteActions.ToString();
                    var maxNumberOfWriteObjectPerTransactionAsString =
                        StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction.ToString();

                    DLogger.Info("OdbTransaction: Number of objects has exceeded the max number " + numberOfWriteActions + "/" +
                                 maxNumberOfWriteObjectPerTransactionAsString +
                                 ": switching to persistent transaction managment");
                }
            }
        }
Example #2
0
        public void Commit()
        {
            var numberOfWriteActionsAsString       = _numberOfWriteActions.ToString();
            var hasAllWriteActionsInMemoryAsString = _hasAllWriteActionsInMemory.ToString();

            Log4NetHelper.Instance.LogInfoMessage("OdbTransaction: Commiting " + numberOfWriteActionsAsString + " write actions - In Memory : " +
                                                  hasAllWriteActionsInMemoryAsString + string.Format(" - sid={0}", _session.GetId()));

            // Check if database has been rollbacked
            CheckRollback();

            // call the commit listeners
            ManageCommitListenersBefore();

            if (_currentWriteAction != null && !_currentWriteAction.IsEmpty())
            {
                AddWriteAction(_currentWriteAction, true);
                _currentWriteAction = null;
            }

            if (_fsi == null && _numberOfWriteActions != 0)
            {
                throw new OdbRuntimeException(NDatabaseError.TransactionAlreadyCommitedOrRollbacked);
            }

            if (_numberOfWriteActions == 0)
            {
                // FIXME call commitMetaModel in realOnlyMode?
                CommitMetaModel();
                // Nothing to do
                if (_fsi != null)
                {
                    _fsi.Close();
                    _fsi = null;
                }
                if (_session != null)
                {
                    _session.GetCache().ClearOnCommit();
                }
                return;
            }

            // Marks the transaction as committed
            SetCommited();

            // Apply the write actions the main database file
            ApplyTo();

            // Commit Meta Model changes
            CommitMetaModel();

            if (_fsi != null)
            {
                _fsi.Close();
                _fsi = null;
            }

            if (_session != null)
            {
                _session.GetCache().ClearOnCommit();
            }

            ManageCommitListenersAfter();
        }
Example #3
0
        /// <summary>
        ///   Adds a write action to the transaction
        /// </summary>
        /// <param name="writeAction"> The write action to be added </param>
        /// <param name="persistWriteAction"> To indicate if write action must be persisted </param>
        private void AddWriteAction(WriteAction writeAction, bool persistWriteAction)
        {
            if (OdbConfiguration.IsLoggingEnabled())
                DLogger.Info(string.Format("OdbTransaction: Adding WriteAction in Transaction of session {0}", _session.GetId()));

            if (writeAction.IsEmpty())
                return;

            CheckRollback();
            if (!_hasBeenPersisted && persistWriteAction)
                Persist();

            if (persistWriteAction)
                writeAction.PersistMeTo(_fsi);

            // Only adds the write action to the list if the transaction keeps all in
            // memory
            if (_hasAllWriteActionsInMemory)
                _writeActions.Add(writeAction);

            _numberOfWriteActions++;

            if (_hasAllWriteActionsInMemory &&
                _numberOfWriteActions > StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction)
            {
                _hasAllWriteActionsInMemory = false;

                foreach (var defaultWriteAction in _writeActions)
                    defaultWriteAction.Clear();

                _writeActions.Clear();

                if (OdbConfiguration.IsLoggingEnabled())
                {
                    var numberOfWriteActions = _numberOfWriteActions.ToString();
                    var maxNumberOfWriteObjectPerTransactionAsString =
                        StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction.ToString();

                    DLogger.Info("OdbTransaction: Number of objects has exceeded the max number " + numberOfWriteActions + "/" +
                                 maxNumberOfWriteObjectPerTransactionAsString +
                                 ": switching to persistent transaction managment");
                }
            }
        }