HHH-18212 Small cleanups to transient check logic
This commit is contained in:
parent
8686392afe
commit
638466fa8c
|
@ -19,14 +19,12 @@ import org.hibernate.engine.spi.CascadingAction;
|
||||||
import org.hibernate.engine.spi.CollectionEntry;
|
import org.hibernate.engine.spi.CollectionEntry;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.PersistenceContext;
|
import org.hibernate.engine.spi.PersistenceContext;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
import org.hibernate.event.spi.DeleteContext;
|
import org.hibernate.event.spi.DeleteContext;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
|
||||||
import org.hibernate.metamodel.mapping.AttributeMappingsList;
|
|
||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.type.AssociationType;
|
import org.hibernate.type.AssociationType;
|
||||||
|
@ -172,7 +170,6 @@ public final class Cascade {
|
||||||
type,
|
type,
|
||||||
style,
|
style,
|
||||||
propertyName,
|
propertyName,
|
||||||
persister.getAttributeMapping( i ),
|
|
||||||
anything,
|
anything,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -214,17 +211,16 @@ public final class Cascade {
|
||||||
final Type type,
|
final Type type,
|
||||||
final CascadeStyle style,
|
final CascadeStyle style,
|
||||||
final String propertyName,
|
final String propertyName,
|
||||||
final AttributeMapping attributeMapping,
|
|
||||||
final T anything,
|
final T anything,
|
||||||
final boolean isCascadeDeleteEnabled) throws HibernateException {
|
final boolean isCascadeDeleteEnabled) throws HibernateException {
|
||||||
|
|
||||||
if ( child != null ) {
|
if ( child != null ) {
|
||||||
if ( type.isAssociationType() ) {
|
if ( type.isAssociationType() ) {
|
||||||
final AssociationType associationType = (AssociationType) type;
|
final AssociationType associationType = (AssociationType) type;
|
||||||
final boolean strictUnowned = eventSource.getSessionFactory()
|
final boolean unownedTransient = eventSource.getSessionFactory()
|
||||||
.getSessionFactoryOptions()
|
.getSessionFactoryOptions()
|
||||||
.isUnownedAssociationTransientCheck();
|
.isUnownedAssociationTransientCheck();
|
||||||
if ( cascadeAssociationNow( action, cascadePoint, associationType, attributeMapping, strictUnowned ) ) {
|
if ( cascadeAssociationNow( action, cascadePoint, associationType, eventSource.getFactory(), unownedTransient ) ) {
|
||||||
cascadeAssociation(
|
cascadeAssociation(
|
||||||
action,
|
action,
|
||||||
cascadePoint,
|
cascadePoint,
|
||||||
|
@ -254,7 +250,6 @@ public final class Cascade {
|
||||||
parent,
|
parent,
|
||||||
child,
|
child,
|
||||||
(CompositeType) type,
|
(CompositeType) type,
|
||||||
attributeMapping,
|
|
||||||
anything
|
anything
|
||||||
);
|
);
|
||||||
if ( componentPath != null ) {
|
if ( componentPath != null ) {
|
||||||
|
@ -390,14 +385,14 @@ public final class Cascade {
|
||||||
CascadingAction<?> action,
|
CascadingAction<?> action,
|
||||||
CascadePoint cascadePoint,
|
CascadePoint cascadePoint,
|
||||||
AssociationType associationType,
|
AssociationType associationType,
|
||||||
AttributeMapping attributeMapping,
|
SessionFactoryImplementor factory,
|
||||||
boolean isStrictUnownedTransienceEnabled) {
|
boolean unownedTransient) {
|
||||||
return associationType.getForeignKeyDirection().cascadeNow( cascadePoint )
|
return associationType.getForeignKeyDirection().cascadeNow( cascadePoint )
|
||||||
// For check on flush, we should only check owned associations when strictness is enforced
|
// For check on flush, we should only check unowned associations when strictness is enforced
|
||||||
&& ( action != CHECK_ON_FLUSH || isStrictUnownedTransienceEnabled || !isUnownedAssociation( associationType, attributeMapping ) );
|
&& ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isUnownedAssociation(AssociationType associationType, AttributeMapping attributeMapping) {
|
private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) {
|
||||||
if ( associationType.isEntityType() ) {
|
if ( associationType.isEntityType() ) {
|
||||||
if ( associationType instanceof ManyToOneType ) {
|
if ( associationType instanceof ManyToOneType ) {
|
||||||
final ManyToOneType manyToOne = (ManyToOneType) associationType;
|
final ManyToOneType manyToOne = (ManyToOneType) associationType;
|
||||||
|
@ -412,7 +407,7 @@ public final class Cascade {
|
||||||
}
|
}
|
||||||
else if ( associationType.isCollectionType() ) {
|
else if ( associationType.isCollectionType() ) {
|
||||||
// for collections, we can ask the persister if we're on the inverse side
|
// for collections, we can ask the persister if we're on the inverse side
|
||||||
return ( (PluralAttributeMapping) attributeMapping ).getCollectionDescriptor().isInverse();
|
return ( (CollectionType) associationType ).isInverse( factory );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -425,14 +420,10 @@ public final class Cascade {
|
||||||
final Object parent,
|
final Object parent,
|
||||||
final Object child,
|
final Object child,
|
||||||
final CompositeType componentType,
|
final CompositeType componentType,
|
||||||
final AttributeMapping attributeMapping,
|
|
||||||
final T anything) {
|
final T anything) {
|
||||||
Object[] children = null;
|
Object[] children = null;
|
||||||
final Type[] types = componentType.getSubtypes();
|
final Type[] types = componentType.getSubtypes();
|
||||||
final String[] propertyNames = componentType.getPropertyNames();
|
final String[] propertyNames = componentType.getPropertyNames();
|
||||||
final AttributeMappingsList subMappings = attributeMapping != null ?
|
|
||||||
attributeMapping.asEmbeddedAttributeMapping().getEmbeddableTypeDescriptor().getAttributeMappings() :
|
|
||||||
null;
|
|
||||||
for ( int i = 0; i < types.length; i++ ) {
|
for ( int i = 0; i < types.length; i++ ) {
|
||||||
final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle( i );
|
final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle( i );
|
||||||
final String subPropertyName = propertyNames[i];
|
final String subPropertyName = propertyNames[i];
|
||||||
|
@ -452,7 +443,6 @@ public final class Cascade {
|
||||||
types[i],
|
types[i],
|
||||||
componentPropertyStyle,
|
componentPropertyStyle,
|
||||||
subPropertyName,
|
subPropertyName,
|
||||||
subMappings != null && i < subMappings.size() ? subMappings.get( i ) : null,
|
|
||||||
anything,
|
anything,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -594,7 +584,6 @@ public final class Cascade {
|
||||||
elemType,
|
elemType,
|
||||||
style,
|
style,
|
||||||
collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ),
|
collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ),
|
||||||
null,
|
|
||||||
anything,
|
anything,
|
||||||
isCascadeDeleteEnabled
|
isCascadeDeleteEnabled
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue