public DataLoaderResolver(Func <TSource, TKey> keySelector, FetchDelegate <TKey, TReturn> fetchDelegate)
 {
     _keySelector         = keySelector;
     _captureFieldContext = false;
     _loaderContext       = new DataLoaderContext();
     _loader = new DataLoader <TKey, TReturn>(fetchDelegate, _loaderContext);
 }
Ejemplo n.º 2
0
        // Fetch an object from backing store if not cached, serve from
        // cache if it is.
        //
        public virtual Object Get(string index, FetchDelegate fetch)
        {
            CacheItemBase item = GetItem(index);

            if (item != null)
            {
                return(item.Retrieve());
            }

            Object data = fetch(index);

            if (data == null)
            {
                if ((m_Flags & CacheFlags.CacheMissing) != 0)
                {
                    lock (m_Index)
                    {
                        CacheItemBase missing = new CacheItemBase(index);
                        if (!m_Index.Contains(missing))
                        {
                            m_Index.Add(missing);
                            m_Lookup[index] = missing;
                        }
                    }
                }
                return(null);
            }

            Store(index, data);
            return(data);
        }
Ejemplo n.º 3
0
        // Fetch an object from backing store if not cached, serve from
        // cache if it is.
        //
        public virtual Object Get(string index, FetchDelegate fetch)
        {
            Object item = Get(index);

            if (item != null)
            {
                return(item);
            }

            Object data = fetch(index);

            if (data == null)
            {
                if ((m_Flags & CacheFlags.CacheMissing) != 0)
                {
                    m_IndexRwLock.AcquireWriterLock(-1);
                    try
                    {
                        CacheItemBase missing = new CacheItemBase(index);
                        if (!m_Index.Contains(missing))
                        {
                            m_Index.Add(missing);
                            m_Lookup[index] = missing;
                        }
                    }
                    finally
                    {
                        m_IndexRwLock.ReleaseWriterLock();
                    }
                }
                return(null);
            }

            Store(index, data);

            return(data);
        }
        public MovieAwardsWon FetchMovieAwardsWon(int productionId)
        {
            var d = new FetchDelegate(productionId);

            return(executor.ExecuteReader(d));
        }
Ejemplo n.º 5
0
        public Oscars FetchOscars(int OscarId)
        {
            var d = new FetchDelegate(OscarId);

            return(executor.ExecuteReader(d));
        }
 public static IDataLoader <int, TReturn> GetDataLoader <TSource, TReturn>(this ResolveFieldContext <TSource> context, FetchDelegate <int, TReturn> fetchDelegate)
 {
     return(context.GetUserContext().LoadContext.GetLoader <int, TReturn>(context.FieldDefinition, fetchDelegate));
 }
 /// <summary>
 /// Configures a field to use a <see cref="DataLoaderResolver"/> to resolve batches.
 /// </summary>
 public static FieldBuilder <TSource, IEnumerable <TReturn> > BatchResolve <TSource, TKey, TReturn>(this FieldBuilder <TSource, object> fieldBuilder, Func <TSource, TKey> keySelector, FetchDelegate <TKey, TReturn> fetchDelegate)
 {
     return(fieldBuilder
            .Returns <IEnumerable <TReturn> >()
            .Resolve(new DataLoaderResolver <TSource, TKey, TReturn>(keySelector, fetchDelegate)));
 }
Ejemplo n.º 8
0
        public Sales FetchSales(int productionId)
        {
            var d = new FetchDelegate(productionId);

            return(executor.ExecuteReader(d));
        }
        public Person FetchPerson(int personId)
        {
            var d = new FetchDelegate(personId);

            return(executor.ExecuteReader(d));
        }
Ejemplo n.º 10
0
        public IndividualAwardsWon FetchIndividualAwardsWon(int productionId)
        {
            var d = new FetchDelegate(productionId);

            return(executor.ExecuteReader(d));
        }
Ejemplo n.º 11
0
        public ProductionHouse FetchProductionHouse(int productionId)
        {
            var d = new FetchDelegate(productionId);

            return(executor.ExecuteReader(d));
        }