public void DeleteItemFromCaches(RepositoryId id) { foreach (KeyValuePair <string, ResultSetCache <T> > pair in labelToResultSetCacheMap) { pair.Value.DeleteItemFromCache(id); } }
public RepositoryId[] GetAllItems() { int numberOfIds = idToObjectHashtable.Keys.Count; RepositoryId[] ids = new RepositoryId[numberOfIds]; idToObjectHashtable.Keys.CopyTo(ids, 0); return(ids); }
public void DeleteItemFromCache(RepositoryId id) { if (id == null) { throw new ArgumentNullException("id"); } CheckIfItemIsInRepository(id); RemoveOldTokensWithId(id); }
public void DeleteItemFromCache(T item) { if (item == null) { throw new ArgumentNullException("item"); } RepositoryId id = _dataMapperQueried.GetId(item); DeleteItemFromCache(id); }
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 }
public override int CompareTo(RepositoryId other) { if (other == null) { return(1); } if (other is EmptyRepositoryId) { return(0); } return(-1); }
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]); }
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; }
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); }
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); } }
/// <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); } } }
public override bool Equals(RepositoryId other) { return(Equals(other as MemoryRepositoryId)); }
public override int CompareTo(RepositoryId other) { return(CompareTo(other as MemoryRepositoryId)); }
private void CheckIfItemIsInRepository(RepositoryId id) { _dataMapperQueried.GetItem(id); }
public override bool Equals(RepositoryId other) { return(ReferenceEquals(this, other)); }
public RecordToken <T> FindFirst(RepositoryId id) { int index = FindFirstIndex(id); return(GetItemFromIndex(index)); }
public RecordToken <T> FindFirst(RepositoryId id, int startIndex, int count) { int index = FindFirstIndex(id, startIndex, count); return(GetItemFromIndex(index)); }
public int FindFirstIndex(RepositoryId id, int startIndex) { return(_results.FindIndex(startIndex, delegate(RecordToken <T> r) { return (r.Id == id); })); }
public int FindFirstIndex(T item) { RepositoryId id = _dataMapper.GetId(item); return(FindFirstIndex(id)); }
public int FindFirstIndex(T item, int startIndex, int count) { RepositoryId id = _dataMapper.GetId(item); return(FindFirstIndex(id, startIndex, count)); }