Esempio n. 1
0
        private void LoadWriteActions(string filename, bool apply)
        {
            Log4NetHelper.Instance.LogDebugMessage(string.Format("OdbTransaction: Load write actions of {0}", filename));

            CheckFileAccess(filename);
            _fsi.SetReadPosition(0);
            _isCommited       = _fsi.ReadByte() == 1;
            _creationDateTime = _fsi.ReadLong();
            var totalNumberOfWriteActions = _fsi.ReadLong();

            Log4NetHelper.Instance.LogInfoMessage(string.Concat("OdbTransaction: ", _writeActions.Count.ToString(), " write actions in file"));

            for (var i = 0; i < totalNumberOfWriteActions; i++)
            {
                var defaultWriteAction = WriteAction.Read(_fsi);

                if (apply)
                {
                    defaultWriteAction.ApplyTo(_fsiToApplyWriteActions);
                    defaultWriteAction.Clear();
                }
                else
                {
                    AddWriteAction(defaultWriteAction, false);
                }
            }

            if (apply)
            {
                _fsiToApplyWriteActions.Flush();
            }
        }
Esempio n. 2
0
        private void LoadWriteActions(string filename, bool apply)
        {
            if (OdbConfiguration.IsLoggingEnabled())
            {
                DLogger.Debug(string.Format("OdbTransaction: Load write actions of {0}", filename));
            }

            CheckFileAccess(filename);
            _fsi.SetReadPosition(0);
            _isCommited       = _fsi.ReadByte() == 1;
            _creationDateTime = _fsi.ReadLong();
            var totalNumberOfWriteActions = _fsi.ReadLong();

            if (OdbConfiguration.IsLoggingEnabled())
            {
                DLogger.Info(string.Concat("OdbTransaction: ", _writeActions.Count.ToString(), " write actions in file"));
            }

            for (var i = 0; i < totalNumberOfWriteActions; i++)
            {
                var defaultWriteAction = WriteAction.Read(_fsi);

                if (apply)
                {
                    defaultWriteAction.ApplyTo(_fsiToApplyWriteActions);
                    defaultWriteAction.Clear();
                }
                else
                {
                    AddWriteAction(defaultWriteAction, false);
                }
            }

            if (apply)
            {
                _fsiToApplyWriteActions.Flush();
            }
        }
Esempio n. 3
0
        /// <summary>
        ///   Mark te transaction file as committed
        /// </summary>
        private void SetCommited()
        {
            _isCommited = true;
            CheckFileAccess(null);

            // TODO Check atomicity
            // Writes the number of write actions after the byte and date
            _fsi.SetWritePositionNoVerification(OdbType.Byte.Size + OdbType.Long.Size, false);
            _fsi.WriteLong(_numberOfWriteActions, false);
            // FIXME The fsi.flush should not be called after the last write?
            _fsi.Flush();
            // Only set useBuffer = false when it is a local database to avoid
            // net io overhead

            _fsi.SetWritePositionNoVerification(0, false);
            _fsi.WriteByte(1, false);
        }