Skip to content

Commit

Permalink
HHH-10363 - The Cascade class makes unnecessary calls to the Reflection
Browse files Browse the repository at this point in the history
API.
  • Loading branch information
golovnin authored and sebersole committed Dec 16, 2015
1 parent 153b8f2 commit 328fa23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ public static void 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++) {
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;
Expand All @@ -109,9 +110,9 @@ public static void cascade(
else if ( action.requiresNoCascadeChecking() ) {
action.noCascade(
eventSource,
persister.getPropertyValue( parent, i ),
parent,
persister,
types[i],
i
);
}
Expand Down Expand Up @@ -166,7 +167,6 @@ else if ( type.isComponentType() ) {
parent,
child,
(CompositeType) type,
propertyName,
anything
);
}
Expand Down Expand Up @@ -263,15 +263,19 @@ private static void cascadeComponent(
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();
for ( int i=0; i<types.length; i++ ) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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
Expand All @@ -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,
Expand All @@ -48,7 +49,7 @@ public void cascade(
* @param collection The collection instance.
* @return The children iterator.
*/
public Iterator getCascadableChildrenIterator(
Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection);
Expand All @@ -58,30 +59,30 @@ public Iterator getCascadableChildrenIterator(
*
* @return True if this action can lead to deletions of orphans.
*/
public boolean deleteOrphans();
boolean deleteOrphans();


/**
* Does the specified cascading action require verification of no cascade validity?
*
* @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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,16 @@ public boolean requiresNoCascadeChecking() {
@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();
Expand Down Expand Up @@ -453,7 +451,7 @@ public boolean requiresNoCascadeChecking() {
}

@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
Expand Down

0 comments on commit 328fa23

Please sign in to comment.