Пример #1
0
        private IEnumerable <RowId> SelectDirect <TField>(IField <TRecord, TField> field, TField min, TField max)
        {
            Debug.Assert(field.Compare(min, max) <= 0);
            int version = this.StoreSnapshot.Version;

            foreach (RowId rowId in this)
            {
                TField value = this.table.GetField <TField>(rowId, field, version);
                if (field.Compare(value, min) >= 0 && field.Compare(value, max) <= 0)
                {
                    yield return(rowId);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Updates field of the row
 /// </summary>
 /// <typeparam name="TField">Type of the field</typeparam>
 /// <param name="rowId">row id</param>
 /// <param name="field">Field to update</param>
 /// <param name="value">New value to assign</param>
 /// <returns></returns>
 public bool SetField <TField>(RowId rowId, IField <TRecord, TField> field, TField value)
 {
     this.ValidateModification();
     this.table.ValidateField(field);
     if (field.Compare(this.table.GetLatestField <TField>(rowId, field), value) != 0)
     {
         List <IIndex <TRecord> > list = this.table.Indexes[field.Order];
         if (list != null)
         {
             foreach (IIndex <TRecord> index in list)
             {
                 // no need to check for timestamp as only one field updated
                 index.Delete(rowId);
             }
         }
         bool updated = this.table.SetField <TField>(rowId, field, value);
         Debug.Assert(updated);
         if (list != null)
         {
             foreach (IIndex <TRecord> index in list)
             {
                 // no need to check for timestamp as only one field updated
                 index.Insert(rowId);
             }
         }
         return(true);
     }
     return(false);
 }
Пример #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);
        }
Пример #4
0
        private IEnumerable <RowId> SelectDirect <TField>(IField <TRecord, TField> field, TField value)
        {
            int version = this.StoreSnapshot.Version;

            foreach (RowId rowId in this)
            {
                if (field.Compare(this.table.GetField <TField>(rowId, field, version), value) == 0)
                {
                    yield return(rowId);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Gets maximum value of the provided field.
 /// </summary>
 /// <typeparam name="TField"></typeparam>
 /// <param name="field"></param>
 /// <returns></returns>
 public TField Maximum <TField>(IField <TRecord, TField> field)
 {
     this.table.ValidateField(field);
     if (!this.IsEmpty())
     {
         List <IIndex <TRecord> > list = this.table.Indexes[field.Order];
         if (list != null)
         {
             foreach (IIndex <TRecord> index in list)
             {
                 if (((IFieldHolder)index).Field == field)
                 {
                     RangeIndex <TField> rangeIndex = index as RangeIndex <TField>;
                     if (rangeIndex != null)
                     {
                         return(rangeIndex.MaximumValue(this.StoreSnapshot.Version));
                     }
                 }
             }
         }
         TField max   = field.DefaultValue;
         bool   first = true;
         foreach (RowId rowId in this)
         {
             if (first)
             {
                 max   = this.GetField(rowId, field);
                 first = false;
             }
             else
             {
                 TField value = this.GetField(rowId, field);
                 if (field.Compare(max, value) < 0)
                 {
                     max = value;
                 }
             }
         }
         return(max);
     }
     return(field.DefaultValue);
 }