Example #1
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     if (@event.Entity is DbObject dbObject)
     {
         dbObject.Session = @event.Session;
     }
 }
Example #2
0
 public void OnPostLoad(IUnitOfWorkTracked uow, PostLoadEvent loadEvent)
 {
     foreach (var listner in PostLoadListeners)
     {
         listner.OnPostLoad(uow, loadEvent);
     }
 }
        public void OnPostLoad(PostLoadEvent @event)
        {
            //Из-за бага\фичи в Nh, приходят по 2 одинаковых события.
            if (lastPostLoadEntity == @event.Entity)
            {
                return;
            }
            lastPostLoadEntity = @event.Entity;

            IUnitOfWorkTracked uow = GetUnitOfWork(@event.Session);

            if (uow == null)
            {
                logger.Warn("Пришло событие PostLoadEvent но соответствующий сессии UnitOfWork не найден.");
                return;
            }

            lock (PostLoadListeners)
            {
                foreach (var listner in PostLoadListeners)
                {
                    listner.OnPostLoad(uow, @event);
                }
            }

            uow.EventsTracker.OnPostLoad(uow, @event);
        }
Example #4
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     if (@event.Entity is IPersistentEntity)
     {
         (@event.Entity as IPersistentEntity).OnLoad();
     }
 }
Example #5
0
        public void OnPostLoad(PostLoadEvent @event)
        {
            var tipo   = @event.Entity.GetType();
            var entity = @event.Entity;

            Dispatch(tipo, typeof(ILoadDataHook <>), entity);
        }
 public virtual void OnPostLoad(PostLoadEvent @event)
 {
     if (@event.Persister.ImplementsLifecycle)
     {
         //log.debug( "calling onLoad()" );
         ((ILifecycle)@event.Entity).OnLoad(@event.Session, @event.Id);
     }
 }
		public virtual void OnPostLoad(PostLoadEvent @event)
		{
			if (@event.Persister.ImplementsLifecycle(@event.Session.EntityMode))
			{
				//log.debug( "calling onLoad()" );
				((ILifecycle)@event.Entity).OnLoad(@event.Session, @event.Id);
			}
		}
Example #8
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     Debug.WriteLine(string.Format("OnPostLoad - {0}", @event.Entity));
     if (@event.Entity is IDataObject)
     {
         ServiceDataAuthorizationConnector.Check((IDataObject)@event.Entity,
                                                 DataOperation.Retreive);
     }
 }
Example #9
0
    public virtual void OnPostLoad(PostLoadEvent postloadEvent)
    {
        if (postloadEvent.Entity is Employee)
        {
            var employee = (Employee)postloadEvent.Entity;

            // do what you want with the object
            employee.Gender = null;
        }
    }
Example #10
0
        public void OnPostLoad(PostLoadEvent @event)
        {
            var trackableEntity = @event.Entity as INotifyPropertyChanged;

            if (trackableEntity != null)
            {
                EntityEntry entry = @event.Session.PersistenceContext.GetEntry(@event.Entity);
                entry.BackSetStatus(Status.ReadOnly);
                entry.BackSetTracer(new EntityTracer(entry, trackableEntity));
            }
        }
Example #11
0
        public void OnPostLoad(PostLoadEvent @event)
        {
            IUnitOfWorkEventHandler uow = GetUnitOfWork(@event.Session);

            if (uow != null)
            {
                uow.OnPostLoad(@event);
            }
            else
            {
                logger.Warn("Пришло событие PostLoadEvent но соответствующий сессии UnitOfWork не найден.");
            }
        }
Example #12
0
        private object AssembleCacheEntry(CacheEntry entry, object id, IEntityPersister persister, LoadEvent @event)
        {
            object       optionalObject        = @event.InstanceToLoad;
            IEventSource session               = @event.Session;
            ISessionFactoryImplementor factory = session.Factory;

            if (log.IsDebugEnabled)
            {
                log.Debug("assembling entity from second-level cache: " + MessageHelper.InfoString(persister, id, factory));
            }

            IEntityPersister subclassPersister = factory.GetEntityPersister(entry.Subclass);
            object           result            = optionalObject ?? session.Instantiate(subclassPersister, id);

            // make it circular-reference safe
            TwoPhaseLoad.AddUninitializedCachedEntity(new EntityKey(id, subclassPersister, session.EntityMode), result, subclassPersister, LockMode.None, entry.AreLazyPropertiesUnfetched, entry.Version, session);

            IType[]  types  = subclassPersister.PropertyTypes;
            object[] values = entry.Assemble(result, id, subclassPersister, session.Interceptor, session);             // intializes result by side-effect
            TypeFactory.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session);

            object version = Versioning.GetVersion(values, subclassPersister);

            if (log.IsDebugEnabled)
            {
                log.Debug("Cached Version: " + version);
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;

            persistenceContext.AddEntry(result, Status.Loaded, values, null, id, version, LockMode.None, true, subclassPersister, false, entry.AreLazyPropertiesUnfetched);
            subclassPersister.AfterInitialize(result, entry.AreLazyPropertiesUnfetched, session);
            persistenceContext.InitializeNonLazyCollections();
            // upgrade the lock if necessary:
            //lock(result, lockMode);

            //PostLoad is needed for EJB3
            //TODO: reuse the PostLoadEvent...
            PostLoadEvent postLoadEvent = new PostLoadEvent(session);

            postLoadEvent.Entity    = result;
            postLoadEvent.Id        = id;
            postLoadEvent.Persister = persister;

            IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
            for (int i = 0; i < listeners.Length; i++)
            {
                listeners[i].OnPostLoad(postLoadEvent);
            }
            return(result);
        }
Example #13
0
        public void OnPostLoad(PostLoadEvent ev)
        {
            var networkNode = ev.Entity as MongoNode;

            if (networkNode == null)
            {
                return;
            }

            var repository = new NodeLinkRepository();
            IList <NodeLink> linksFromMongo = repository.GetLinks(networkNode.Id);

            HashSet <NodeLink> links = (HashSet <NodeLink>)networkNode
                                       .GetType()
                                       .GetProperty("LinksInternal", BindingFlags.NonPublic | BindingFlags.Instance)
                                       .GetValue(networkNode);

            links.UnionWith(linksFromMongo);
        }
        public override void OnPostLoad(PostLoadEvent @event)
        {
            if (@event.Entity is Cargo)
            {
                /*
                 * Itinerary is a column-less component with a collection field,
                 * and there's no way (that I know of) to map this behaviour in metadata.
                 *
                 * Hibernate is all about reflection, so helping the mapping along with
                 * another field manipulation is OK. This avoids the need for a public method
                 * on Cargo.
                 */
                Cargo cargo = (Cargo)@event.Entity;
                if (cargo.Itinerary != null && !cargo.Itinerary.Legs.Any())
                {
                    ItineraryProperty.SetValue(cargo, null, null);
                }
            }

            base.OnPostLoad(@event);
        }
Example #15
0
 public void OnPostLoad(PostLoadEvent e)
 {
     _checker.Load(e.Entity as IEntity);
 }
Example #16
0
        public void OnPostLoad(PostLoadEvent @event)
        {
            EntityEntry entry = @event.Session.PersistenceContext.GetEntry(@event.Entity);

            entry.BackSetStatus(Status.ReadOnly);
        }
        /// <summary>
        /// Perform the second step of 2-phase load. Fully initialize the entity instance.
        /// After processing a JDBC result set, we "resolve" all the associations
        /// between the entities which were instantiated and had their state
        /// "hydrated" into an array
        /// </summary>
        public static async Task InitializeEntityAsync(object entity, bool readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //TODO: Should this be an InitializeEntityEventListener??? (watch out for performance!)

            bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled;
            var  stopWath     = new Stopwatch();

            if (statsEnabled)
            {
                stopWath.Start();
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;
            EntityEntry         entityEntry        = persistenceContext.GetEntry(entity);

            if (entityEntry == null)
            {
                throw new AssertionFailure("possible non-threadsafe access to the session");
            }
            IEntityPersister persister = entityEntry.Persister;
            object           id        = entityEntry.Id;

            object[] hydratedState = entityEntry.LoadedState;

            if (log.IsDebugEnabled)
            {
                log.Debug("resolving associations for " + MessageHelper.InfoString(persister, id, session.Factory));
            }

            IType[] types = persister.PropertyTypes;
            for (int i = 0; i < hydratedState.Length; i++)
            {
                object value = hydratedState[i];
                if (!Equals(LazyPropertyInitializer.UnfetchedProperty, value) && !(Equals(BackrefPropertyAccessor.Unknown, value)))
                {
                    hydratedState[i] = await(types[i].ResolveIdentifierAsync(value, session, entity, cancellationToken)).ConfigureAwait(false);
                }
            }

            //Must occur after resolving identifiers!
            if (session.IsEventSource)
            {
                preLoadEvent.Entity    = entity;
                preLoadEvent.State     = hydratedState;
                preLoadEvent.Id        = id;
                preLoadEvent.Persister = persister;
                IPreLoadEventListener[] listeners = session.Listeners.PreLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    await(listeners[i].OnPreLoadAsync(preLoadEvent, cancellationToken)).ConfigureAwait(false);
                }
            }

            persister.SetPropertyValues(entity, hydratedState);

            ISessionFactoryImplementor factory = session.Factory;

            if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Put))
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("adding entity to second-level cache: " + MessageHelper.InfoString(persister, id, session.Factory));
                }

                object     version = Versioning.GetVersion(hydratedState, persister);
                CacheEntry entry   =
                    new CacheEntry(hydratedState, persister, entityEntry.LoadedWithLazyPropertiesUnfetched, version, session, entity);
                CacheKey cacheKey = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);
                bool     put      =
                    await(persister.Cache.PutAsync(cacheKey, persister.CacheEntryStructure.Structure(entry), session.Timestamp, version,
                                                   persister.IsVersioned ? persister.VersionType.Comparator : null,
                                                   UseMinimalPuts(session, entityEntry), cancellationToken)).ConfigureAwait(false);

                if (put && factory.Statistics.IsStatisticsEnabled)
                {
                    factory.StatisticsImplementor.SecondLevelCachePut(persister.Cache.RegionName);
                }
            }

            bool isReallyReadOnly = readOnly;

            if (!persister.IsMutable)
            {
                isReallyReadOnly = true;
            }
            else
            {
                object proxy = persistenceContext.GetProxy(entityEntry.EntityKey);
                if (proxy != null)
                {
                    // there is already a proxy for this impl
                    // only set the status to read-only if the proxy is read-only
                    isReallyReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
                }
            }

            if (isReallyReadOnly)
            {
                //no need to take a snapshot - this is a
                //performance optimization, but not really
                //important, except for entities with huge
                //mutable property values
                persistenceContext.SetEntryStatus(entityEntry, Status.ReadOnly);
            }
            else
            {
                //take a snapshot
                TypeHelper.DeepCopy(hydratedState, persister.PropertyTypes, persister.PropertyUpdateability, hydratedState, session);
                persistenceContext.SetEntryStatus(entityEntry, Status.Loaded);
            }

            persister.AfterInitialize(entity, entityEntry.LoadedWithLazyPropertiesUnfetched, session);

            if (session.IsEventSource)
            {
                postLoadEvent.Entity    = entity;
                postLoadEvent.Id        = id;
                postLoadEvent.Persister = persister;
                IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    listeners[i].OnPostLoad(postLoadEvent);
                }
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("done materializing entity " + MessageHelper.InfoString(persister, id, session.Factory));
            }

            if (statsEnabled)
            {
                stopWath.Stop();
                factory.StatisticsImplementor.LoadEntity(persister.EntityName, stopWath.Elapsed);
            }
        }
Example #18
0
		private object AssembleCacheEntry(CacheEntry entry, object id, IEntityPersister persister, LoadEvent @event)
		{
			object optionalObject = @event.InstanceToLoad;
			IEventSource session = @event.Session;
			ISessionFactoryImplementor factory = session.Factory;

			if (log.IsDebugEnabled)
			{
				log.Debug("assembling entity from second-level cache: " + MessageHelper.InfoString(persister, id, factory));
			}

			IEntityPersister subclassPersister = factory.GetEntityPersister(entry.Subclass);
			object result = optionalObject ?? session.Instantiate(subclassPersister, id);

			// make it circular-reference safe
			EntityKey entityKey = new EntityKey(id, subclassPersister, session.EntityMode);
			TwoPhaseLoad.AddUninitializedCachedEntity(entityKey, result, subclassPersister, LockMode.None, entry.AreLazyPropertiesUnfetched, entry.Version, session);

			IType[] types = subclassPersister.PropertyTypes;
			object[] values = entry.Assemble(result, id, subclassPersister, session.Interceptor, session); // intializes result by side-effect
			TypeHelper.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session);

			object version = Versioning.GetVersion(values, subclassPersister);
			if (log.IsDebugEnabled)
			{
				log.Debug("Cached Version: " + version);
			}

			IPersistenceContext persistenceContext = session.PersistenceContext;
			bool isReadOnly = session.DefaultReadOnly;

			if (persister.IsMutable)
			{
				object proxy = persistenceContext.GetProxy(entityKey);
				if (proxy != null)
				{
					// this is already a proxy for this impl
					// only set the status to read-only if the proxy is read-only
					isReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
				}
			}
			else
				isReadOnly = true;
			
			persistenceContext.AddEntry(
				result,
				isReadOnly ? Status.ReadOnly : Status.Loaded,
				values,
				null,
				id,
				version,
				LockMode.None,
				true,
				subclassPersister,
				false,
				entry.AreLazyPropertiesUnfetched);
			
			subclassPersister.AfterInitialize(result, entry.AreLazyPropertiesUnfetched, session);
			persistenceContext.InitializeNonLazyCollections();
			// upgrade the lock if necessary:
			//lock(result, lockMode);

			//PostLoad is needed for EJB3
			//TODO: reuse the PostLoadEvent...
			PostLoadEvent postLoadEvent = new PostLoadEvent(session);
			postLoadEvent.Entity = result;
			postLoadEvent.Id = id;
			postLoadEvent.Persister = persister;

			IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
			for (int i = 0; i < listeners.Length; i++)
			{
				listeners[i].OnPostLoad(postLoadEvent);
			}
			return result;
		}
Example #19
0
        private async Task <object> AssembleCacheEntryAsync(CacheEntry entry, object id, IEntityPersister persister, LoadEvent @event, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            object       optionalObject        = @event.InstanceToLoad;
            IEventSource session               = @event.Session;
            ISessionFactoryImplementor factory = session.Factory;

            if (log.IsDebugEnabled())
            {
                log.Debug("assembling entity from second-level cache: {0}", MessageHelper.InfoString(persister, id, factory));
            }

            IEntityPersister subclassPersister = factory.GetEntityPersister(entry.Subclass);
            object           result            = optionalObject ?? session.Instantiate(subclassPersister, id);

            // make it circular-reference safe
            EntityKey entityKey = session.GenerateEntityKey(id, subclassPersister);

            TwoPhaseLoad.AddUninitializedCachedEntity(entityKey, result, subclassPersister, LockMode.None, entry.Version, session);

            IType[]  types  = subclassPersister.PropertyTypes;
            object[] values = await(entry.AssembleAsync(result, id, subclassPersister, session.Interceptor, session, cancellationToken)).ConfigureAwait(false);              // intializes result by side-effect
            TypeHelper.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session);

            object version = Versioning.GetVersion(values, subclassPersister);

            if (log.IsDebugEnabled())
            {
                log.Debug("Cached Version: {0}", version);
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;
            bool isReadOnly = session.DefaultReadOnly;

            if (persister.IsMutable)
            {
                object proxy = persistenceContext.GetProxy(entityKey);
                if (proxy != null)
                {
                    // this is already a proxy for this impl
                    // only set the status to read-only if the proxy is read-only
                    isReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
                }
            }
            else
            {
                isReadOnly = true;
            }

            persistenceContext.AddEntry(
                result,
                isReadOnly ? Status.ReadOnly : Status.Loaded,
                values,
                null,
                id,
                version,
                LockMode.None,
                true,
                subclassPersister,
                false);

            subclassPersister.AfterInitialize(result, session);
            await(persistenceContext.InitializeNonLazyCollectionsAsync(cancellationToken)).ConfigureAwait(false);
            // upgrade the lock if necessary:
            //lock(result, lockMode);

            //PostLoad is needed for EJB3
            //TODO: reuse the PostLoadEvent...
            PostLoadEvent postLoadEvent = new PostLoadEvent(session);

            postLoadEvent.Entity    = result;
            postLoadEvent.Id        = id;
            postLoadEvent.Persister = persister;

            IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
            for (int i = 0; i < listeners.Length; i++)
            {
                listeners[i].OnPostLoad(postLoadEvent);
            }
            return(result);
        }
Example #20
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     EventDispatcher.RaiseEvent(@event.Entity, typeof(LoadedEvent));
 }
Example #21
0
        public static void SwitchDreamLevel(string levelPath, string spawnPoint = "")
        {
            PostLoadEvent = null;

            if (_loadedDreamObject)
            {
                UnityEngine.Object.Destroy(_loadedDreamObject);
                ResourceManager.ClearLifespan(ResourceLifespan.LEVEL);
            }

            GameObject.FindGameObjectWithTag("EnvironmentController")
            .GetComponent <EnvironmentController>()
            .EnvironmentEntity = null;

            PlayerSpawns.Clear();
            PlayerSpawnForced = false;

            Target.Targets.Clear();
            ActionSequence.Sequences.Clear();

            TMAP t;

            _loadedDreamObject = IOUtil.LoadToriiMap(levelPath, ResourceLifespan.DREAM, out t);
            Payload.LevelsVisited.Add(t.Header.Name);

            if (PlayerSpawns.Count > 0)
            {
                int spawnPointHandle = 0;
                if (spawnPoint.Equals(string.Empty))                 // random spawn point
                {
                    spawnPointHandle = (PlayerSpawnForced || CurrentDay == 1)
                                                ? ForcedSpawnIndex
                                                : RandUtil.Int(0, PlayerSpawns.Count);
                }
                else
                {
                    // named spawn point
                    for (int i = 0; i < PlayerSpawns.Count; i++)
                    {
                        if (PlayerSpawns[i].Name.Equals(spawnPoint))
                        {
                            spawnPointHandle = i;
                        }
                    }
                }
                Vector3 spawnPos = SetPlayerSpawn(PlayerSpawns[spawnPointHandle].transform);

                Player.transform.position = spawnPos;
                Player.transform.rotation = Quaternion.Euler(0, PlayerSpawns[spawnPointHandle].transform.rotation.eulerAngles.y, 0);
            }
            else
            {
                Debug.LogError("There are no player_spawn entities in the level, cannot spawn player!");
            }

            if (PostLoadEvent != null)
            {
                PostLoadEvent.Invoke();
            }
            if (OnLevelFinishChange != null)
            {
                OnLevelFinishChange.Invoke();
            }
        }
Example #22
0
 public void OnPostLoad(PostLoadEvent @event)
 {
 }
 public void OnPostLoad(PostLoadEvent @event)
 {
     if (@event != null && @event.Entity != null)
         @event.Entity.EnableInvariantEvaluation(true);
 }
Example #24
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     Console.WriteLine(@event.Entity.ToString());
 }
Example #25
0
 /// <summary>
 /// Perform the second step of 2-phase load. Fully initialize the entity instance.
 /// After processing a JDBC result set, we "resolve" all the associations
 /// between the entities which were instantiated and had their state
 /// "hydrated" into an array
 /// </summary>
 public static Task InitializeEntityAsync(object entity, bool readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return(Task.FromCanceled <object>(cancellationToken));
     }
     return(InitializeEntityAsync(entity, readOnly, session, preLoadEvent, postLoadEvent, null, cancellationToken));
 }
Example #26
0
 /// <summary>
 /// Perform the second step of 2-phase load. Fully initialize the entity instance.
 /// After processing a JDBC result set, we "resolve" all the associations
 /// between the entities which were instantiated and had their state
 /// "hydrated" into an array
 /// </summary>
 public static void InitializeEntity(object entity, bool readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent)
 {
     InitializeEntity(entity, readOnly, session, preLoadEvent, postLoadEvent, null);
 }
Example #27
0
 void IUnitOfWorkEventHandler.OnPostLoad(PostLoadEvent loadEvent)
 {
 }
 public void OnPostLoad(PostLoadEvent @event)
 {
     SetReadOnlyEntity(@event.Session, @event.Entity);
 }
Example #29
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     InitialializeRelations(@event.Entity as ContentItem, @event.Session);
     InitialializeRelations(@event.Entity as ContentVersion, @event.Session);
     InitialializeRelations(@event.Entity as ContentDetail, @event.Session);
 }
Example #30
0
 /// <summary>
 /// Triggered when the connection tree and all plugins have loaded
 /// </summary>
 /// <param name="context">The current state of the application</param>
 public void PostLoad(IPluginContext context)
 {
     PostLoadEvent?.Invoke(context, new RdcManEventArgs(pluginContext));
 }
Example #31
0
        /// <summary>
        /// Perform the second step of 2-phase load. Fully initialize the entity instance.
        /// After processing a JDBC result set, we "resolve" all the associations
        /// between the entities which were instantiated and had their state
        /// "hydrated" into an array
        /// </summary>
        internal static void InitializeEntity(object entity, bool readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent,
                                              Action <IEntityPersister, CachePutData> cacheBatchingHandler)
        {
            //TODO: Should this be an InitializeEntityEventListener??? (watch out for performance!)

            bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled;
            var  stopWath     = new Stopwatch();

            if (statsEnabled)
            {
                stopWath.Start();
            }

            IPersistenceContext persistenceContext = session.PersistenceContext;
            EntityEntry         entityEntry        = persistenceContext.GetEntry(entity);

            if (entityEntry == null)
            {
                throw new AssertionFailure("possible non-threadsafe access to the session");
            }
            IEntityPersister persister = entityEntry.Persister;
            object           id        = entityEntry.Id;

            object[] hydratedState = entityEntry.LoadedState;

            if (log.IsDebugEnabled())
            {
                log.Debug("resolving associations for {0}", MessageHelper.InfoString(persister, id, session.Factory));
            }

            IType[] types = persister.PropertyTypes;
            var     collectionToResolveIndexes = new List <int>(hydratedState.Length);

            for (int i = 0; i < hydratedState.Length; i++)
            {
                object value = hydratedState[i];
                if (!Equals(LazyPropertyInitializer.UnfetchedProperty, value) && !(Equals(BackrefPropertyAccessor.Unknown, value)))
                {
                    if (types[i].IsCollectionType)
                    {
                        // Resolve them last, because they may depend on other properties if they use a property-ref
                        collectionToResolveIndexes.Add(i);
                        continue;
                    }

                    hydratedState[i] = types[i].ResolveIdentifier(value, session, entity);
                }
            }

            foreach (var i in collectionToResolveIndexes)
            {
                hydratedState[i] = types[i].ResolveIdentifier(hydratedState[i], session, entity);
            }

            //Must occur after resolving identifiers!
            if (session.IsEventSource)
            {
                preLoadEvent.Entity    = entity;
                preLoadEvent.State     = hydratedState;
                preLoadEvent.Id        = id;
                preLoadEvent.Persister = persister;
                IPreLoadEventListener[] listeners = session.Listeners.PreLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    listeners[i].OnPreLoad(preLoadEvent);
                }
            }

            persister.SetPropertyValues(entity, hydratedState);

            ISessionFactoryImplementor factory = session.Factory;

            if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Put))
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("adding entity to second-level cache: {0}", MessageHelper.InfoString(persister, id, session.Factory));
                }

                object     version = Versioning.GetVersion(hydratedState, persister);
                CacheEntry entry   =
                    CacheEntry.Create(hydratedState, persister, version, session, entity);
                CacheKey cacheKey = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName);

                if (cacheBatchingHandler != null && persister.IsBatchLoadable)
                {
                    cacheBatchingHandler(
                        persister,
                        new CachePutData(
                            cacheKey,
                            persister.CacheEntryStructure.Structure(entry),
                            version,
                            persister.IsVersioned ? persister.VersionType.Comparator : null,
                            UseMinimalPuts(session, entityEntry)));
                }
                else
                {
                    bool put =
                        persister.Cache.Put(cacheKey, persister.CacheEntryStructure.Structure(entry), session.Timestamp, version,
                                            persister.IsVersioned ? persister.VersionType.Comparator : null,
                                            UseMinimalPuts(session, entityEntry));

                    if (put && factory.Statistics.IsStatisticsEnabled)
                    {
                        factory.StatisticsImplementor.SecondLevelCachePut(persister.Cache.RegionName);
                    }
                }
            }

            bool isReallyReadOnly = readOnly;

            if (!persister.IsMutable)
            {
                isReallyReadOnly = true;
            }
            else
            {
                object proxy = persistenceContext.GetProxy(entityEntry.EntityKey);
                if (proxy != null)
                {
                    // there is already a proxy for this impl
                    // only set the status to read-only if the proxy is read-only
                    isReallyReadOnly = ((INHibernateProxy)proxy).HibernateLazyInitializer.ReadOnly;
                }
            }

            if (isReallyReadOnly)
            {
                //no need to take a snapshot - this is a
                //performance optimization, but not really
                //important, except for entities with huge
                //mutable property values
                persistenceContext.SetEntryStatus(entityEntry, Status.ReadOnly);
            }
            else
            {
                //take a snapshot
                TypeHelper.DeepCopy(hydratedState, persister.PropertyTypes, persister.PropertyUpdateability, hydratedState, session);
                persistenceContext.SetEntryStatus(entityEntry, Status.Loaded);
            }

            persister.AfterInitialize(entity, session);

            if (session.IsEventSource)
            {
                postLoadEvent.Entity    = entity;
                postLoadEvent.Id        = id;
                postLoadEvent.Persister = persister;
                IPostLoadEventListener[] listeners = session.Listeners.PostLoadEventListeners;
                for (int i = 0; i < listeners.Length; i++)
                {
                    listeners[i].OnPostLoad(postLoadEvent);
                }
            }

            if (log.IsDebugEnabled())
            {
                log.Debug("done materializing entity {0}", MessageHelper.InfoString(persister, id, session.Factory));
            }

            if (statsEnabled)
            {
                stopWath.Stop();
                factory.StatisticsImplementor.LoadEntity(persister.EntityName, stopWath.Elapsed);
            }
        }
Example #32
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     //RepositoryFramework.RaisePostLoad(@event.Entity);
 }