Ejemplo n.º 1
0
        /// <summary>
        /// Deletes row.
        /// </summary>
        /// <param name="rowId"></param>
        public void Delete(RowId rowId)
        {
            Debug.Assert(0 <= rowId.Value && rowId.Value < this.table.Count, "broken rowId");
            this.ValidateModification();
            ValueList <Row> .Address address = this.table.ItemAddress(rowId.Value);
            SnapTable <TRecord> .ValidateModification(ref address);

            this.PushToLog(ref address.Page[address.Index], rowId);
            // if the row was inserted in this transaction, then after deletion it will be invalid. so just ignore it in all future operations
            address.Page[address.Index].IsDeleted = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets entire structure.
        /// </summary>
        /// <param name="rowId"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool SetData(RowId rowId, ref TRecord data)
        {
            Debug.Assert(0 <= rowId.Value && rowId.Value < this.table.Count, "broken rowId");
            this.ValidateModification();
            ValueList <Row> .Address address = this.table.ItemAddress(rowId.Value);
            SnapTable <TRecord> .ValidateModification(ref address);

            if (TableSnapshot <TRecord> .Compare(this.Fields, ref address.Page[address.Index].Data, ref data) != 0)
            {
                this.PushToLog(ref address.Page[address.Index], rowId);
                address.Page[address.Index].Data = data;
                Debug.Assert(TableSnapshot <TRecord> .Compare(this.Fields, ref address.Page[address.Index].Data, ref data) == 0, "Assignment or comparison failed");
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates field of the row
        /// </summary>
        /// <typeparam name="TField"></typeparam>
        /// <param name="rowId"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetField <TField>(RowId rowId, IField <TRecord, TField> field, TField value)
        {
            Debug.Assert(0 <= rowId.Value && rowId.Value < this.table.Count, "broken rowId");
            this.ValidateModification();
            // It is only possible to set value via basic fields defined on table.
            this.ValidateField(field);
            ValueList <Row> .Address address = this.table.ItemAddress(rowId.Value);
            SnapTable <TRecord> .ValidateModification(ref address);

            if (field.Compare(field.GetValue(ref address.Page[address.Index].Data), value) != 0)
            {
                this.PushToLog(ref address.Page[address.Index], rowId);
                field.SetValue(ref address.Page[address.Index].Data, value);
                Debug.Assert(field.Compare(field.GetValue(ref address.Page[address.Index].Data), value) == 0, "Assignment or comparison failed");
                return(true);
            }
            return(false);
        }