示例#1
0
        internal TransactionLogEntry <T> GetObject <T>(StmObject <T> stmObject)
        {
            ITransactionLogEntry tle;

            if (_entries.TryGetValue(stmObject.UniqueId, out tle))
            {
                return((TransactionLogEntry <T>)tle);
            }

            return(null);
        }
示例#2
0
        internal void LogWrite <T>(StmObject <T> stmObject, T newValue)
        {
            var newStmObject = new StmObject <T>(newValue);
            var txEntry      = _txLog.GetObject(stmObject);

            if (txEntry == null)
            {
                txEntry = TransactionLogEntry <T> .LogWriteEntry(stmObject, newStmObject);

                _txLog.Add(txEntry);

                return;
            }

            txEntry.UpdateNewStmObject(newStmObject);
        }
示例#3
0
        private TransactionLogEntry(StmObject <T> originalObject, StmObject <T> newObject, bool incrementVersionId)
        {
            OriginalObject = originalObject;
            NewObject      = newObject;

            var versionId = originalObject.Element.Version;

            if (versionId is int)
            {
                OriginalVersionId = versionId;

                newObject.Element.Version = incrementVersionId ? (int)versionId + 1 : (int)versionId;
            }
            else
            {
                // this object is being updated. wait until the update is complete or error out.
                bool waitMore;
                do
                {
                    waitMore = OriginalObject.ResetEvent.Wait(1000);

                    versionId = originalObject.Element.Version;
                } while (!(versionId is int) && waitMore);

                if (versionId is int)
                {
                    OriginalVersionId = versionId;

                    newObject.Element.Version = incrementVersionId ? (int)versionId + 1 : (int)versionId;
                }
                else
                {
                    throw new InvalidStmObjectStateException("StmObject is not in valid state.");
                }
            }
        }
示例#4
0
        internal T LogRead <T>(StmObject <T> stmObject)
        {
            var txEntry = _txLog.GetObject(stmObject);

            if (txEntry == null)
            {
                // first read on object: create txlog entry...
                var newStmObject = stmObject.Clone();

                txEntry = TransactionLogEntry <T> .LogReadEntry(stmObject, newStmObject);

                _txLog.Add(txEntry);

                // return new value
                return(newStmObject.Value);
            }

            if (IsValidVersion(txEntry))
            {
                return(txEntry.NewObject.Value);
            }

            throw new StmObjectValueChangedException("StmObject value has been changed by another transaction since it was last read. (Use isolation level 'ReadCommitted' to allow such changes to happen.)");
        }
示例#5
0
 internal void UpdateNewStmObject(StmObject <T> newStmObject)
 {
     newStmObject.Element.Version = (int)OriginalVersionId + 1;
     NewObject = newStmObject;
 }
示例#6
0
 internal static TransactionLogEntry <T> LogWriteEntry(StmObject <T> originalObject, StmObject <T> newObject)
 {
     return(new TransactionLogEntry <T>(originalObject, newObject, true));
 }
示例#7
0
 internal static TransactionLogEntry <T> LogReadEntry(StmObject <T> originalObject, StmObject <T> newObject)
 {
     return(new TransactionLogEntry <T>(originalObject, newObject, false));
 }