示例#1
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     var persistableObject = @event.Entity as IPersistableObject;
     if (persistableObject != null)
     {
         persistableObject.SysState = EntityStateEnum.Unchanged;
     }
 }
 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);
     }
 }
        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);
        }
示例#4
0
		internal void InitializeEntitiesAndCollections(IList hydratedObjects, object resultSetId, ISessionImplementor session,
		                                               bool readOnly)
		{
			ICollectionPersister[] collectionPersisters = CollectionPersisters;
			if (collectionPersisters != null)
			{
				for (int i = 0; i < collectionPersisters.Length; i++)
				{
					if (collectionPersisters[i].IsArray)
					{
						//for arrays, we should end the collection load before resolving
						//the entities, since the actual array instances are not instantiated
						//during loading
						//TODO: or we could do this polymorphically, and have two
						//      different operations implemented differently for arrays
						EndCollectionLoad(resultSetId, session, collectionPersisters[i]);
					}
				}
			}
			//important: reuse the same event instances for performance!
			PreLoadEvent pre;
			PostLoadEvent post;
			if (session.IsEventSource)
			{
				var eventSourceSession = (IEventSource) session;
				pre = new PreLoadEvent(eventSourceSession);
				post = new PostLoadEvent(eventSourceSession);
			}
			else
			{
				pre = null;
				post = null;
			}

			if (hydratedObjects != null)
			{
				int hydratedObjectsSize = hydratedObjects.Count;

				if (log.IsDebugEnabled)
				{
					log.Debug(string.Format("total objects hydrated: {0}", hydratedObjectsSize));
				}

				for (int i = 0; i < hydratedObjectsSize; i++)
				{
					TwoPhaseLoad.InitializeEntity(hydratedObjects[i], readOnly, session, pre, post);
				}
			}

			if (collectionPersisters != null)
			{
				for (int i = 0; i < collectionPersisters.Length; i++)
				{
					if (!collectionPersisters[i].IsArray)
					{
						//for sets, we should end the collection load after resolving
						//the entities, since we might call hashCode() on the elements
						//TODO: or we could do this polymorphically, and have two
						//      different operations implemented differently for arrays
						EndCollectionLoad(resultSetId, session, collectionPersisters[i]);
					}
				}
			}
		}
示例#5
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)
        {
            //TODO: Should this be an InitializeEntityEventListener??? (watch out for performance!)
            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 (value != LazyPropertyInitializer.UnfetchedProperty && value != BackrefPropertyAccessor.Unknown)
                {
                    hydratedState[i] = types[i].ResolveIdentifier(value, 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, session.EntityMode);

            ISessionFactoryImplementor factory = session.Factory;

            if (persister.HasCache && ((session.CacheMode & CacheMode.Put) == 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 = new CacheKey(id, persister.IdentifierType, persister.RootEntityName, session.EntityMode, session.Factory);
                bool put =
                    persister.Cache.Put(cacheKey, entry, session.Timestamp, version,
                                        persister.IsVersioned ? persister.VersionType.Comparator : null,
                                        UseMinimalPuts(session, entityEntry));
                //we could use persister.hasLazyProperties() instead of true

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

            if (readOnly || !persister.IsMutable)
            {
                //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
                TypeFactory.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 (factory.Statistics.IsStatisticsEnabled)
            {
                factory.StatisticsImplementor.LoadEntity(persister.EntityName);
            }
        }
 public void OnPostLoad(PostLoadEvent @event)
 {
 }
		public void OnPostLoad(PostLoadEvent @event)
		{
			SetReadOnlyEntity(@event.Session, @event.Entity);
		}
示例#8
0
 public void OnPostLoad(PostLoadEvent @event)
 {
     Debug.WriteLine("EventListener.OnPostLoad: {0}", @event.Id);
 }
 public override void OnPostLoad(PostLoadEvent @event)
 {
     base.OnPostLoad(@event);
 }
			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);
			}
 public void OnPostLoad(PostLoadEvent @event)
 {
     log.Debug("OnPostLoad :" + @event);
 }
 public void OnPostLoad(PostLoadEvent @event)
 {
     EventDispatcher.RaiseEvent(@event.Entity, typeof (LoadedEvent));
 }