Esempio n. 1
0
        public void Handle(IList <IObjectFuture> objectFutures)
        {
            IEntityFactory  entityFactory = EntityFactory;
            IList <IObjRef> oris          = new List <IObjRef>(objectFutures.Count);

            // ObjectFutures have to be handled in order
            for (int i = 0, size = objectFutures.Count; i < size; i++)
            {
                IObjectFuture objectFuture = objectFutures[i];
                if (!(objectFuture is ObjRefFuture))
                {
                    throw new ArgumentException("'" + GetType().Name + "' cannot handle " + typeof(IObjectFuture).Name
                                                + " implementations of type '" + objectFuture.GetType().Name + "'");
                }
                if (objectFuture.Value != null)
                {
                    continue;
                }

                ObjRefFuture objRefFuture = (ObjRefFuture)objectFuture;
                IObjRef      ori          = objRefFuture.Ori;
                if (ori.Id != null && !Object.Equals(ori.Id, 0))
                {
                    oris.Add(ori);
                }
                else if (ori is IDirectObjRef && ((IDirectObjRef)ori).Direct != null)
                {
                    Object entity = ((IDirectObjRef)ori).Direct;
                    objRefFuture.Value = entity;
                    oris.Add(null);
                }
                else
                {
                    Object newEntity = entityFactory.CreateEntity(ori.RealType);
                    objRefFuture.Value = newEntity;
                    oris.Add(null);
                }
            }

            IList <Object> objects = Cache.GetObjects(oris, CacheDirective.ReturnMisses);

            for (int i = 0, size = objectFutures.Count; i < size; i++)
            {
                if (oris[i] == null)
                {
                    continue;
                }

                ObjRefFuture objRefFuture = (ObjRefFuture)objectFutures[i];
                Object       obj          = objects[i];
                objRefFuture.Value = obj;
            }
        }
Esempio n. 2
0
        public void Handle(IList <IObjectFuture> objectFutures)
        {
            List <IEnumerable> allToPrefetch = new List <IEnumerable>(objectFutures.Count);

            for (int i = 0, size = objectFutures.Count; i < size; i++)
            {
                IObjectFuture objectFuture = objectFutures[i];
                if (!(objectFuture is PrefetchFuture))
                {
                    throw new ArgumentException("'" + GetType().Name + "' cannot handle " + typeof(IObjectFuture).Name
                                                + " implementations of type '" + objectFuture.GetType().Name + "'");
                }

                PrefetchFuture prefetchFuture = (PrefetchFuture)objectFuture;
                IEnumerable    toPrefetch     = prefetchFuture.ToPrefetch;
                allToPrefetch.Add(toPrefetch);
            }

            PrefetchHelper.Prefetch(allToPrefetch);
        }
Esempio n. 3
0
        protected IDictionary <Type, ISet <IObjectFuture> > BucketSortObjectFutures(IList <IObjectCommand> objectCommands)
        {
            IDictionary <Type, ISet <IObjectFuture> > sortedObjectFutures = new Dictionary <Type, ISet <IObjectFuture> >((int)(objectCommands.Count / 0.75));

            for (int i = 0, size = objectCommands.Count; i < size; i++)
            {
                IObjectCommand objectCommand = objectCommands[i];
                IObjectFuture  objectFuture  = objectCommand.ObjectFuture;
                if (objectFuture != null)
                {
                    Type type = objectFuture.GetType();
                    ISet <IObjectFuture> objectFutures = DictionaryExtension.ValueOrDefault(sortedObjectFutures, type);
                    if (objectFutures == null)
                    {
                        objectFutures = new HashSet <IObjectFuture>();
                        sortedObjectFutures.Add(type, objectFutures);
                    }
                    objectFutures.Add(objectFuture);
                }
            }

            return(sortedObjectFutures);
        }