diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java index e4776059fe..943e0a9db5 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java @@ -37,11 +37,9 @@ import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.EntityEntry; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.event.spi.EventSource; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; @@ -59,76 +57,35 @@ import org.hibernate.type.Type; * @see org.hibernate.engine.spi.CascadingAction */ public final class Cascade { + private static final CoreMessageLogger LOG = Logger.getMessageLogger( + CoreMessageLogger.class, + Cascade.class.getName() + ); + + private final CascadingAction action; + private final EventSource eventSource; + private CascadePoint cascadePoint; /** - * A cascade point that occurs just after the insertion of the parent entity and - * just before deletion + * Constructs a Cascade + * + * @param action The action we are cascading + * @param cascadePoint The point in the action at which we are trying to cascade currently + * @param eventSource The session */ - public static final int AFTER_INSERT_BEFORE_DELETE = 1; - /** - * A cascade point that occurs just before the insertion of the parent entity and - * just after deletion - */ - public static final int BEFORE_INSERT_AFTER_DELETE = 2; - /** - * A cascade point that occurs just after the insertion of the parent entity and - * just before deletion, inside a collection - */ - public static final int AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION = 3; - /** - * A cascade point that occurs just after update of the parent entity - */ - public static final int AFTER_UPDATE = 0; - /** - * A cascade point that occurs just before the session is flushed - */ - public static final int BEFORE_FLUSH = 0; - /** - * A cascade point that occurs just after eviction of the parent entity from the - * session cache - */ - public static final int AFTER_EVICT = 0; - /** - * A cascade point that occurs just after locking a transient parent entity into the - * session cache - */ - public static final int BEFORE_REFRESH = 0; - /** - * A cascade point that occurs just after refreshing a parent entity - */ - public static final int AFTER_LOCK = 0; - /** - * A cascade point that occurs just before merging from a transient parent entity into - * the object in the session cache - */ - public static final int BEFORE_MERGE = 0; - - private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Cascade.class.getName()); - - - private int cascadeTo; - private EventSource eventSource; - private CascadingAction action; - - public Cascade(final CascadingAction action, final int cascadeTo, final EventSource eventSource) { - this.cascadeTo = cascadeTo; + public Cascade(final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource) { + this.cascadePoint = cascadePoint; this.eventSource = eventSource; this.action = action; } - private SessionFactoryImplementor getFactory() { - return eventSource.getFactory(); - } - /** * Cascade an action from the parent entity instance to all its children. * * @param persister The parent's entity persister * @param parent The parent reference. - * @throws HibernateException */ - public void cascade(final EntityPersister persister, final Object parent) - throws HibernateException { + public void cascade(final EntityPersister persister, final Object parent) { cascade( persister, parent, null ); } @@ -140,20 +97,18 @@ public final class Cascade { * @param parent The parent reference. * @param anything Anything ;) Typically some form of cascade-local cache * which is specific to each CascadingAction type - * @throws HibernateException */ - public void cascade(final EntityPersister persister, final Object parent, final Object anything) - throws HibernateException { - - if ( persister.hasCascades() || action.requiresNoCascadeChecking() ) { // performance opt + public void cascade(final EntityPersister persister, final Object parent, final Object anything) { + if ( persister.hasCascades() || action.requiresNoCascadeChecking() ) { + // performance opt final boolean traceEnabled = LOG.isTraceEnabled(); if ( traceEnabled ) { LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() ); } - Type[] types = persister.getPropertyTypes(); - CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles(); - boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent ); + final Type[] types = persister.getPropertyTypes(); + final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles(); + final boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent ); for ( int i=0; i componentPathStack = new Stack(); private boolean cascadeAssociationNow(AssociationType associationType) { - return associationType.getForeignKeyDirection().cascadeNow(cascadeTo); + return associationType.getForeignKeyDirection().cascadeNow( cascadePoint ); } private void cascadeComponent( @@ -300,12 +255,12 @@ public final class Cascade { final String componentPropertyName, final Object anything) { componentPathStack.push( componentPropertyName ); - Object[] children = componentType.getPropertyValues( child, eventSource ); - Type[] types = componentType.getSubtypes(); + final Object[] children = componentType.getPropertyValues( child, eventSource ); + final Type[] types = componentType.getSubtypes(); for ( int i=0; i