public abstract DoCascade ( NHibernate.Engine.CascadingAction action ) : bool | ||
action | NHibernate.Engine.CascadingAction | The action to be checked for cascade-ability. |
return | bool |
/// <summary> /// Cascade an action from the parent entity instance to all its children. This /// form is typically called from within cascade actions. /// </summary> /// <param name="persister">The parent's entity persister </param> /// <param name="parent">The parent reference. </param> /// <param name="anything"> /// Typically some form of cascade-local cache /// which is specific to each CascadingAction type /// </param> public void CascadeOn(IEntityPersister persister, object parent, object anything) { if (persister.HasCascades || action.RequiresNoCascadeChecking) { log.Info("processing cascade {0} for: {1}", action, persister.EntityName); IType[] types = persister.PropertyTypes; CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles; bool hasUninitializedLazyProperties = persister.HasUninitializedLazyProperties(parent); for (int i = 0; i < types.Length; i++) { CascadeStyle style = cascadeStyles[i]; string propertyName = persister.PropertyNames[i]; if (hasUninitializedLazyProperties && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty) { //do nothing to avoid a lazy property initialization continue; } if (style.DoCascade(action)) { CascadeProperty(parent, persister.GetPropertyValue(parent, i), types[i], style, propertyName, anything, false); } else if (action.RequiresNoCascadeChecking) { action.NoCascade(eventSource, persister.GetPropertyValue(parent, i), parent, persister, i); } } log.Info("done processing cascade {0} for: {1}", action, persister.EntityName); } }
/// <summary> /// Cascade an action from the parent entity instance to all its children. This /// form is typically called from within cascade actions. /// </summary> /// <param name="persister">The parent's entity persister </param> /// <param name="parent">The parent reference. </param> /// <param name="anything"> /// Typically some form of cascade-local cache /// which is specific to each CascadingAction type /// </param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param> public async Task CascadeOnAsync(IEntityPersister persister, object parent, object anything, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (persister.HasCascades || action.RequiresNoCascadeChecking) { log.Info("processing cascade " + action + " for: " + persister.EntityName); IType[] types = persister.PropertyTypes; CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles; bool hasUninitializedLazyProperties = persister.HasUninitializedLazyProperties(parent); for (int i = 0; i < types.Length; i++) { CascadeStyle style = cascadeStyles[i]; string propertyName = persister.PropertyNames[i]; if (hasUninitializedLazyProperties && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty) { //do nothing to avoid a lazy property initialization continue; } if (style.DoCascade(action)) { await(CascadePropertyAsync(parent, persister.GetPropertyValue(parent, i), types[i], style, propertyName, anything, false, cancellationToken)).ConfigureAwait(false); } else if (action.RequiresNoCascadeChecking) { await(action.NoCascadeAsync(eventSource, persister.GetPropertyValue(parent, i), parent, persister, i, cancellationToken)).ConfigureAwait(false); } } log.Info("done processing cascade " + action + " for: " + persister.EntityName); } }
/// <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); } } } } }
private void CascadeComponent(object parent, object child, IAbstractComponentType componentType, object anything) { object[] children = componentType.GetPropertyValues(child, eventSource); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = componentType.GetCascadeStyle(i); if (componentPropertyStyle.DoCascade(action)) { CascadeProperty(parent, children[i], types[i], componentPropertyStyle, anything, false); } } }
private async Task CascadeComponentAsync(object parent, object child, IAbstractComponentType componentType, string componentPropertyName, object anything, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); componentPathStack.Push(componentPropertyName); object[] children = await(componentType.GetPropertyValuesAsync(child, eventSource, cancellationToken)).ConfigureAwait(false); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = componentType.GetCascadeStyle(i); string subPropertyName = componentType.PropertyNames[i]; if (componentPropertyStyle.DoCascade(action)) { await(CascadePropertyAsync(parent, children[i], types[i], componentPropertyStyle, subPropertyName, anything, false, cancellationToken)).ConfigureAwait(false); } } componentPathStack.Pop(); }
/// <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); } } }
protected override bool IsJoinedFetchEnabled(IAssociationType type, FetchMode config, CascadeStyle cascadeStyle) { return (type.IsEntityType || type.IsCollectionType) && (cascadeStyle == null || cascadeStyle.DoCascade(cascadeAction)); }