LocalDataStoreSlot writeCache; // thread-local write copy public STMObject(ICloneable obj, LocalDataStoreSlot readCache, LocalDataStoreSlot writeCache) { start = new Locator(obj); this.readCache = readCache; this.writeCache = writeCache; // Do not cache objects if not in transaction! if (Xaction.IsActive) { Xaction.AddToCache(readCache, obj); Xaction.AddToCache(writeCache, obj); } }
public void ReadById_PassNonExistantId_ShouldReturnNoRecord() { //arrange int transId = 100; Xaction transaction = new Xaction(transId, 1, "Payment made for levy", 2200); _dbAdaptorMock.Setup(x => x.ReadById(It.IsAny <int>())).Returns(transaction); //act var result = Service.ReadById(999); //Assert Assert.AreNotEqual(result.Id, 999); }
public bool Create(XactionViewModel vm) { if (vm.Amount > 20000.00M) { throw new ArgumentOutOfRangeException(nameof(vm.Amount)); } Xaction transaction = new Xaction(vm.Id, vm.HouseId, vm.Description, vm.Amount); _repo.Create(transaction); _emailSender.SendEmail("*****@*****.**", "New transaction created", "general message"); _logger.Log(LogLevel.Information, "test log message"); return(true); }
//public async Task<Xaction> ReadXaction(int id) //{ // return await Task.FromResult(new Xaction(1, "descr 123", 52)); //} public bool Update(XactionViewModel vm) { if (!Validate(vm)) { return(false); } Xaction transaction = new Xaction(vm.Id, vm.HouseId, vm.Description, vm.Amount); if (transaction.MaximumAmount()) { return(false); } _repo.Update(transaction); _repo.Save(); return(true); }
public void Update(Xaction transaction) { new Xaction(transaction.Id, transaction.HouseId, transaction.Description, transaction.Amount); }
public void Create(Xaction transact) { Save(); }
public Tryout() { this.factory = new XObjectFactory(typeof(Node)); header = (Node)factory.Create(8); testXaction = new Xaction(new Xaction.Delegate(Test)); }
void IXactionResository.Update(Xaction transaction) { _appDbContext.Xactions.Update(transaction); _appDbContext.SaveChanges(); }
public void Create(Xaction transaction) { _appDbContext.Xactions.Add(transaction); }
/// <summary> /// Open object with intention to modify. /// </summary> /// <returns>Private version of object</returns> public ICloneable OpenWrite() { XStatus me = Xaction.XStatus; // my transaction IContentionManager manager = Xaction.Manager; // my manager // allocate successor Locator newLocator = new Locator(); newLocator.writer = me; ICloneable oldVersion = null; ICloneable newVersion = null; while (true) { retry: // read locator Locator oldLocator = (Locator)this.start; XStatus writer = oldLocator.writer; switch (writer.State) { case XState.ACTIVE: case XState.WAITING: // abort or wait? manager.ResolveConflict(me, writer); goto retry; // try again case XState.COMMITTED: oldVersion = newLocator.oldObject = oldLocator.newObject; break; case XState.ABORTED: oldVersion = newLocator.oldObject = oldLocator.oldObject; break; default: Panic.SystemError("Unknown transaction state: {0}", me.State); break; // not reached } switch (me.State) { case XState.ABORTED: throw new AbortedException(); case XState.COMMITTED: return(oldVersion); case XState.ACTIVE: // check for read conflicts if (ConflictsWithReader(me, oldLocator.readers)) { manager.ResolveConflict(me, oldLocator.readers); goto retry; } // no conflict newVersion = newLocator.newObject = (ICloneable)oldVersion.Clone(); // try to install if ((Locator)(Interlocked.CompareExchange( ref start, newLocator, oldLocator)) == oldLocator) { #if DEBUG Xaction.myMisses++; #endif Xaction.AddToCache(readCache, newVersion); Xaction.AddToCache(writeCache, newVersion); return(newVersion); } break; default: Panic.SystemError("Unknown transaction state: {0}", me.State); break; // not reached } } }
/// <summary> /// If object hasn't changed since snapshot, upgrade to read access. /// </summary> /// <returns>Shared version of object</returns> public bool Upgrade(ICloneable snapshot) { XStatus me = Xaction.XStatus; // my transaction IContentionManager manager = Xaction.Manager; // my manager // allocate successor Locator newLocator = new Locator(); newLocator.writer = XStatus.COMMITTED; while (true) { retry: // read locator Locator oldLocator = (Locator)this.start; XStatus writer = oldLocator.writer; switch (writer.State) { case XState.ACTIVE: // abort or wait? manager.ResolveConflict(me, writer); goto retry; // try again case XState.COMMITTED: if (snapshot != oldLocator.newObject) { return(false); } break; case XState.ABORTED: if (snapshot != oldLocator.oldObject) { return(false); } break; default: Panic.SystemError("Unknown transaction state: {0}", me.State); break; // not reached } switch (me.State) { case XState.ABORTED: throw new AbortedException(); case XState.ACTIVE: newLocator.newObject = snapshot; // copy live readers into new locator newLocator.readers.Clear(); newLocator.readers.Add(me); foreach (XStatus t in oldLocator.readers) { if (t.State == XState.ACTIVE) { newLocator.readers.Add(t); } } if (Interlocked.CompareExchange( ref start, newLocator, oldLocator) == oldLocator) { #if DEBUG Xaction.myMisses++; #endif Xaction.AddToCache(readCache, snapshot); return(true); } break; default: Panic.SystemError("Unknown transaction state: {0}", me.State); break; // not reached } } }