예제 #1
0
        /// <summary>
        /// Cascade to the collection elements
        /// </summary>
        /// <param name="action"></param>
        /// <param name="style"></param>
        /// <param name="collectionType"></param>
        /// <param name="elemType"></param>
        /// <param name="child"></param>
        /// <param name="cascadeVia"></param>
        /// <param name="session"></param>
        /// <param name="anything"></param>
        private static void CascadeCollection(
            CascadingAction action,
            CascadeStyle style,
            PersistentCollectionType collectionType,
            IType elemType,
            object child,
            CascadePoint cascadeVia,
            ISessionImplementor session,
            object anything)
        {
            // cascade to current collection elements
            if (log.IsDebugEnabled)
            {
                log.Debug("cascading to collection: " + collectionType.Role);
            }
            ICollection iter = action.CascadableChildrenCollection(collectionType, child);

            foreach (object obj in iter)
            {
                Cascade(session, obj, elemType, action, style, cascadeVia, anything);
            }

            // handle oprhaned entities!!
            if (style.HasOrphanDelete && action.DeleteOrphans() && child is PersistentCollection)
            {
                // We can do the cast since orphan-delete does not apply to:
                // 1. newly instatiated collections
                // 2. arrays ( we can't track orphans for detached arrays)
                DeleteOrphans(child as PersistentCollection, session);
            }
        }
예제 #2
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.ActionSaveUpdate ||
            action == CascadingAction.ActionLock ||
            action == CascadingAction.ActionReplicate ||
            action == CascadingAction.ActionCopy);
 }
예제 #3
0
 /// <summary>
 /// Check sub elements-nullability. Returns property path that break
 /// nullability or null if none
 /// </summary>
 /// <param name="propertyType">type to check </param>
 /// <param name="value">value to check </param>
 /// <returns> property path </returns>
 private string CheckSubElementsNullability(IType propertyType, object value)
 {
     //for non null args, check for components and elements containing components
     if (propertyType.IsComponentType)
     {
         return(CheckComponentNullability(value, (IAbstractComponentType)propertyType));
     }
     else if (propertyType.IsCollectionType)
     {
         //persistent collections may have components
         CollectionType collectionType        = (CollectionType)propertyType;
         IType          collectionElementType = collectionType.GetElementType(session.Factory);
         if (collectionElementType.IsComponentType)
         {
             //check for all components values in the collection
             IAbstractComponentType componentType = (IAbstractComponentType)collectionElementType;
             IEnumerable            ec            = CascadingAction.GetLoadedElementsIterator(session, collectionType, value);
             foreach (object compValue in ec)
             {
                 if (compValue != null)
                 {
                     return(CheckComponentNullability(compValue, componentType));
                 }
             }
         }
     }
     return(null);
 }
예제 #4
0
        /// <summary>
        /// Cascade an action to the child or children
        /// </summary>
        /// <param name="session"></param>
        /// <param name="child"></param>
        /// <param name="type"></param>
        /// <param name="action"></param>
        /// <param name="style"></param>
        /// <param name="cascadeTo"></param>
        /// <param name="anything"></param>
        private static void Cascade(
            ISessionImplementor session,
            object child,
            IType type,
            CascadingAction action,
            CascadeStyle style,
            CascadePoint cascadeTo,
            object anything)
        {
            if (child != null)
            {
                if (type.IsAssociationType)
                {
                    if ((( IAssociationType )type).ForeignKeyType.CascadeNow(cascadeTo))
                    {
                        if (type.IsEntityType || type.IsObjectType)
                        {
                            action.Cascade(session, child, anything);
                        }
                        else if (type.IsPersistentCollectionType)
                        {
                            CascadePoint cascadeVia;
                            if (cascadeTo == CascadePoint.CascadeAfterInsertBeforeDelete)
                            {
                                cascadeVia = CascadePoint.CascadeAfterInsertBeforeDeleteViaCollection;
                            }
                            else
                            {
                                cascadeVia = cascadeTo;
                            }
                            PersistentCollectionType pctype    = ( PersistentCollectionType )type;
                            ICollectionPersister     persister = session.Factory.GetCollectionPersister(pctype.Role);
                            IType elemType = persister.ElementType;

                            // cascade to current collection elements
                            if (elemType.IsEntityType || elemType.IsObjectType || elemType.IsComponentType)
                            {
                                CascadeCollection(action, style, pctype, elemType, child, cascadeVia, session, anything);
                            }
                        }
                    }
                }
                else if (type.IsComponentType)
                {
                    IAbstractComponentType ctype = (( IAbstractComponentType )type);
                    object[] children            = ctype.GetPropertyValues(child, session);
                    IType[]  types = ctype.Subtypes;
                    for (int i = 0; i < types.Length; i++)
                    {
                        CascadeStyle componentPropertyStyle = ctype.Cascade(i);
                        if (componentPropertyStyle.DoCascade(action))
                        {
                            Cascade(session, children[i], types[i], action, componentPropertyStyle, cascadeTo, anything);
                        }
                    }
                }
            }
        }
예제 #5
0
        public CascadeEntityLoader(IOuterJoinLoadable persister, CascadingAction action, ISessionFactoryImplementor factory)
            : base(persister, persister.IdentifierType, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
        {
            JoinWalker walker = new CascadeEntityJoinWalker(persister, action, factory);
            InitFromWalker(walker);

            PostInstantiate();

            log.Debug(string.Format("Static select for action {0} on entity {1}: {2}", action, entityName, SqlString));
        }
		public CascadeEntityJoinWalker(IOuterJoinLoadable persister, CascadingAction action,
		                               ISessionFactoryImplementor factory)
			: base(persister, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
		{
			cascadeAction = action;
			SqlStringBuilder whereCondition = WhereString(Alias, persister.IdentifierColumnNames, 1)
				//include the discriminator and class-level where, but not filters
				.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitAll(whereCondition.ToSqlString(), SqlString.Empty, LockMode.Read);
		}
예제 #7
0
 public override bool ReallyDoCascade(CascadingAction action)
 {
     for (int i = 0; i < styles.Length; i++)
     {
         if (styles[i].ReallyDoCascade(action))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #8
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Evict;
			}
예제 #9
0
 /// <summary>
 /// Probably more aptly named something like doCascadeToCollectionElements();
 /// it is however used from both the collection and to-one logic branches...
 /// </summary>
 /// <param name="action">The action to be checked for cascade-ability. </param>
 /// <returns> True if the action should be really cascaded under this style; false otherwise. </returns>
 /// <remarks>
 /// 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.
 /// </remarks>
 public virtual bool ReallyDoCascade(CascadingAction action)
 {
     return(DoCascade(action));
 }
예제 #10
0
			public override bool ReallyDoCascade(CascadingAction action)
			{
				for (int i = 0; i < styles.Length; i++)
				{
					if (styles[i].ReallyDoCascade(action))
						return true;
				}
				return false;
			}
예제 #11
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Merge || action == CascadingAction.SaveUpdateCopy;
			}
예제 #12
0
 /// <summary>
 /// Cascade an action from the parent object to all its children.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="persister"></param>
 /// <param name="parent"></param>
 /// <param name="action"></param>
 /// <param name="cascadeTo"></param>
 /// <param name="anything"></param>
 public static void Cascade(ISessionImplementor session, IClassPersister persister, object parent, CascadingAction action, CascadePoint cascadeTo, object anything)
 {
     if (persister.HasCascades)
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("processing cascades for: " + persister.ClassName);
         }
         IType[]        types         = persister.PropertyTypes;
         CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles;
         for (int i = 0; i < types.Length; i++)
         {
             CascadeStyle style = cascadeStyles[i];
             if (style.DoCascade(action))
             {
                 Cascade(session, persister.GetPropertyValue(parent, i), types[i], action, style, cascadeTo, anything);
             }
         }
         if (log.IsDebugEnabled)
         {
             log.Debug("done processing cascades for: " + persister.ClassName);
         }
     }
 }
예제 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="session"></param>
 /// <param name="persister"></param>
 /// <param name="parent"></param>
 /// <param name="action"></param>
 /// <param name="cascadeTo"></param>
 public static void Cascade(ISessionImplementor session, IClassPersister persister, object parent, CascadingAction action, CascadePoint cascadeTo)
 {
     Cascade(session, persister, parent, action, cascadeTo, null);
 }
예제 #14
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.ActionDelete);
 }
예제 #15
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Merge;
			}
예제 #16
0
		public Cascade(CascadingAction action, CascadePoint point, IEventSource eventSource)
		{
			this.point = point;
			this.eventSource = eventSource;
			this.action = action;
		}
예제 #17
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Delete || action == CascadingAction.SaveUpdate;
			}
예제 #18
0
				public override bool DoCascade(CascadingAction action)
				{
					return action == CascadingAction.ActionSaveUpdate ||
					       action == CascadingAction.ActionLock ||
					       action == CascadingAction.ActionReplicate ||
					       action == CascadingAction.ActionCopy;
				}
예제 #19
0
		/// <summary> 
		/// Probably more aptly named something like doCascadeToCollectionElements(); 
		/// it is however used from both the collection and to-one logic branches...
		/// </summary>
		/// <param name="action">The action to be checked for cascade-ability. </param>
		/// <returns> True if the action should be really cascaded under this style; false otherwise. </returns>
		/// <remarks>
		/// 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.
		/// </remarks>
		public virtual bool ReallyDoCascade(CascadingAction action)
		{
			return DoCascade(action);
		}
예제 #20
0
				public override bool DoCascade(CascadingAction action)
				{
					return action == CascadingAction.ActionDelete;
				}
예제 #21
0
 public override bool ReallyDoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Delete);
 }
예제 #22
0
		/// <summary>
		/// Cascade an action to the child or children
		/// </summary>
		/// <param name="session"></param>
		/// <param name="child"></param>
		/// <param name="type"></param>
		/// <param name="action"></param>
		/// <param name="style"></param>
		/// <param name="cascadeTo"></param>
		/// <param name="anything"></param>
		private static void Cascade(
			ISessionImplementor session,
			object child,
			IType type,
			CascadingAction action,
			CascadeStyle style,
			CascadePoint cascadeTo,
			object anything)
		{
			if (child != null)
			{
				if (type.IsAssociationType)
				{
					if (((IAssociationType) type).ForeignKeyDirection.CascadeNow(cascadeTo))
					{
						if (type.IsEntityType || type.IsAnyType)
						{
							action.Cascade(session, child, anything);
						}
						else if (type.IsCollectionType)
						{
							CascadePoint cascadeVia;
							if (cascadeTo == CascadePoint.CascadeAfterInsertBeforeDelete)
							{
								cascadeVia = CascadePoint.CascadeAfterInsertBeforeDeleteViaCollection;
							}
							else
							{
								cascadeVia = cascadeTo;
							}
							CollectionType pctype = (CollectionType) type;
							ICollectionPersister persister = session.Factory.GetCollectionPersister(pctype.Role);
							IType elemType = persister.ElementType;

							// cascade to current collection elements
							if (elemType.IsEntityType || elemType.IsAnyType || elemType.IsComponentType)
							{
								CascadeCollection(action, style, pctype, elemType, child, cascadeVia, session, anything);
							}
						}
					}
				}
				else if (type.IsComponentType)
				{
					IAbstractComponentType ctype = ((IAbstractComponentType) type);
					object[] children = ctype.GetPropertyValues(child, session);
					IType[] types = ctype.Subtypes;
					for (int i = 0; i < types.Length; i++)
					{
						CascadeStyle componentPropertyStyle = ctype.GetCascadeStyle(i);
						if (componentPropertyStyle.DoCascade(action))
						{
							Cascade(session, children[i], types[i], action, componentPropertyStyle, cascadeTo, anything);
						}
					}
				}
			}
		}
예제 #23
0
 /// <summary> For this style, should the given action be cascaded? </summary>
 /// <param name="action">The action to be checked for cascade-ability. </param>
 /// <returns> True if the action should be cascaded under this style; false otherwise. </returns>
 public abstract bool DoCascade(CascadingAction action);
예제 #24
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="session"></param>
		/// <param name="persister"></param>
		/// <param name="parent"></param>
		/// <param name="action"></param>
		/// <param name="cascadeTo"></param>
		public static void Cascade(ISessionImplementor session, IEntityPersister persister, object parent,
		                           CascadingAction action, CascadePoint cascadeTo)
		{
			Cascade(session, persister, parent, action, cascadeTo, null);
		}
예제 #25
0
 public override bool DoCascade(CascadingAction action)
 {
     return(true);
 }
예제 #26
0
		/// <summary>
		/// Cascade an action from the parent object to all its children.
		/// </summary>
		/// <param name="session"></param>
		/// <param name="persister"></param>
		/// <param name="parent"></param>
		/// <param name="action"></param>
		/// <param name="cascadeTo"></param>
		/// <param name="anything"></param>
		public static void Cascade(ISessionImplementor session, IEntityPersister persister, object parent,
		                           CascadingAction action, CascadePoint cascadeTo, object anything)
		{
			if (persister.HasCascades)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("processing cascades for: " + persister.ClassName);
				}
				IType[] types = persister.PropertyTypes;
				CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles;
				for (int i = 0; i < types.Length; i++)
				{
					CascadeStyle style = cascadeStyles[i];
					if (style.DoCascade(action))
					{
						Cascade(session, persister.GetPropertyValue(parent, i), types[i], action, style, cascadeTo, anything);
					}
				}
				if (log.IsDebugEnabled)
				{
					log.Debug("done processing cascades for: " + persister.ClassName);
				}
			}
		}
예제 #27
0
 public Cascade(CascadingAction action, CascadePoint point, IEventSource eventSource)
 {
     this.point       = point;
     this.eventSource = eventSource;
     this.action      = action;
 }
예제 #28
0
		/// <summary>
		/// Cascade to the collection elements
		/// </summary>
		/// <param name="action"></param>
		/// <param name="style"></param>
		/// <param name="collectionType"></param>
		/// <param name="elemType"></param>
		/// <param name="child"></param>
		/// <param name="cascadeVia"></param>
		/// <param name="session"></param>
		/// <param name="anything"></param>
		private static void CascadeCollection(
			CascadingAction action,
			CascadeStyle style,
			CollectionType collectionType,
			IType elemType,
			object child,
			CascadePoint cascadeVia,
			ISessionImplementor session,
			object anything)
		{
			// cascade to current collection elements
			if (log.IsDebugEnabled)
			{
				log.Debug("cascading to collection: " + collectionType.Role);
			}
			ICollection iter = action.CascadableChildrenCollection(collectionType, child);
			foreach (object obj in iter)
			{
				Cascade(session, obj, elemType, action, style, cascadeVia, anything);
			}

			// handle oprhaned entities!!
			if (style.HasOrphanDelete && action.DeleteOrphans() && child is IPersistentCollection)
			{
				// We can do the cast since orphan-delete does not apply to:
				// 1. newly instatiated collections
				// 2. arrays ( we can't track orphans for detached arrays)
				System.Type entityName = collectionType.GetAssociatedClass(session.Factory);
				DeleteOrphans(entityName, child as IPersistentCollection, session);
			}
		}
예제 #29
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Refresh;
			}
예제 #30
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Refresh);
 }
예제 #31
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Replicate;
			}
예제 #32
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Replicate);
 }
예제 #33
0
			public override bool DoCascade(CascadingAction action)
			{
				return action == CascadingAction.Persist || action == CascadingAction.PersistOnFlush;
			}
예제 #34
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Merge);
 }
예제 #35
0
			public override bool ReallyDoCascade(CascadingAction action)
			{
				return action == CascadingAction.Delete;
			}
예제 #36
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Persist || action == CascadingAction.PersistOnFlush);
 }
예제 #37
0
		/// <summary> For this style, should the given action be cascaded? </summary>
		/// <param name="action">The action to be checked for cascade-ability. </param>
		/// <returns> True if the action should be cascaded under this style; false otherwise. </returns>
		public abstract bool DoCascade(CascadingAction action);
예제 #38
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Delete || action == CascadingAction.SaveUpdate);
 }
예제 #39
0
			public override bool DoCascade(CascadingAction action)
			{
				return true;
			}
예제 #40
0
 public override bool DoCascade(CascadingAction action)
 {
     return(action == CascadingAction.Merge || action == CascadingAction.SaveUpdateCopy);
 }