public bool Delete(Transaction context, RID rId, int count) { // enlist with TM this.Enlist(context); // read in the resource Resource data = null; bool removed = this.dataStore.Read(context, rId, out data); if (!removed || null == data) { // silently discard return(false); } // update the resource if (data.getCount() > count) { data.decrCount(count); } else { data.setCount(0); } // write the resource back return(this.dataStore.Write(context, rId, data)); }
/// <summary> /// Deletes certain amount of resource. /// </summary> /// <param name="context"></param> /// <param name="rid"></param> /// <param name="count"></param> /// <returns>true the given resources exists. False if not</returns> public bool Delete(Transaction context, RID rid, int count) { WaitForReady(); Enlist(context); _lockManager.LockForWrite(context, rid); Resource resource = _transactionStorage.Read(context, rid); if (resource == null) { // silently discard return(false); } if (resource.getCount() > count) { resource.decrCount(count); } else { resource.setCount(0); } _transactionStorage.Write(context, rid, resource); return(true); }