HHH-8159 - Apply fixups indicated by analysis tools
This commit is contained in:
parent
48331ed8cf
commit
fc02da1c12
|
@ -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<types.length; i++) {
|
||||
final CascadeStyle style = cascadeStyles[i];
|
||||
final String propertyName = persister.getPropertyNames()[i];
|
||||
|
@ -164,13 +119,13 @@ public final class Cascade {
|
|||
|
||||
if ( style.doCascade( action ) ) {
|
||||
cascadeProperty(
|
||||
parent,
|
||||
persister.getPropertyValue( parent, i ),
|
||||
types[i],
|
||||
style,
|
||||
parent,
|
||||
persister.getPropertyValue( parent, i ),
|
||||
types[i],
|
||||
style,
|
||||
propertyName,
|
||||
anything,
|
||||
false
|
||||
anything,
|
||||
false
|
||||
);
|
||||
}
|
||||
else if ( action.requiresNoCascadeChecking() ) {
|
||||
|
@ -204,7 +159,7 @@ public final class Cascade {
|
|||
|
||||
if (child!=null) {
|
||||
if ( type.isAssociationType() ) {
|
||||
AssociationType associationType = (AssociationType) type;
|
||||
final AssociationType associationType = (AssociationType) type;
|
||||
if ( cascadeAssociationNow( associationType ) ) {
|
||||
cascadeAssociation(
|
||||
parent,
|
||||
|
@ -287,10 +242,10 @@ public final class Cascade {
|
|||
return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne();
|
||||
}
|
||||
|
||||
private Stack componentPathStack = new Stack();
|
||||
private Stack<String> componentPathStack = new Stack<String>();
|
||||
|
||||
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<types.length; i++ ) {
|
||||
final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle(i);
|
||||
final String subPropertyName = componentType.getPropertyNames()[i];
|
||||
if ( componentPropertyStyle.doCascade(action) ) {
|
||||
if ( componentPropertyStyle.doCascade( action ) ) {
|
||||
cascadeProperty(
|
||||
parent,
|
||||
children[i],
|
||||
|
@ -344,13 +299,12 @@ public final class Cascade {
|
|||
final CascadeStyle style,
|
||||
final Object anything,
|
||||
final CollectionType type) {
|
||||
CollectionPersister persister = eventSource.getFactory()
|
||||
.getCollectionPersister( type.getRole() );
|
||||
Type elemType = persister.getElementType();
|
||||
final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() );
|
||||
final Type elemType = persister.getElementType();
|
||||
|
||||
final int oldCascadeTo = cascadeTo;
|
||||
if ( cascadeTo==AFTER_INSERT_BEFORE_DELETE) {
|
||||
cascadeTo = AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
|
||||
final CascadePoint originalCascadePoint = cascadePoint;
|
||||
if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE) {
|
||||
cascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
|
||||
}
|
||||
|
||||
//cascade to current collection elements
|
||||
|
@ -366,7 +320,7 @@ public final class Cascade {
|
|||
);
|
||||
}
|
||||
|
||||
cascadeTo = oldCascadeTo;
|
||||
cascadePoint = originalCascadePoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,13 +336,14 @@ public final class Cascade {
|
|||
final String entityName = type.isEntityType()
|
||||
? ( (EntityType) type ).getAssociatedEntityName()
|
||||
: null;
|
||||
if ( style.reallyDoCascade(action) ) { //not really necessary, but good for consistency...
|
||||
eventSource.getPersistenceContext().addChildParent(child, parent);
|
||||
if ( style.reallyDoCascade( action ) ) {
|
||||
//not really necessary, but good for consistency...
|
||||
eventSource.getPersistenceContext().addChildParent( child, parent );
|
||||
try {
|
||||
action.cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
|
||||
action.cascade( eventSource, child, entityName, anything, isCascadeDeleteEnabled );
|
||||
}
|
||||
finally {
|
||||
eventSource.getPersistenceContext().removeChildParent(child);
|
||||
eventSource.getPersistenceContext().removeChildParent( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,26 +359,25 @@ public final class Cascade {
|
|||
final Type elemType,
|
||||
final Object anything,
|
||||
final boolean isCascadeDeleteEnabled) throws HibernateException {
|
||||
|
||||
boolean reallyDoCascade = style.reallyDoCascade(action) && child!=CollectionType.UNFETCHED_COLLECTION;
|
||||
final boolean reallyDoCascade = style.reallyDoCascade( action ) && child != CollectionType.UNFETCHED_COLLECTION;
|
||||
|
||||
if ( reallyDoCascade ) {
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Cascade {0} for collection: {1}", action, collectionType.getRole() );
|
||||
}
|
||||
|
||||
Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child);
|
||||
while ( iter.hasNext() ) {
|
||||
final Iterator itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
|
||||
while ( itr.hasNext() ) {
|
||||
cascadeProperty(
|
||||
parent,
|
||||
iter.next(),
|
||||
itr.next(),
|
||||
elemType,
|
||||
style,
|
||||
null,
|
||||
anything,
|
||||
isCascadeDeleteEnabled
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
if ( traceEnabled ) {
|
||||
|
@ -431,12 +385,13 @@ public final class Cascade {
|
|||
}
|
||||
}
|
||||
|
||||
final boolean deleteOrphans = style.hasOrphanDelete() &&
|
||||
action.deleteOrphans() &&
|
||||
elemType.isEntityType() &&
|
||||
child instanceof PersistentCollection; //a newly instantiated collection can't have orphans
|
||||
final boolean deleteOrphans = style.hasOrphanDelete()
|
||||
&& action.deleteOrphans()
|
||||
&& elemType.isEntityType()
|
||||
// a newly instantiated collection can't have orphans
|
||||
&& child instanceof PersistentCollection;
|
||||
|
||||
if ( deleteOrphans ) { // handle orphaned entities!!
|
||||
if ( deleteOrphans ) {
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Deleting orphans for collection: {0}", collectionType.getRole() );
|
||||
|
@ -460,19 +415,17 @@ public final class Cascade {
|
|||
//TODO: suck this logic into the collection!
|
||||
final Collection orphans;
|
||||
if ( pc.wasInitialized() ) {
|
||||
CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc);
|
||||
orphans = ce==null ?
|
||||
java.util.Collections.EMPTY_LIST :
|
||||
ce.getOrphans(entityName, pc);
|
||||
final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc );
|
||||
orphans = ce==null
|
||||
? java.util.Collections.EMPTY_LIST
|
||||
: ce.getOrphans( entityName, pc );
|
||||
}
|
||||
else {
|
||||
orphans = pc.getQueuedOrphans(entityName);
|
||||
orphans = pc.getQueuedOrphans( entityName );
|
||||
}
|
||||
|
||||
final Iterator orphanIter = orphans.iterator();
|
||||
while ( orphanIter.hasNext() ) {
|
||||
Object orphan = orphanIter.next();
|
||||
if (orphan!=null) {
|
||||
for ( Object orphan : orphans ) {
|
||||
if ( orphan != null ) {
|
||||
LOG.tracev( "Deleting orphaned entity instance: {0}", entityName );
|
||||
eventSource.delete( entityName, orphan, false, new HashSet() );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.internal;
|
||||
|
||||
/**
|
||||
* Describes the point at which a cascade is occurring
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum CascadePoint {
|
||||
/**
|
||||
* A cascade point that occurs just after the insertion of the parent entity and
|
||||
* just before deletion
|
||||
*/
|
||||
AFTER_INSERT_BEFORE_DELETE,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just before the insertion of the parent entity and
|
||||
* just after deletion
|
||||
*/
|
||||
BEFORE_INSERT_AFTER_DELETE,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just after the insertion of the parent entity and
|
||||
* just before deletion, inside a collection
|
||||
*/
|
||||
AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just after update of the parent entity
|
||||
*/
|
||||
AFTER_UPDATE,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just before the session is flushed
|
||||
*/
|
||||
BEFORE_FLUSH,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just after eviction of the parent entity from the
|
||||
* session cache
|
||||
*/
|
||||
AFTER_EVICT,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just after locking a transient parent entity into the
|
||||
* session cache
|
||||
*/
|
||||
BEFORE_REFRESH,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just after refreshing a parent entity
|
||||
*/
|
||||
AFTER_LOCK,
|
||||
|
||||
/**
|
||||
* A cascade point that occurs just before merging from a transient parent entity into
|
||||
* the object in the session cache
|
||||
*/
|
||||
BEFORE_MERGE
|
||||
}
|
|
@ -34,6 +34,7 @@ import org.hibernate.action.internal.CollectionRemoveAction;
|
|||
import org.hibernate.action.internal.CollectionUpdateAction;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.internal.Collections;
|
||||
import org.hibernate.engine.spi.ActionQueue;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
|
@ -159,8 +160,7 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
|||
throws HibernateException {
|
||||
session.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( getCascadingAction(), Cascade.BEFORE_FLUSH, session )
|
||||
.cascade( persister, object, anything );
|
||||
new Cascade( getCascadingAction(), CascadePoint.BEFORE_FLUSH, session ).cascade( persister, object, anything );
|
||||
}
|
||||
finally {
|
||||
session.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.action.internal.EntityInsertAction;
|
|||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.internal.ForeignKeys;
|
||||
import org.hibernate.engine.internal.Versioning;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
|
@ -421,8 +422,11 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
// cascade-save to many-to-one BEFORE the parent is saved
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( getCascadeAction(), Cascade.BEFORE_INSERT_AFTER_DELETE, source )
|
||||
.cascade( persister, entity, anything );
|
||||
new Cascade( getCascadeAction(), CascadePoint.BEFORE_INSERT_AFTER_DELETE, source ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
anything
|
||||
);
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
@ -446,8 +450,11 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
// cascade-save to collections AFTER the collection owner was saved
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( getCascadeAction(), Cascade.AFTER_INSERT_BEFORE_DELETE, source )
|
||||
.cascade( persister, entity, anything );
|
||||
new Cascade( getCascadeAction(), CascadePoint.AFTER_INSERT_BEFORE_DELETE, source ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
anything
|
||||
);
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.TransientObjectException;
|
|||
import org.hibernate.action.internal.EntityDeleteAction;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.internal.ForeignKeys;
|
||||
import org.hibernate.engine.internal.Nullability;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
|
@ -321,8 +322,11 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
session.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
// cascade-delete to collections BEFORE the collection owner is deleted
|
||||
new Cascade( CascadingActions.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session )
|
||||
.cascade( persister, entity, transientEntities );
|
||||
new Cascade( CascadingActions.DELETE, CascadePoint.AFTER_INSERT_BEFORE_DELETE, session ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
transientEntities
|
||||
);
|
||||
}
|
||||
finally {
|
||||
session.getPersistenceContext().decrementCascadeLevel();
|
||||
|
@ -341,8 +345,11 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
session.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
// cascade-delete to many-to-one AFTER the parent was deleted
|
||||
new Cascade( CascadingActions.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session )
|
||||
.cascade( persister, entity, transientEntities );
|
||||
new Cascade( CascadingActions.DELETE, CascadePoint.BEFORE_INSERT_AFTER_DELETE, session ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
transientEntities
|
||||
);
|
||||
}
|
||||
finally {
|
||||
session.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
|
@ -142,7 +143,6 @@ public class DefaultEvictEventListener implements EvictEventListener {
|
|||
// This is now handled by removeEntity()
|
||||
//session.getPersistenceContext().removeDatabaseSnapshot(key);
|
||||
|
||||
new Cascade( CascadingActions.EVICT, Cascade.AFTER_EVICT, session )
|
||||
.cascade( persister, object );
|
||||
new Cascade( CascadingActions.EVICT, CascadePoint.AFTER_EVICT, session ).cascade( persister, object );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.internal.ForeignKeys;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
|
@ -102,8 +103,11 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
|
|||
EventSource source = event.getSession();
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( CascadingActions.LOCK, Cascade.AFTER_LOCK, source)
|
||||
.cascade( persister, entity, event.getLockOptions() );
|
||||
new Cascade( CascadingActions.LOCK, CascadePoint.AFTER_LOCK, source).cascade(
|
||||
persister,
|
||||
entity,
|
||||
event.getLockOptions()
|
||||
);
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.StaleObjectStateException;
|
|||
import org.hibernate.WrongClassException;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
|
@ -437,8 +438,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
) {
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( getCascadeAction(), Cascade.BEFORE_MERGE, source )
|
||||
.cascade(persister, entity, copyCache);
|
||||
new Cascade( getCascadeAction(), CascadePoint.BEFORE_MERGE, source ).cascade( persister, entity, copyCache );
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.PersistentObjectException;
|
|||
import org.hibernate.UnresolvableObjectException;
|
||||
import org.hibernate.cache.spi.CacheKey;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
|
@ -118,9 +119,12 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
}
|
||||
|
||||
// cascade the refresh prior to refreshing this entity
|
||||
refreshedAlready.put(object, object);
|
||||
new Cascade( CascadingActions.REFRESH, Cascade.BEFORE_REFRESH, source)
|
||||
.cascade( persister, object, refreshedAlready );
|
||||
refreshedAlready.put( object, object );
|
||||
new Cascade( CascadingActions.REFRESH, CascadePoint.BEFORE_REFRESH, source ).cascade(
|
||||
persister,
|
||||
object,
|
||||
refreshedAlready
|
||||
);
|
||||
|
||||
if ( e != null ) {
|
||||
final EntityKey key = source.generateEntityKey( id, persister );
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.ReplicationMode;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
|
@ -209,8 +210,11 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
EventSource source) {
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( CascadingActions.REPLICATE, Cascade.AFTER_UPDATE, source )
|
||||
.cascade( persister, entity, replicationMode );
|
||||
new Cascade( CascadingActions.REPLICATE, CascadePoint.AFTER_UPDATE, source ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
replicationMode
|
||||
);
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.PersistentObjectException;
|
|||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
|
@ -359,11 +360,10 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
* @param entity The entity being updated.
|
||||
*/
|
||||
private void cascadeOnUpdate(SaveOrUpdateEvent event, EntityPersister persister, Object entity) {
|
||||
EventSource source = event.getSession();
|
||||
final EventSource source = event.getSession();
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( CascadingActions.SAVE_UPDATE, Cascade.AFTER_UPDATE, source )
|
||||
.cascade( persister, entity );
|
||||
new Cascade( CascadingActions.SAVE_UPDATE, CascadePoint.AFTER_UPDATE, source ).cascade( persister, entity );
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -25,7 +25,7 @@ package org.hibernate.type;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
|
||||
/**
|
||||
* Represents directionality of the foreign key constraint
|
||||
|
@ -35,18 +35,25 @@ public abstract class ForeignKeyDirection implements Serializable {
|
|||
protected ForeignKeyDirection() {}
|
||||
/**
|
||||
* Should we cascade at this cascade point?
|
||||
*
|
||||
* @param cascadePoint The point at which the cascade is being initiated.
|
||||
*
|
||||
* @return {@code true} if cascading should be performed now.
|
||||
*
|
||||
* @see org.hibernate.engine.internal.Cascade
|
||||
*/
|
||||
public abstract boolean cascadeNow(int cascadePoint);
|
||||
public abstract boolean cascadeNow(CascadePoint cascadePoint);
|
||||
|
||||
/**
|
||||
* A foreign key from child to parent
|
||||
*/
|
||||
public static final ForeignKeyDirection FOREIGN_KEY_TO_PARENT = new ForeignKeyDirection() {
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint!=Cascade.BEFORE_INSERT_AFTER_DELETE;
|
||||
@Override
|
||||
public boolean cascadeNow(CascadePoint cascadePoint) {
|
||||
return cascadePoint != CascadePoint.BEFORE_INSERT_AFTER_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "toParent";
|
||||
}
|
||||
|
@ -59,10 +66,12 @@ public abstract class ForeignKeyDirection implements Serializable {
|
|||
* A foreign key from parent to child
|
||||
*/
|
||||
public static final ForeignKeyDirection FOREIGN_KEY_FROM_PARENT = new ForeignKeyDirection() {
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint!= Cascade.AFTER_INSERT_BEFORE_DELETE;
|
||||
@Override
|
||||
public boolean cascadeNow(CascadePoint cascadePoint) {
|
||||
return cascadePoint != CascadePoint.AFTER_INSERT_BEFORE_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "fromParent";
|
||||
}
|
||||
|
@ -71,4 +80,4 @@ public abstract class ForeignKeyDirection implements Serializable {
|
|||
return FOREIGN_KEY_FROM_PARENT;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue