internal TransactionLogEntry <T> GetObject <T>(StmObject <T> stmObject) { ITransactionLogEntry tle; if (_entries.TryGetValue(stmObject.UniqueId, out tle)) { return((TransactionLogEntry <T>)tle); } return(null); }
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); }
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."); } } }
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.)"); }
internal void UpdateNewStmObject(StmObject <T> newStmObject) { newStmObject.Element.Version = (int)OriginalVersionId + 1; NewObject = newStmObject; }
internal static TransactionLogEntry <T> LogWriteEntry(StmObject <T> originalObject, StmObject <T> newObject) { return(new TransactionLogEntry <T>(originalObject, newObject, true)); }
internal static TransactionLogEntry <T> LogReadEntry(StmObject <T> originalObject, StmObject <T> newObject) { return(new TransactionLogEntry <T>(originalObject, newObject, false)); }