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 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;
|
||||
@ -109,9 +110,9 @@ public static void cascade(
|
||||
else if ( action.requiresNoCascadeChecking() ) {
|
||||
action.noCascade(
|
||||
eventSource,
|
||||
persister.getPropertyValue( parent, i ),
|
||||
parent,
|
||||
persister,
|
||||
types[i],
|
||||
i
|
||||
);
|
||||
}
|
||||
@ -166,7 +167,6 @@ else if ( type.isComponentType() ) {
|
||||
parent,
|
||||
child,
|
||||
(CompositeType) type,
|
||||
propertyName,
|
||||
anything
|
||||
);
|
||||
}
|
||||
@ -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,
|
||||
|
@ -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
|
||||
@ -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 void cascade(
|
||||
* @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 Iterator getCascadableChildrenIterator(
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -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();
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user