ReallyDoCascade() публичный Метод

Probably more aptly named something like doCascadeToCollectionElements(); it is however used from both the collection and to-one logic branches...
For this style, should the given action really be cascaded? The default implementation is simply to return {@link #doCascade}; for certain styles (currently only delete-orphan), however, we need to be able to control this separately.
public ReallyDoCascade ( NHibernate.Engine.CascadingAction action ) : bool
action NHibernate.Engine.CascadingAction The action to be checked for cascade-ability.
Результат bool
Пример #1
0
        /// <summary> Cascade to the collection elements</summary>
        private void CascadeCollectionElements(object parent, object child, CollectionType collectionType, CascadeStyle style, IType elemType, object anything, bool isCascadeDeleteEnabled)
        {
            bool reallyDoCascade = style.ReallyDoCascade(action) &&
                                   child != CollectionType.UnfetchedCollection;

            if (reallyDoCascade)
            {
                log.Info("cascade {0} for collection: {1}", action, collectionType.Role);

                foreach (object o in action.GetCascadableChildrenIterator(eventSource, collectionType, child))
                {
                    CascadeProperty(parent, o, elemType, style, null, anything, isCascadeDeleteEnabled);
                }

                log.Info("done cascade {0} for collection: {1}", action, collectionType.Role);
            }

            var  childAsPersColl = child as IPersistentCollection;
            bool deleteOrphans   = style.HasOrphanDelete && action.DeleteOrphans && elemType.IsEntityType &&
                                   childAsPersColl != null;              //a newly instantiated collection can't have orphans

            if (deleteOrphans)
            {
                // handle orphaned entities!!
                log.Info("deleting orphans for collection: {0}", collectionType.Role);

                // we can do the cast since orphan-delete does not apply to:
                // 1. newly instantiated collections
                // 2. arrays (we can't track orphans for detached arrays)
                string entityName = collectionType.GetAssociatedEntityName(eventSource.Factory);
                DeleteOrphans(entityName, childAsPersColl);

                log.Info("done deleting orphans for collection: {0}", collectionType.Role);
            }
        }
Пример #2
0
        /// <summary> Cascade an action to a to-one association or any type</summary>
        private void CascadeToOne(object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled)
        {
            string entityName = type.IsEntityType ? ((EntityType)type).GetAssociatedEntityName() : null;

            if (style.ReallyDoCascade(action))
            {
                //not really necessary, but good for consistency...
                action.Cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
            }
        }
Пример #3
0
        /// <summary> Cascade an action to a to-one association or any type</summary>
        private void CascadeToOne(object parent, object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled)
        {
            string entityName = type.IsEntityType ? ((EntityType)type).GetAssociatedEntityName() : null;

            if (style.ReallyDoCascade(action))
            {
                //not really necessary, but good for consistency...
                eventSource.PersistenceContext.AddChildParent(child, parent);
                try
                {
                    action.Cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
                }
                finally
                {
                    eventSource.PersistenceContext.RemoveChildParent(child);
                }
            }
        }
Пример #4
0
        /// <summary> Cascade an action to a to-one association or any type</summary>
        private async Task CascadeToOneAsync(object parent, object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            string entityName = type.IsEntityType ? ((EntityType)type).GetAssociatedEntityName() : null;

            if (style.ReallyDoCascade(action))
            {
                //not really necessary, but good for consistency...
                eventSource.PersistenceContext.AddChildParent(child, parent);
                try
                {
                    await(action.CascadeAsync(eventSource, child, entityName, anything, isCascadeDeleteEnabled, cancellationToken)).ConfigureAwait(false);
                }
                finally
                {
                    eventSource.PersistenceContext.RemoveChildParent(child);
                }
            }
        }
Пример #5
0
        /// <summary> Cascade to the collection elements</summary>
        private async Task CascadeCollectionElementsAsync(object parent, object child, CollectionType collectionType, CascadeStyle style, IType elemType, object anything, bool isCascadeDeleteEnabled, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            bool reallyDoCascade = style.ReallyDoCascade(action) &&
                                   child != CollectionType.UnfetchedCollection;

            if (reallyDoCascade)
            {
                log.Info("cascade " + action + " for collection: " + collectionType.Role);

                foreach (object o in action.GetCascadableChildrenIterator(eventSource, collectionType, child))
                {
                    await(CascadePropertyAsync(parent, o, elemType, style, null, anything, isCascadeDeleteEnabled, cancellationToken)).ConfigureAwait(false);
                }

                log.Info("done cascade " + action + " for collection: " + collectionType.Role);
            }

            var  childAsPersColl = child as IPersistentCollection;
            bool deleteOrphans   = style.HasOrphanDelete && action.DeleteOrphans && elemType.IsEntityType &&
                                   childAsPersColl != null;              //a newly instantiated collection can't have orphans

            if (deleteOrphans)
            {
                // handle orphaned entities!!
                log.Info("deleting orphans for collection: " + collectionType.Role);

                // we can do the cast since orphan-delete does not apply to:
                // 1. newly instantiated collections
                // 2. arrays (we can't track orphans for detached arrays)
                string entityName = collectionType.GetAssociatedEntityName(eventSource.Factory);
                await(DeleteOrphansAsync(entityName, childAsPersColl, cancellationToken)).ConfigureAwait(false);

                log.Info("done deleting orphans for collection: " + collectionType.Role);
            }
        }
Пример #6
0
		/// <summary> Cascade to the collection elements</summary>
		private void CascadeCollectionElements(object child, CollectionType collectionType, CascadeStyle style, IType elemType, object anything, bool isCascadeDeleteEnabled)
		{
			// we can't cascade to non-embedded elements
			bool embeddedElements = eventSource.EntityMode != EntityMode.Xml
			                        || ((EntityType) collectionType.GetElementType(eventSource.Factory)).IsEmbeddedInXML;

			bool reallyDoCascade = style.ReallyDoCascade(action) && embeddedElements
			                       && child != CollectionType.UnfetchedCollection;

			if (reallyDoCascade)
			{
				log.Info("cascade " + action + " for collection: " + collectionType.Role);

				foreach (object o in action.GetCascadableChildrenIterator(eventSource, collectionType, child))
					CascadeProperty(o, elemType, style, anything, isCascadeDeleteEnabled);

				log.Info("done cascade " + action + " for collection: " + collectionType.Role);
			}

			var childAsPersColl = child as IPersistentCollection;
			bool deleteOrphans = style.HasOrphanDelete && action.DeleteOrphans && elemType.IsEntityType
			                     && childAsPersColl != null; //a newly instantiated collection can't have orphans

			if (deleteOrphans)
			{
				// handle orphaned entities!!
				log.Info("deleting orphans for collection: " + collectionType.Role);

				// we can do the cast since orphan-delete does not apply to:
				// 1. newly instantiated collections
				// 2. arrays (we can't track orphans for detached arrays)
				string entityName = collectionType.GetAssociatedEntityName(eventSource.Factory);
				DeleteOrphans(entityName, childAsPersColl);

				log.Info("done deleting orphans for collection: " + collectionType.Role);
			}
		}
Пример #7
0
		/// <summary> Cascade an action to a to-one association or any type</summary>
		private void CascadeToOne(object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled)
		{
			string entityName = type.IsEntityType ? ((EntityType)type).GetAssociatedEntityName() : null;
			if (style.ReallyDoCascade(action))
			{
				//not really necessary, but good for consistency...
				action.Cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
			}
		}
Пример #8
0
		/// <summary> Cascade an action to a to-one association or any type</summary>
		private void CascadeToOne(object parent, object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled)
		{
			string entityName = type.IsEntityType ? ((EntityType)type).GetAssociatedEntityName() : null;
			if (style.ReallyDoCascade(action))
			{
				//not really necessary, but good for consistency...
				eventSource.PersistenceContext.AddChildParent(child, parent);
				try
				{
					action.Cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
				}
				finally
				{
					eventSource.PersistenceContext.RemoveChildParent(child);
				}
			}
		}