HHH-10363 - The Cascade class makes unnecessary calls to the Reflection

API.
This commit is contained in:
Andrej Golovnin 2015-12-06 13:44:29 +01:00 committed by Steve Ebersole
parent 153b8f26cc
commit 328fa2363a
3 changed files with 27 additions and 24 deletions

View File

@ -80,12 +80,13 @@ public final class Cascade {
}
final Type[] types = persister.getPropertyTypes();
final String[] propertyNames = persister.getPropertyNames();
final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
final boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent );
final int componentPathStackDepth = 0;
for ( int i = 0; i < types.length; i++) {
final CascadeStyle style = cascadeStyles[i];
final String propertyName = persister.getPropertyNames()[i];
final String propertyName = propertyNames[i];
if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
//do nothing to avoid a lazy property initialization
continue;
@ -109,9 +110,9 @@ public final class Cascade {
else if ( action.requiresNoCascadeChecking() ) {
action.noCascade(
eventSource,
persister.getPropertyValue( parent, i ),
parent,
persister,
types[i],
i
);
}
@ -166,7 +167,6 @@ public final class Cascade {
parent,
child,
(CompositeType) type,
propertyName,
anything
);
}
@ -263,15 +263,19 @@ public final class Cascade {
final Object parent,
final Object child,
final CompositeType componentType,
final String componentPropertyName,
final Object anything) {
final Object[] children = componentType.getPropertyValues( child, eventSource );
Object[] children = null;
final Type[] types = componentType.getSubtypes();
final String[] propertyNames = componentType.getPropertyNames();
for ( int i = 0; i < types.length; i++ ) {
final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle( i );
final String subPropertyName = componentType.getPropertyNames()[i];
final String subPropertyName = propertyNames[i];
if ( componentPropertyStyle.doCascade( action ) ) {
if (children == null) {
// Get children on demand.
children = componentType.getPropertyValues( child, eventSource );
}
cascadeProperty(
action,
cascadePoint,

View File

@ -12,6 +12,7 @@ import org.hibernate.HibernateException;
import org.hibernate.event.spi.EventSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
/**
* A session action that may be cascaded from parent entity to its children
@ -32,7 +33,7 @@ public interface CascadingAction {
* @param isCascadeDeleteEnabled Are cascading deletes enabled.
* @throws HibernateException
*/
public void cascade(
void cascade(
EventSource session,
Object child,
String entityName,
@ -48,7 +49,7 @@ public interface CascadingAction {
* @param collection The collection instance.
* @return The children iterator.
*/
public Iterator getCascadableChildrenIterator(
Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection);
@ -58,7 +59,7 @@ public interface CascadingAction {
*
* @return True if this action can lead to deletions of orphans.
*/
public boolean deleteOrphans();
boolean deleteOrphans();
/**
@ -66,22 +67,22 @@ public interface CascadingAction {
*
* @return True if this action requires no-cascade verification; false otherwise.
*/
public boolean requiresNoCascadeChecking();
boolean requiresNoCascadeChecking();
/**
* Called (in the case of {@link #requiresNoCascadeChecking} returning true) to validate
* that no cascade on the given property is considered a valid semantic.
*
* @param session The session witin which the cascade is occurring.
* @param child The property value
* @param parent The property value owner
* @param persister The entity persister for the owner
* @param propertyType The property type
* @param propertyIndex The index of the property within the owner.
*/
public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex);
void noCascade(EventSource session, Object parent, EntityPersister persister, Type propertyType, int propertyIndex);
/**
* Should this action be performed (or noCascade consulted) in the case of lazy properties.
*/
public boolean performOnLazyProperty();
boolean performOnLazyProperty();
}

View File

@ -362,18 +362,16 @@ public class CascadingActions {
@Override
public void noCascade(
EventSource session,
Object child,
Object parent,
EntityPersister persister,
Type propertyType,
int propertyIndex) {
if ( child == null ) {
return;
}
Type type = persister.getPropertyTypes()[propertyIndex];
if ( type.isEntityType() ) {
String childEntityName = ((EntityType) type).getAssociatedEntityName( session.getFactory() );
if ( propertyType.isEntityType() ) {
Object child = persister.getPropertyValue( parent, propertyIndex );
String childEntityName = ((EntityType) propertyType).getAssociatedEntityName( session.getFactory() );
if ( !isInManagedState( child, session )
if ( child != null
&& !isInManagedState( child, session )
&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
String parentEntiytName = persister.getEntityName();
@ -453,7 +451,7 @@ public class CascadingActions {
}
@Override
public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex) {
public void noCascade(EventSource session, Object parent, EntityPersister persister, Type propertyType, int propertyIndex) {
}
@Override