Esempio n. 1
0
 public void RaiseInvalidate(QuerySetStorageKey key)
 {
     this.Invalidate(
         this,
         new QuerySetStorageInvalidateEventArgs(key)
     );
 }
Esempio n. 2
0
 public void Set(QuerySetStorageKey key, IModel o)
 {
     if (cache.Count >= MAX_ENTRIES)
     {
         foreach (QuerySetStorageKey k in cache.Keys)
         {
             cache.Remove(k);
             this.RaiseInvalidate(k);
             break;
         }
     }
     cache[key] = o;
     this.RaiseInvalidate(key);
 }
Esempio n. 3
0
 public IModel Get(QuerySetStorageKey key)
 {
     return cache[key];
 }
Esempio n. 4
0
 public void Delete(QuerySetStorageKey key)
 {
     cache.Remove(key);
 }
Esempio n. 5
0
 public bool Equals(QuerySetStorageKey other)
 {
     return this.GetHashCode() == other.GetHashCode();
 }
Esempio n. 6
0
 public QuerySetStorageInvalidateEventArgs(QuerySetStorageKey key)
 {
     this.Key = key;
 }
Esempio n. 7
0
        public IEnumerator<IModel> GetEnumerator()
        {
            Connections.IConnection conn = new Connections.Connection();
            object[][] res = conn.Execute(this.query);
            IModel o;
            Dictionary<string, object> dict;
            QuerySetStorageKey storage_key;
            foreach (object[] row in res)
            {
                // need to instantiate a model here, to get the ModelMeta
                o = (IModel)(Activator.CreateInstance(this.query.Model));

                storage_key = new QuerySetStorageKey(
                    this.query.Model,
                    row[o.Meta.GetFieldIndex(o.Meta.PrimaryKey.DbField)]
                );
                try
                {
                    o = storage.Get(storage_key);
                }
                catch (KeyNotFoundException)
                {
                    dict = o.Meta.PrepareRowForInstance(row);
                    foreach (string key in dict.Keys)
                    {
                        o.Set(key, dict[key]);
                    }
                    this.storage.Set(storage_key, o);
                }
                yield return o;
            }
        }