Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import org.hibernate.Hibernate;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;

import jakarta.validation.Path;
Expand Down Expand Up @@ -54,17 +57,17 @@ private void addAssociationsToTheSetForAllProperties(String[] names, Type[] type

private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {

if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
CollectionType collType = (CollectionType) type;
Type assocType = collType.getElementType( factory );
addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
}
//ToOne association
else if ( type.isEntityType() || type.isAnyType() ) {
else if ( type instanceof EntityType || type instanceof AnyType ) {
associations.add( prefix + name );
}
else if ( type.isComponentType() ) {
CompositeType componentType = (CompositeType) type;
else if ( type instanceof ComponentType ) {
ComponentType componentType = (ComponentType) type;
addAssociationsToTheSetForAllProperties(
componentType.getPropertyNames(),
componentType.getSubtypes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -67,7 +68,7 @@ public EnhancementAsProxyLazinessInterceptor(
collectionAttributeNames = new HashSet<>();
for ( int i = 0; i < propertyTypes.length; i++ ) {
Type propertyType = propertyTypes[i];
if ( propertyType.isCollectionType() ) {
if ( propertyType instanceof CollectionType ) {
collectionAttributeNames.add( entityPersister.getPropertyNames()[i] );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.bytecode.enhance.spi.interceptor;

import org.hibernate.mapping.Property;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;

/**
Expand All @@ -21,7 +22,7 @@ public static LazyAttributeDescriptor from(
int lazyIndex) {
String fetchGroupName = property.getLazyGroup();
if ( fetchGroupName == null ) {
fetchGroupName = property.getType().isCollectionType()
fetchGroupName = property.getType() instanceof CollectionType
? property.getName()
: "DEFAULT";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.Type;

import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy;
Expand Down Expand Up @@ -125,7 +127,7 @@ public static <T> void cascade(
// parent was not in the PersistenceContext
continue;
}
if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
// CollectionType#getCollection gets the PersistentCollection
// that corresponds to the uninitialized collection from the
// PersistenceContext. If not present, an uninitialized
Expand All @@ -140,13 +142,13 @@ public static <T> void cascade(
null
);
}
else if ( type.isComponentType() ) {
else if ( type instanceof AnyType || type instanceof ComponentType ) {
// Hibernate does not support lazy embeddables, so this shouldn't happen.
throw new UnsupportedOperationException(
"Lazy components are not supported."
);
}
else if ( action.performOnLazyProperty() && type.isEntityType() ) {
else if ( action.performOnLazyProperty() && type instanceof EntityType ) {
// Only need to initialize a lazy entity attribute when action.performOnLazyProperty()
// returns true.
LazyAttributeLoadingInterceptor interceptor = persister.getBytecodeEnhancementMetadata()
Expand Down Expand Up @@ -226,7 +228,7 @@ private static <T> void cascadeProperty(
final boolean isCascadeDeleteEnabled) throws HibernateException {

if ( child != null ) {
if ( type.isAssociationType() ) {
if ( type instanceof EntityType || type instanceof CollectionType || type instanceof AnyType ) {
final AssociationType associationType = (AssociationType) type;
if ( cascadeAssociationNow( cascadePoint, associationType ) ) {
cascadeAssociation(
Expand All @@ -243,7 +245,7 @@ private static <T> void cascadeProperty(
);
}
}
else if ( type.isComponentType() ) {
else if ( type instanceof ComponentType ) {
if ( componentPath == null && propertyName != null ) {
componentPath = new ArrayList<>();
}
Expand Down Expand Up @@ -358,9 +360,8 @@ private static <T> void cascadeLogicalOneToOneOrphanRemoval(
LOG.tracev( "Deleting orphaned entity instance: {0}", description );
}

if ( type.isAssociationType() && ( (AssociationType) type ).getForeignKeyDirection().equals(
ForeignKeyDirection.TO_PARENT
) ) {
if ( type instanceof CollectionType
|| type instanceof OneToOneType && ( (OneToOneType) type ).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) {
// If FK direction is to-parent, we must remove the orphan *before* the queued update(s)
// occur. Otherwise, replacing the association on a managed entity, without manually
// nulling and flushing, causes FK constraint violations.
Expand Down Expand Up @@ -442,10 +443,10 @@ private static <T> void cascadeAssociation(
final CascadeStyle style,
final T anything,
final boolean isCascadeDeleteEnabled) {
if ( type.isEntityType() || type.isAnyType() ) {
if ( type instanceof EntityType || type instanceof AnyType ) {
cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled );
}
else if ( type.isCollectionType() ) {
else if ( type instanceof CollectionType ) {
cascadeCollection(
action,
cascadePoint,
Expand Down Expand Up @@ -485,7 +486,7 @@ private static <T> void cascadeCollection(
}

//cascade to current collection elements
if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
if ( elemType instanceof EntityType || elemType instanceof AnyType || elemType instanceof ComponentType ) {
cascadeCollectionElements(
action,
elementsCascadePoint,
Expand Down Expand Up @@ -514,7 +515,7 @@ private static <T> void cascadeToOne(
final CascadeStyle style,
final T anything,
final boolean isCascadeDeleteEnabled) {
final String entityName = type.isEntityType()
final String entityName = type instanceof EntityType
? ( (EntityType) type ).getAssociatedEntityName()
: null;
if ( style.reallyDoCascade( action ) ) {
Expand Down Expand Up @@ -578,7 +579,7 @@ private static <T> void cascadeCollectionElements(

final boolean deleteOrphans = style.hasOrphanDelete()
&& action.deleteOrphans()
&& elemType.isEntityType()
&& elemType instanceof EntityType
&& child instanceof PersistentCollection
// a newly instantiated collection can't have orphans
&& ! ( (PersistentCollection<?>) child ).isNewlyInstantiated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CompositeType;
import org.hibernate.type.AnyType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -91,7 +92,7 @@ private Object nullifyTransientReferences(final Object value, final String prope
if ( value == null ) {
returnedValue = null;
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type;
if ( entityType.isOneToOne() ) {
returnedValue = value;
Expand All @@ -113,11 +114,11 @@ else if ( type.isEntityType() ) {
}
}
}
else if ( type.isAnyType() ) {
else if ( type instanceof AnyType ) {
returnedValue = isNullifiable( null, value ) ? null : value;
}
else if ( type.isComponentType() ) {
final CompositeType actype = (CompositeType) type;
else if ( type instanceof ComponentType ) {
final ComponentType actype = (ComponentType) type;
final Object[] subvalues = actype.getPropertyValues( value, session );
final Type[] subtypes = actype.getSubtypes();
final String[] subPropertyNames = actype.getPropertyNames();
Expand Down Expand Up @@ -159,7 +160,7 @@ private Object initializeIfNecessary(
final Type type) {
if ( isDelete &&
value == LazyPropertyInitializer.UNFETCHED_PROPERTY &&
type.isEntityType() &&
type instanceof EntityType &&
!session.getPersistenceContextInternal().isNullifiableEntityKeysEmpty() ) {
// IMPLEMENTATION NOTE: If cascade-remove was mapped for the attribute,
// then value should have been initialized previously, when the remove operation was
Expand Down Expand Up @@ -406,21 +407,21 @@ private static void collectNonNullableTransientEntities(
return;
}

if ( type.isEntityType() ) {
if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type;
if ( !isNullable
&& !entityType.isOneToOne()
&& nullifier.isNullifiable( entityType.getAssociatedEntityName(), value ) ) {
nonNullableTransientEntities.add( propertyName, value );
}
}
else if ( type.isAnyType() ) {
else if ( type instanceof AnyType ) {
if ( !isNullable && nullifier.isNullifiable( null, value ) ) {
nonNullableTransientEntities.add( propertyName, value );
}
}
else if ( type.isComponentType() ) {
final CompositeType actype = (CompositeType) type;
else if ( type instanceof ComponentType ) {
final ComponentType actype = (ComponentType) type;
final boolean[] subValueNullability = actype.getPropertyNullability();
if ( subValueNullability != null ) {
final String[] subPropertyNames = actype.getPropertyNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.generator.Generator;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -143,16 +145,19 @@ private static boolean generated(Generator generator) {
* @throws HibernateException error while getting subcomponent values
*/
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
if ( propertyType.isComponentType() ) {
return checkComponentNullability( value, (CompositeType) propertyType );
if ( propertyType instanceof AnyType ) {
return checkComponentNullability( value, (AnyType) propertyType );
}
if ( propertyType instanceof ComponentType ) {
return checkComponentNullability( value, (ComponentType) propertyType );
}

if ( propertyType.isCollectionType() ) {
if ( propertyType instanceof CollectionType ) {
// persistent collections may have components
final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType( session.getFactory() );

if ( collectionElementType.isComponentType() ) {
if ( collectionElementType instanceof ComponentType || collectionElementType instanceof AnyType ) {
// check for all components values in the collection
final CompositeType componentType = (CompositeType) collectionElementType;
final Iterator<?> itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
Expand Down Expand Up @@ -188,7 +193,7 @@ private String checkComponentNullability(Object value, CompositeType compositeTy
//
// The more correct fix would be to cascade saves of the many-to-any elements before the Nullability checking

if ( compositeType.isAnyType() ) {
if ( compositeType instanceof AnyType ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.type.BagType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public void addFetch(Association association, Fetch.Style style) {
public void addFetch(final Fetch fetch) {
final String fetchAssociactionRole = fetch.getAssociation().getRole();
final Type associationType = fetch.getAssociation().getOwner().getPropertyType( fetch.getAssociation().getAssociationPath() );
if ( associationType.isCollectionType() ) {
if ( associationType instanceof CollectionType ) {
LOG.tracev( "Handling request to add collection fetch [{0}]", fetchAssociactionRole );

// couple of things for which to account in the case of collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.OneToOneType;
Expand Down Expand Up @@ -1151,7 +1151,10 @@ public void addTransitiveDependencies(InsertInfo origin, Set<InsertInfo> visited
}

private void addDirectDependency(Type type, Object value, IdentityHashMap<Object, InsertInfo> insertInfosByEntity) {
if ( type.isEntityType() && value != null ) {
if ( value == null ) {
return;
}
if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type;
final InsertInfo insertInfo = insertInfosByEntity.get(value);
if (insertInfo != null) {
Expand All @@ -1171,7 +1174,7 @@ private void addDirectDependency(Type type, Object value, IdentityHashMap<Object
}
}
}
else if ( type.isCollectionType() && value != null ) {
else if ( type instanceof CollectionType ) {
CollectionType collectionType = (CollectionType) type;
final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession()
.getFactory()
Expand All @@ -1194,9 +1197,9 @@ else if ( type.isCollectionType() && value != null ) {
}
}
}
else if ( type.isComponentType() && value != null ) {
else if ( type instanceof ComponentType ) {
// Support recursive checks of composite type properties for associations and collections.
CompositeType compositeType = (CompositeType) type;
ComponentType compositeType = (ComponentType) type;
final SharedSessionContractImplementor session = insertAction.getSession();
Object[] componentValues = compositeType.getPropertyValues( value, session );
for ( int j = 0; j < componentValues.length; ++j ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void noCascade(
EntityPersister persister,
Type propertyType,
int propertyIndex) {
if ( propertyType.isEntityType() ) {
if ( propertyType instanceof EntityType ) {
Object child = persister.getValue( parent, propertyIndex );
if ( child != null
&& !isInManagedState( child, session )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.event.spi.EventSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
Expand Down Expand Up @@ -87,15 +89,18 @@ Object processComponent(Object component, CompositeType componentType) throws Hi
*/
final Object processValue(Object value, Type type) throws HibernateException {

if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
//even process null collections
return processCollection( value, (CollectionType) type );
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
return processEntity( value, (EntityType) type );
}
else if ( type.isComponentType() ) {
return processComponent( value, (CompositeType) type );
else if ( type instanceof ComponentType ) {
return processComponent( value, (ComponentType) type );
}
else if ( type instanceof AnyType ) {
return processComponent( value, (AnyType) type );
}
else {
return null;
Expand Down
Loading