Beispiel #1
0
        public SpmItem(ISpmContext readContext, SpmAttribute mappedHolder, string group)
        {
            if (readContext == null)
            {
                throw new ArgumentNullException("itemReader");
            }
            this.context      = readContext;
            this.MappedHolder = mappedHolder;
            ReadOnlyCollection <ISpmAccessor <TItem> > coll = SpmAccessors <TItem> .Collection;

            this.accessors = new List <SprIndexedAccessor>(coll.Count);
            this.keys      = new List <SprIndexedAccessor>(4);
            for (int i = 0; i < coll.Count; i++)
            {
                ISpmAccessor <TItem> accessor = coll[i];
                if (accessor.Mapped.InGroup(group))
                {
                    string[] colNames = accessor.Mapped.Columns;
                    int      index    = -1;
                    for (int j = 0; j < colNames.Length; j++)
                    {
                        string colName = colNames[j];
                        if (colName.StartsWith("/"))
                        {
                            if (this.MappedHolder == null || !this.MappedHolder.HasSynonyms)
                            {
                                throw new ArgumentException(String.Concat("Не заданы родительские синонимы для", colNames[j]));
                            }
                            if (String.IsNullOrEmpty((colName = this.MappedHolder.GetSynonim(colName.Substring(1)))))
                            {
                                throw new ArgumentException(String.Concat("Не найдена ссылка на родительский синоним ", colNames[j]));
                            }
                        }
                        if ((index = this.context.TryGetIndex(colName)) >= 0)
                        {
                            break;
                        }
                    }
                    if (index < 0 && colNames.Length > 0)
                    {
                        throw new ArgumentException(String.Concat("В результате запроса не найдено хотя бы одно из полей: ",
                                                                  String.Join(", ", colNames)));
                    }
                    SprIndexedAccessor indexedAccessor = new SprIndexedAccessor(index, accessor);
                    this.accessors.Add(indexedAccessor);
                    if (accessor.Mapped.Key)
                    {
                        keys.Add(indexedAccessor);
                    }
                }
            }
            this.accessors.TrimExcess();
            if (mappedHolder != null && mappedHolder.Shared)
            {
                this.sharedItems = readContext.SharedPool.Get <TItem>(mappedHolder.ShareId, out this.extendable);
                if (this.sharedItems == null)
                {
                    this.sharedItems = new Dictionary <TItem, TItem>(10);
                    readContext.SharedPool.Set(mappedHolder.ShareId, this.sharedItems, true);
                    this.extendable = true;
                }
                else
                if (this.keys.Count == 0 && !this.extendable)
                {
                    throw new ArgumentException("Не заданы ключи для использования фиксированного пула элементов.");
                }
                this.sharedItem = new TItem();
            }
        }
Beispiel #2
0
 private bool isKeyNull(SprIndexedAccessor entry)
 {
     return(entry.Accessor.IsNull(this.context, entry.Index));
 }