Ejemplo n.º 1
0
        /// <summary>
        /// Given that there is no pre-existing proxy.
        /// Check if the entity is already loaded. If it is, return the entity,
        /// otherwise create and return a proxy.
        /// </summary>
        private object CreateProxyIfNecessary(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext)
        {
            object existing = persistenceContext.GetEntity(keyToLoad);

            if (existing != null)
            {
                // return existing object or initialized proxy (unless deleted)
                log.Debug("entity found in session cache");
                if (options.IsCheckDeleted)
                {
                    EntityEntry entry  = persistenceContext.GetEntry(existing);
                    Status      status = entry.Status;
                    if (status == Status.Deleted || status == Status.Gone)
                    {
                        return(null);
                    }
                }
                return(existing);
            }
            else
            {
                log.Debug("creating new proxy for entity");
                // return new uninitialized proxy
                object proxy = persister.CreateProxy(@event.EntityId, @event.Session);
                persistenceContext.BatchFetchQueue.AddBatchLoadableEntityKey(keyToLoad);
                persistenceContext.AddProxy(keyToLoad, (INHibernateProxy)proxy);
                ((INHibernateProxy)proxy)
                .HibernateLazyInitializer
                .ReadOnly = @event.Session.DefaultReadOnly || !persister.IsMutable;
                return(proxy);
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Given that there is no pre-existing proxy.
		/// Check if the entity is already loaded. If it is, return the entity,
		/// otherwise create and return a proxy.
		/// </summary>
		private object CreateProxyIfNecessary(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext)
		{
			object existing = persistenceContext.GetEntity(keyToLoad);
			if (existing != null)
			{
				// return existing object or initialized proxy (unless deleted)
				log.Debug("entity found in session cache");
				if (options.IsCheckDeleted)
				{
					EntityEntry entry = persistenceContext.GetEntry(existing);
					Status status = entry.Status;
					if (status == Status.Deleted || status == Status.Gone)
					{
						return null;
					}
				}
				return existing;
			}
			else
			{
				log.Debug("creating new proxy for entity");
				// return new uninitialized proxy
				object proxy = persister.CreateProxy(@event.EntityId, @event.Session);
				persistenceContext.BatchFetchQueue.AddBatchLoadableEntityKey(keyToLoad);
				persistenceContext.AddProxy(keyToLoad, (INHibernateProxy)proxy);
				((INHibernateProxy)proxy)
					.HibernateLazyInitializer
					.ReadOnly = @event.Session.DefaultReadOnly || !persister.IsMutable;
				return proxy;
			}
		}