public void DeleteItemFromCaches(RepositoryId id)
 {
     foreach (KeyValuePair <string, ResultSetCache <T> > pair in labelToResultSetCacheMap)
     {
         pair.Value.DeleteItemFromCache(id);
     }
 }
示例#2
0
        public RepositoryId[] GetAllItems()
        {
            int numberOfIds = idToObjectHashtable.Keys.Count;

            RepositoryId[] ids = new RepositoryId[numberOfIds];
            idToObjectHashtable.Keys.CopyTo(ids, 0);
            return(ids);
        }
示例#3
0
 public void DeleteItemFromCache(RepositoryId id)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     CheckIfItemIsInRepository(id);
     RemoveOldTokensWithId(id);
 }
示例#4
0
        public void DeleteItemFromCache(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            RepositoryId id = _dataMapperQueried.GetId(item);

            DeleteItemFromCache(id);
        }
示例#5
0
 public RecordToken(IDataMapper <T> dataMapper,
                    IDictionary <string, object> queryResults,
                    RepositoryId id) : this(dataMapper, id)
 {
     if (queryResults == null)
     {
         throw new ArgumentNullException("queryResults");
     }
     _dataMapper   = dataMapper;
     _queryResults = new SortedDictionary <string, object>(queryResults);            // we need to own this
 }
示例#6
0
 public override int CompareTo(RepositoryId other)
 {
     if (other == null)
     {
         return(1);
     }
     if (other is EmptyRepositoryId)
     {
         return(0);
     }
     return(-1);
 }
示例#7
0
 public virtual T GetItem(RepositoryId id)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     if (!idToObjectHashtable.ContainsKey(id))
     {
         throw new ArgumentOutOfRangeException("id");
     }
     return(this.idToObjectHashtable[id]);
 }
示例#8
0
 public RecordToken(IDataMapper <T> dataMapper, RepositoryId id)
 {
     if (dataMapper == null)
     {
         throw new ArgumentNullException("dataMapper");
     }
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     _dataMapper = dataMapper;
     _id         = id;
 }
示例#9
0
        public virtual void DeleteItem(RepositoryId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (!idToObjectHashtable.ContainsKey(id))
            {
                throw new ArgumentOutOfRangeException("id");
            }
            T item = GetItem(id);

            DeleteItem(item);
        }
示例#10
0
        private void RemoveOldTokensWithId(RepositoryId itemId)
        {
            List <KeyValuePair <RecordToken <T>, object> > oldTokensToDelete = new List <KeyValuePair <RecordToken <T>, object> >();

            foreach (KeyValuePair <RecordToken <T>, object> token in _sortedTokens)
            {
                if (token.Key.Id == itemId)
                {
                    oldTokensToDelete.Add(token);
                }
            }
            foreach (KeyValuePair <RecordToken <T>, object> pair in oldTokensToDelete)
            {
                _sortedTokens.Remove(pair.Key);
            }
        }
示例#11
0
        /// <summary>
        /// Call this method every time a cached item changes. This method verifies that the item you are trying to update exists int he repository.
        /// </summary>
        /// <param name="item"></param>
        public void UpdateItemInCache(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            RepositoryId itemId = _dataMapperQueried.GetId(item);

            RemoveOldTokensWithId(itemId);

            ResultSet <T> itemsQueryResults = QueryNewItem(item);

            foreach (RecordToken <T> token in itemsQueryResults)
            {
                if (!_sortedTokens.ContainsKey(token))
                {
                    _sortedTokens.Add(token, null);
                }
            }
        }
示例#12
0
 public override bool Equals(RepositoryId other)
 {
     return(Equals(other as MemoryRepositoryId));
 }
示例#13
0
 public override int CompareTo(RepositoryId other)
 {
     return(CompareTo(other as MemoryRepositoryId));
 }
示例#14
0
 private void CheckIfItemIsInRepository(RepositoryId id)
 {
     _dataMapperQueried.GetItem(id);
 }
示例#15
0
 public override bool Equals(RepositoryId other)
 {
     return(ReferenceEquals(this, other));
 }
示例#16
0
        public RecordToken <T> FindFirst(RepositoryId id)
        {
            int index = FindFirstIndex(id);

            return(GetItemFromIndex(index));
        }
示例#17
0
        public RecordToken <T> FindFirst(RepositoryId id, int startIndex, int count)
        {
            int index = FindFirstIndex(id, startIndex, count);

            return(GetItemFromIndex(index));
        }
示例#18
0
 public int FindFirstIndex(RepositoryId id, int startIndex)
 {
     return(_results.FindIndex(startIndex,
                               delegate(RecordToken <T> r) { return (r.Id == id); }));
 }
示例#19
0
        public int FindFirstIndex(T item)
        {
            RepositoryId id = _dataMapper.GetId(item);

            return(FindFirstIndex(id));
        }
示例#20
0
        public int FindFirstIndex(T item, int startIndex, int count)
        {
            RepositoryId id = _dataMapper.GetId(item);

            return(FindFirstIndex(id, startIndex, count));
        }