mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-06 19:36:03 +00:00
HHH-10363 - The Cascade class makes unnecessary calls to the Reflection
API. (cherry picked from commit 328fa2363a9db91bef0b6aa1b547c55860ec17d9)
This commit is contained in:
parent
b0709a78e6
commit
760ac6c8c2
@ -80,12 +80,13 @@ public static void cascade(
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Type[] types = persister.getPropertyTypes();
|
final Type[] types = persister.getPropertyTypes();
|
||||||
|
final String[] propertyNames = persister.getPropertyNames();
|
||||||
final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
|
final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
|
||||||
final boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent );
|
final boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent );
|
||||||
final int componentPathStackDepth = 0;
|
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 CascadeStyle style = cascadeStyles[i];
|
||||||
final String propertyName = persister.getPropertyNames()[i];
|
final String propertyName = propertyNames[i];
|
||||||
if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
|
if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
|
||||||
//do nothing to avoid a lazy property initialization
|
//do nothing to avoid a lazy property initialization
|
||||||
continue;
|
continue;
|
||||||
@ -109,9 +110,9 @@ public static void cascade(
|
|||||||
else if ( action.requiresNoCascadeChecking() ) {
|
else if ( action.requiresNoCascadeChecking() ) {
|
||||||
action.noCascade(
|
action.noCascade(
|
||||||
eventSource,
|
eventSource,
|
||||||
persister.getPropertyValue( parent, i ),
|
|
||||||
parent,
|
parent,
|
||||||
persister,
|
persister,
|
||||||
|
types[i],
|
||||||
i
|
i
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -166,7 +167,6 @@ else if ( type.isComponentType() ) {
|
|||||||
parent,
|
parent,
|
||||||
child,
|
child,
|
||||||
(CompositeType) type,
|
(CompositeType) type,
|
||||||
propertyName,
|
|
||||||
anything
|
anything
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -263,15 +263,19 @@ private static void cascadeComponent(
|
|||||||
final Object parent,
|
final Object parent,
|
||||||
final Object child,
|
final Object child,
|
||||||
final CompositeType componentType,
|
final CompositeType componentType,
|
||||||
final String componentPropertyName,
|
|
||||||
final Object anything) {
|
final Object anything) {
|
||||||
|
|
||||||
final Object[] children = componentType.getPropertyValues( child, eventSource );
|
Object[] children = null;
|
||||||
final Type[] types = componentType.getSubtypes();
|
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 CascadeStyle componentPropertyStyle = componentType.getCascadeStyle( i );
|
||||||
final String subPropertyName = componentType.getPropertyNames()[i];
|
final String subPropertyName = propertyNames[i];
|
||||||
if ( componentPropertyStyle.doCascade( action ) ) {
|
if ( componentPropertyStyle.doCascade( action ) ) {
|
||||||
|
if (children == null) {
|
||||||
|
// Get children on demand.
|
||||||
|
children = componentType.getPropertyValues( child, eventSource );
|
||||||
|
}
|
||||||
cascadeProperty(
|
cascadeProperty(
|
||||||
action,
|
action,
|
||||||
cascadePoint,
|
cascadePoint,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.type.CollectionType;
|
import org.hibernate.type.CollectionType;
|
||||||
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A session action that may be cascaded from parent entity to its children
|
* 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.
|
* @param isCascadeDeleteEnabled Are cascading deletes enabled.
|
||||||
* @throws HibernateException
|
* @throws HibernateException
|
||||||
*/
|
*/
|
||||||
public void cascade(
|
void cascade(
|
||||||
EventSource session,
|
EventSource session,
|
||||||
Object child,
|
Object child,
|
||||||
String entityName,
|
String entityName,
|
||||||
@ -48,7 +49,7 @@ public void cascade(
|
|||||||
* @param collection The collection instance.
|
* @param collection The collection instance.
|
||||||
* @return The children iterator.
|
* @return The children iterator.
|
||||||
*/
|
*/
|
||||||
public Iterator getCascadableChildrenIterator(
|
Iterator getCascadableChildrenIterator(
|
||||||
EventSource session,
|
EventSource session,
|
||||||
CollectionType collectionType,
|
CollectionType collectionType,
|
||||||
Object collection);
|
Object collection);
|
||||||
@ -58,7 +59,7 @@ public Iterator getCascadableChildrenIterator(
|
|||||||
*
|
*
|
||||||
* @return True if this action can lead to deletions of orphans.
|
* @return True if this action can lead to deletions of orphans.
|
||||||
*/
|
*/
|
||||||
public boolean deleteOrphans();
|
boolean deleteOrphans();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,22 +67,22 @@ public Iterator getCascadableChildrenIterator(
|
|||||||
*
|
*
|
||||||
* @return True if this action requires no-cascade verification; false otherwise.
|
* @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
|
* Called (in the case of {@link #requiresNoCascadeChecking} returning true) to validate
|
||||||
* that no cascade on the given property is considered a valid semantic.
|
* that no cascade on the given property is considered a valid semantic.
|
||||||
*
|
*
|
||||||
* @param session The session witin which the cascade is occurring.
|
* @param session The session witin which the cascade is occurring.
|
||||||
* @param child The property value
|
|
||||||
* @param parent The property value owner
|
* @param parent The property value owner
|
||||||
* @param persister The entity persister for the owner
|
* @param persister The entity persister for the owner
|
||||||
|
* @param propertyType The property type
|
||||||
* @param propertyIndex The index of the property within the owner.
|
* @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.
|
* Should this action be performed (or noCascade consulted) in the case of lazy properties.
|
||||||
*/
|
*/
|
||||||
public boolean performOnLazyProperty();
|
boolean performOnLazyProperty();
|
||||||
}
|
}
|
||||||
|
@ -362,18 +362,16 @@ public boolean requiresNoCascadeChecking() {
|
|||||||
@Override
|
@Override
|
||||||
public void noCascade(
|
public void noCascade(
|
||||||
EventSource session,
|
EventSource session,
|
||||||
Object child,
|
|
||||||
Object parent,
|
Object parent,
|
||||||
EntityPersister persister,
|
EntityPersister persister,
|
||||||
|
Type propertyType,
|
||||||
int propertyIndex) {
|
int propertyIndex) {
|
||||||
if ( child == null ) {
|
if ( propertyType.isEntityType() ) {
|
||||||
return;
|
Object child = persister.getPropertyValue( parent, propertyIndex );
|
||||||
}
|
String childEntityName = ((EntityType) propertyType).getAssociatedEntityName( session.getFactory() );
|
||||||
Type type = persister.getPropertyTypes()[propertyIndex];
|
|
||||||
if ( type.isEntityType() ) {
|
|
||||||
String childEntityName = ((EntityType) type).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
|
&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
|
||||||
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
|
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
|
||||||
String parentEntiytName = persister.getEntityName();
|
String parentEntiytName = persister.getEntityName();
|
||||||
@ -453,7 +451,7 @@ public boolean requiresNoCascadeChecking() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user