Пример #1
0
        protected IEnumerable <AuditLogEntry> CreateCollectionEntries(object affectedOwnerOrNull, Guid id, IPersistentCollection collection)
        {
            var typeName = affectedOwnerOrNull.GetType().Name;

            var excludedProperties = GetExcludedProperties(affectedOwnerOrNull.GetType());

            if (excludedProperties.Any(p => collection.Role.EndsWith(p)) || !(collection.GetValue() is IEnumerable <EntityBase>))
            {
                yield break;
            }

            var newList = ((IEnumerable <EntityBase>)collection.GetValue()).ToList();
            var oldList = ((List <object>)collection.StoredSnapshot).OfType <EntityBase>().ToList();

            foreach (
                var entry in
                ParseCollectionEntries(oldList, newList, typeName,
                                       collection.Role.Replace("Prototype1.Declarations.Entities." + typeName + ".", ""), id))
            {
                yield return(entry);
            }
        }
Пример #2
0
        public object GetCollection(object key, ISessionImplementor session, object owner)
        {
            ICollectionPersister persister          = GetPersister(session);
            IPersistenceContext  persistenceContext = session.PersistenceContext;
            EntityMode           entityMode         = session.EntityMode;

            if (entityMode == EntityMode.Xml && !isEmbeddedInXML)
            {
                return(UnfetchedCollection);
            }

            // check if collection is currently being loaded
            IPersistentCollection collection = persistenceContext.LoadContexts.LocateLoadingCollection(persister, key);

            if (collection == null)
            {
                // check if it is already completely loaded, but unowned
                collection = persistenceContext.UseUnownedCollection(new CollectionKey(persister, key, entityMode));
                if (collection == null)
                {
                    // create a new collection wrapper, to be initialized later
                    collection       = Instantiate(session, persister, key);
                    collection.Owner = owner;

                    persistenceContext.AddUninitializedCollection(persister, collection, key);

                    // some collections are not lazy:
                    if (InitializeImmediately(entityMode))
                    {
                        session.InitializeCollection(collection, false);
                    }
                    else if (!persister.IsLazy)
                    {
                        persistenceContext.AddNonLazyCollection(collection);
                    }

                    if (HasHolder(entityMode))
                    {
                        session.PersistenceContext.AddCollectionHolder(collection);
                    }
                }

                if (log.IsDebugEnabled)
                {
                    log.Debug("Created collection wrapper: " + MessageHelper.CollectionInfoString(persister, collection, key, session));
                }
            }
            collection.Owner = owner;
            return(collection.GetValue());
        }
Пример #3
0
        public async Task <object> GetCollectionAsync(object key, ISessionImplementor session, object owner, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ICollectionPersister persister          = GetPersister(session);
            IPersistenceContext  persistenceContext = session.PersistenceContext;

            // check if collection is currently being loaded
            IPersistentCollection collection = persistenceContext.LoadContexts.LocateLoadingCollection(persister, key);

            if (collection == null)
            {
                // check if it is already completely loaded, but unowned
                collection = persistenceContext.UseUnownedCollection(new CollectionKey(persister, key));
                if (collection == null)
                {
                    // create a new collection wrapper, to be initialized later
                    collection       = Instantiate(session, persister, key);
                    collection.Owner = owner;

                    persistenceContext.AddUninitializedCollection(persister, collection, key);

                    // some collections are not lazy:
                    if (InitializeImmediately())
                    {
                        await(session.InitializeCollectionAsync(collection, false, cancellationToken)).ConfigureAwait(false);
                    }
                    else if (!persister.IsLazy)
                    {
                        persistenceContext.AddNonLazyCollection(collection);
                    }

                    if (HasHolder())
                    {
                        session.PersistenceContext.AddCollectionHolder(collection);
                    }
                }

                if (log.IsDebugEnabled())
                {
                    log.Debug("Created collection wrapper: {0}", MessageHelper.CollectionInfoString(persister, collection, key, session));
                }
            }
            collection.Owner = owner;
            return(collection.GetValue());
        }
		/// <summary> Register a <tt>PersistentCollection</tt> object for an array.
		/// Associates a holder with an array - MUST be called after loading 
		/// array, since the array instance is not created until endLoad().
		/// </summary>
		public void AddCollectionHolder(IPersistentCollection holder)
		{
			//TODO:refactor + make this method private
			arrayHolders[holder.GetValue()] = holder;
		}