From 6da6276d12af7a74383e72243863e04e3a61acee Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 12 Sep 2024 20:03:28 +0200 Subject: [PATCH] squash more warnings --- .../hibernate/engine/internal/Cascade.java | 90 +++++++++---------- .../org/hibernate/engine/spi/ActionQueue.java | 9 +- .../hibernate/engine/spi/CascadeStyle.java | 4 +- .../hibernate/engine/spi/CascadeStyles.java | 30 +++---- .../engine/spi/EffectiveEntityGraph.java | 11 ++- .../hibernate/engine/spi/ManagedEntity.java | 45 +++++----- .../hibernate/engine/spi/SubselectFetch.java | 2 +- .../main/java/org/hibernate/mapping/Any.java | 8 +- .../hibernate/mapping/CheckConstraint.java | 3 +- .../java/org/hibernate/mapping/Column.java | 6 +- .../java/org/hibernate/mapping/Index.java | 2 +- .../java/org/hibernate/mapping/RootClass.java | 3 +- .../main/java/org/hibernate/mapping/Set.java | 3 +- .../java/org/hibernate/mapping/Subclass.java | 2 - .../java/org/hibernate/mapping/ToOne.java | 7 +- .../java/org/hibernate/mapping/Value.java | 20 ++--- .../type/AbstractStandardBasicType.java | 4 +- .../org/hibernate/type/CollectionType.java | 16 ++-- .../java/org/hibernate/type/EntityType.java | 4 +- .../type/internal/ConvertedBasicTypeImpl.java | 2 +- 20 files changed, 120 insertions(+), 151 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java index 42ff34629de1..2f5524c7ad34 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java @@ -36,6 +36,7 @@ import org.hibernate.type.OneToOneType; import org.hibernate.type.Type; +import static java.util.Collections.EMPTY_LIST; import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy; import static org.hibernate.engine.spi.CascadingActions.CHECK_ON_FLUSH; import static org.hibernate.pretty.MessageHelper.infoString; @@ -89,7 +90,8 @@ public static void cascade( LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() ); } final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal(); - final boolean enhancedForLazyLoading = persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading(); + final boolean enhancedForLazyLoading = + persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading(); final EntityEntry entry; if ( enhancedForLazyLoading ) { entry = persistenceContext.getEntry( parent ); @@ -112,8 +114,9 @@ public static void cascade( final String propertyName = propertyNames[ i ]; final Type type = types[i]; final boolean isUninitializedProperty = - hasUninitializedLazyProperties && - !persister.getBytecodeEnhancementMetadata().isAttributeLoaded( parent, propertyName ); + hasUninitializedLazyProperties + && !persister.getBytecodeEnhancementMetadata() + .isAttributeLoaded( parent, propertyName ); if ( style.doCascade( action ) ) { final Object child; @@ -129,14 +132,13 @@ public static void cascade( // parent was not in the PersistenceContext continue; } - if ( type instanceof CollectionType ) { + if ( type instanceof CollectionType collectionType ) { // CollectionType#getCollection gets the PersistentCollection // that corresponds to the uninitialized collection from the // PersistenceContext. If not present, an uninitialized // PersistentCollection will be added to the PersistenceContext. // The action may initialize it later, if necessary. // This needs to be done even when action.performOnLazyProperty() returns false. - final CollectionType collectionType = (CollectionType) type; child = collectionType.getCollection( collectionType.getKeyOfOwner( parent, eventSource ), eventSource, @@ -146,15 +148,14 @@ public static void cascade( } 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." - ); + throw new UnsupportedOperationException( "Lazy embeddables are not supported" ); } else if ( action.performOnLazyProperty() && type instanceof EntityType ) { // Only need to initialize a lazy entity attribute when action.performOnLazyProperty() // returns true. - LazyAttributeLoadingInterceptor interceptor = persister.getBytecodeEnhancementMetadata() - .extractInterceptor( parent ); + final LazyAttributeLoadingInterceptor interceptor = + persister.getBytecodeEnhancementMetadata() + .extractInterceptor( parent ); child = interceptor.fetchAttribute( parent, propertyName ); } @@ -238,10 +239,10 @@ private static void cascadeProperty( style, anything, isCascadeDeleteEnabled - ); + ); } } - else if ( type instanceof ComponentType ) { + else if ( type instanceof ComponentType componentType ) { if ( componentPath == null && propertyName != null ) { componentPath = new ArrayList<>(); } @@ -255,7 +256,7 @@ else if ( type instanceof ComponentType ) { componentPath, parent, child, - (CompositeType) type, + componentType, anything ); if ( componentPath != null ) { @@ -273,7 +274,8 @@ else if ( type instanceof ComponentType ) { type, style, propertyName, - isCascadeDeleteEnabled ); + isCascadeDeleteEnabled + ); } } @@ -376,8 +378,8 @@ private static void cascadeLogicalOneToOneOrphanRemoval( private static boolean isForeignKeyToParent(Type type) { return type instanceof CollectionType - || type instanceof OneToOneType - && ((OneToOneType) type).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT; + || type instanceof OneToOneType oneToOneType + && oneToOneType.getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT; } /** @@ -389,7 +391,7 @@ private static boolean isForeignKeyToParent(Type type) { * @return True if the attribute represents a logical one to one association */ private static boolean isLogicalOneToOne(Type type) { - return type instanceof EntityType && ( (EntityType) type ).isLogicalOneToOne(); + return type instanceof EntityType entityType && entityType.isLogicalOneToOne(); } private static boolean cascadeAssociationNow( @@ -399,24 +401,22 @@ private static boolean cascadeAssociationNow( SessionFactoryImplementor factory, boolean unownedTransient) { return associationType.getForeignKeyDirection().cascadeNow( cascadePoint ) - // For check on flush, we should only check unowned associations when strictness is enforced - && ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) ); + // For check on flush, we should only check unowned associations when strictness is enforced + && ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) ); } private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) { - if ( associationType instanceof ManyToOneType ) { - final ManyToOneType manyToOne = (ManyToOneType) associationType; + if ( associationType instanceof ManyToOneType manyToOne ) { // logical one-to-one + non-null unique key property name indicates unowned return manyToOne.isLogicalOneToOne() && manyToOne.getRHSUniqueKeyPropertyName() != null; } - else if ( associationType instanceof OneToOneType ) { - final OneToOneType oneToOne = (OneToOneType) associationType; + else if ( associationType instanceof OneToOneType oneToOne ) { // constrained false + non-null unique key property name indicates unowned return oneToOne.isNullable() && oneToOne.getRHSUniqueKeyPropertyName() != null; } - else if ( associationType instanceof CollectionType ) { + else if ( associationType instanceof CollectionType collectionType ) { // for collections, we can ask the persister if we're on the inverse side - return ( (CollectionType) associationType ).isInverse( factory ); + return collectionType.isInverse( factory ); } return false; } @@ -454,7 +454,7 @@ private static void cascadeComponent( subPropertyName, anything, false - ); + ); } } } @@ -473,7 +473,7 @@ private static void cascadeAssociation( if ( type instanceof EntityType || type instanceof AnyType ) { cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled ); } - else if ( type instanceof CollectionType ) { + else if ( type instanceof CollectionType collectionType ) { cascadeCollection( action, cascadePoint, @@ -483,7 +483,7 @@ else if ( type instanceof CollectionType ) { child, style, anything, - (CollectionType) type + collectionType ); } } @@ -505,17 +505,13 @@ private static void cascadeCollection( eventSource.getFactory().getMappingMetamodel() .getCollectionDescriptor( type.getRole() ); final Type elemType = persister.getElementType(); - - CascadePoint elementsCascadePoint = cascadePoint; - if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE ) { - elementsCascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION; - } - //cascade to current collection elements if ( elemType instanceof EntityType || elemType instanceof AnyType || elemType instanceof ComponentType ) { cascadeCollectionElements( action, - elementsCascadePoint, + cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE + ? CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION + : cascadePoint, eventSource, componentPath, parent, @@ -541,9 +537,10 @@ private static void cascadeToOne( final CascadeStyle style, final T anything, final boolean isCascadeDeleteEnabled) { - final String entityName = type instanceof EntityType - ? ( (EntityType) type ).getAssociatedEntityName() - : null; + final String entityName = + type instanceof EntityType entityType + ? entityType.getAssociatedEntityName() + : null; if ( style.reallyDoCascade( action ) ) { //not really necessary, but good for consistency... final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal(); @@ -572,6 +569,7 @@ private static void cascadeCollectionElements( final Type elemType, final T anything, final boolean isCascadeDeleteEnabled) throws HibernateException { + final boolean reallyDoCascade = style.reallyDoCascade( action ) && child != CollectionType.UNFETCHED_COLLECTION; @@ -581,15 +579,15 @@ private static void cascadeCollectionElements( LOG.tracev( "Cascade {0} for collection: {1}", action, collectionType.getRole() ); } - final Iterator itr = action.getCascadableChildrenIterator( eventSource, collectionType, child ); - while ( itr.hasNext() ) { + final Iterator iterator = action.getCascadableChildrenIterator( eventSource, collectionType, child ); + while ( iterator.hasNext() ) { cascadeProperty( action, cascadePoint, eventSource, componentPath, parent, - itr.next(), + iterator.next(), elemType, style, collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ), @@ -606,9 +604,9 @@ private static void cascadeCollectionElements( final boolean deleteOrphans = style.hasOrphanDelete() && action.deleteOrphans() && elemType instanceof EntityType - && child instanceof PersistentCollection + && child instanceof PersistentCollection persistentCollection // a newly instantiated collection can't have orphans - && ! ( (PersistentCollection) child ).isNewlyInstantiated(); + && !persistentCollection.isNewlyInstantiated(); if ( deleteOrphans ) { final boolean traceEnabled = LOG.isTraceEnabled(); @@ -634,10 +632,8 @@ private static void deleteOrphans(EventSource eventSource, String entityName, Pe //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { - final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry( pc ); - orphans = ce==null - ? java.util.Collections.EMPTY_LIST - : ce.getOrphans( entityName, pc ); + final CollectionEntry entry = eventSource.getPersistenceContextInternal().getCollectionEntry( pc ); + orphans = entry == null ? EMPTY_LIST : entry.getOrphans( entityName, pc ); } else { orphans = pc.getQueuedOrphans( entityName ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java index 67a7b0d73e7a..db39786da14f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java @@ -1167,8 +1167,7 @@ private void addDirectDependency(Type type, @Nullable Object value, IdentityHash if ( value == null ) { return; } - if ( type instanceof EntityType ) { - final EntityType entityType = (EntityType) type; + if ( type instanceof EntityType entityType ) { final InsertInfo insertInfo = insertInfosByEntity.get( value ); if ( insertInfo != null ) { if ( entityType.isOneToOne() @@ -1188,8 +1187,7 @@ private void addDirectDependency(Type type, @Nullable Object value, IdentityHash } } } - else if ( type instanceof CollectionType ) { - CollectionType collectionType = (CollectionType) type; + else if ( type instanceof CollectionType collectionType ) { final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession() .getFactory() .getMappingMetamodel() @@ -1212,9 +1210,8 @@ else if ( type instanceof CollectionType ) { } } } - else if ( type instanceof ComponentType ) { + else if ( type instanceof ComponentType compositeType ) { // Support recursive checks of composite type properties for associations and collections. - ComponentType compositeType = (ComponentType) type; final SharedSessionContractImplementor session = insertAction.getSession(); final Object[] componentValues = compositeType.getPropertyValues( value, session ); for ( int j = 0; j < componentValues.length; ++j ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyle.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyle.java index d54300e29fb7..bbe1bd2ae7b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyle.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyle.java @@ -22,7 +22,7 @@ public interface CascadeStyle extends Serializable { * * @return True if the action should be cascaded under this style; false otherwise. */ - boolean doCascade(CascadingAction action); + boolean doCascade(CascadingAction action); /** * Probably more aptly named something like doCascadeToCollectionElements(); it is @@ -38,7 +38,7 @@ public interface CascadeStyle extends Serializable { * @return True if the action should be really cascaded under this style; * false otherwise. */ - boolean reallyDoCascade(CascadingAction action); + boolean reallyDoCascade(CascadingAction action); /** * Do we need to delete orphaned collection elements? diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java index 7c0f75e3cfb2..7eeb60de5b65 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyles.java @@ -30,7 +30,7 @@ private CascadeStyles() { */ public static final CascadeStyle ALL_DELETE_ORPHAN = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action != CascadingActions.CHECK_ON_FLUSH; } @@ -50,7 +50,7 @@ public String toString() { */ public static final CascadeStyle ALL = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action != CascadingActions.CHECK_ON_FLUSH; } @@ -65,7 +65,7 @@ public String toString() { */ public static final CascadeStyle LOCK = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.LOCK || action == CascadingActions.CHECK_ON_FLUSH; } @@ -81,7 +81,7 @@ public String toString() { */ public static final CascadeStyle REFRESH = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.REFRESH || action == CascadingActions.CHECK_ON_FLUSH; } @@ -97,7 +97,7 @@ public String toString() { */ public static final CascadeStyle EVICT = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.EVICT || action == CascadingActions.CHECK_ON_FLUSH; } @@ -113,7 +113,7 @@ public String toString() { */ public static final CascadeStyle REPLICATE = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.REPLICATE || action == CascadingActions.CHECK_ON_FLUSH; } @@ -129,7 +129,7 @@ public String toString() { */ public static final CascadeStyle MERGE = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.MERGE || action == CascadingActions.CHECK_ON_FLUSH; } @@ -145,7 +145,7 @@ public String toString() { */ public static final CascadeStyle PERSIST = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.PERSIST || action == CascadingActions.PERSIST_ON_FLUSH; } @@ -161,7 +161,7 @@ public String toString() { */ public static final CascadeStyle DELETE = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.REMOVE || action == CascadingActions.CHECK_ON_FLUSH; } @@ -177,14 +177,14 @@ public String toString() { */ public static final CascadeStyle DELETE_ORPHAN = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.REMOVE || action == CascadingActions.PERSIST_ON_FLUSH || action == CascadingActions.CHECK_ON_FLUSH; } @Override - public boolean reallyDoCascade(CascadingAction action) { + public boolean reallyDoCascade(CascadingAction action) { return action == CascadingActions.REMOVE || action == CascadingActions.CHECK_ON_FLUSH; } @@ -205,7 +205,7 @@ public String toString() { */ public static final CascadeStyle NONE = new BaseCascadeStyle() { @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { return action == CascadingActions.CHECK_ON_FLUSH; } @@ -268,7 +268,7 @@ public static void registerCascadeStyle(String name, BaseCascadeStyle cascadeSty public static abstract class BaseCascadeStyle implements CascadeStyle { @Override - public boolean reallyDoCascade(CascadingAction action) { + public boolean reallyDoCascade(CascadingAction action) { return doCascade( action ); } @@ -286,7 +286,7 @@ public MultipleCascadeStyle(CascadeStyle[] styles) { } @Override - public boolean doCascade(CascadingAction action) { + public boolean doCascade(CascadingAction action) { if ( action == CascadingActions.CHECK_ON_FLUSH ) { return !reallyDoCascade( CascadingActions.PERSIST_ON_FLUSH ); } @@ -299,7 +299,7 @@ public boolean doCascade(CascadingAction action) { } @Override - public boolean reallyDoCascade(CascadingAction action) { + public boolean reallyDoCascade(CascadingAction action) { for ( CascadeStyle style : styles ) { if ( style.reallyDoCascade( action ) ) { return true; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java index 2bb2e865d41e..ceb5ac642ab8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java @@ -17,9 +17,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** - * Think of this as the composite modeling of a graph - * and the semantic. - * + * Think of this as the composite modeling of a graph and the semantic. + *

* Its graph and semantic can be obtained by {@link #getGraph()} and * {@link #getSemantic()} * @@ -100,7 +99,7 @@ private void verifyWriteability() { * Apply a graph and semantic based on configuration properties or hints * based on {@link GraphSemantic#getJpaHintName()} for {@link GraphSemantic#LOAD} or * {@link GraphSemantic#FETCH}. - * + *

* The semantic is required. The graph * may be null, but that should generally be considered mis-use. * @@ -114,10 +113,10 @@ public void applyConfiguredGraph(@Nullable Map properties) { RootGraphImplementor fetchHint = (RootGraphImplementor) properties.get( GraphSemantic.FETCH.getJpaHintName() ); RootGraphImplementor loadHint = (RootGraphImplementor) properties.get( GraphSemantic.LOAD.getJpaHintName() ); - if (fetchHint == null) { + if ( fetchHint == null ) { fetchHint = (RootGraphImplementor) properties.get( GraphSemantic.FETCH.getJakartaHintName() ); } - if (loadHint == null) { + if ( loadHint == null ) { loadHint = (RootGraphImplementor) properties.get( GraphSemantic.LOAD.getJakartaHintName() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/ManagedEntity.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/ManagedEntity.java index 6380a0f19c8e..1de56ccc7530 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/ManagedEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/ManagedEntity.java @@ -81,28 +81,29 @@ public interface ManagedEntity extends Managed { /** * Used to understand if the tracker can be used to detect dirty properties. * - * E.g: - * @Entity - * class MyEntity{ - * @Id Integer id - * String name - * } - * - * inSession ( - * session -> { - * MyEntity entity = new MyEntity(1, "Poul"); - * session.persist(entity); - * }); - * - * - * inSession ( - * session -> { - * MyEntity entity = new MyEntity(1, null); - * session.merge(entity); - * }); - * - * Because the attribute `name` has been set to null the SelfDirtyTracker does not detect any change and - * so doesn't mark the attribute as dirty so the merge does not perform any update. + *

+	 * @Entity
+	 * class MyEntity{
+	 * 	@Id Integer id
+	 * 	String name
+	 * }
+	 *
+	 * inSession (
+	 * 	session -> {
+	 * 		MyEntity entity = new MyEntity(1, "Poul");
+	 * 		session.persist(entity);
+	 * });
+	 *
+	 *
+	 * inSession (
+	 * 	session -> {
+	 * 		MyEntity entity = new MyEntity(1, null);
+	 * 		session.merge(entity);
+	 * });
+	 * 
+ * Because the attribute `name` has been set to null the SelfDirtyTracker + * does not detect any change and so doesn't mark the attribute as dirty + * so the merge does not perform any update. * * * @param useTracker true if the tracker can be used to detect dirty properties, false otherwise diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SubselectFetch.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SubselectFetch.java index 57fcd79ca205..6da79e6ed600 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SubselectFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SubselectFetch.java @@ -74,7 +74,7 @@ public JdbcParameterBindings getLoadingJdbcParameterBindings() { /** *The entity-keys of all owners loaded from a particular execution - * + *

* Used for "empty collection" handling mostly */ public Set getResultingEntityKeys() { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Any.java b/hibernate-core/src/main/java/org/hibernate/mapping/Any.java index 1518ff742484..29a570a21e37 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Any.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Any.java @@ -394,7 +394,7 @@ public void addFormula(Formula formula) { @Override public boolean isValid(MappingContext mappingContext) { return columnName != null - && getType().getColumnSpan( mappingContext ) == 1; + && getType().getColumnSpan( mappingContext ) == 1; } } @@ -464,11 +464,5 @@ public void addFormula(Formula formula) { selectableConsumer.accept( formula ); } - - @Override - public boolean isValid(MappingContext mappingContext) throws MappingException { - // check - return super.isValid( mappingContext ); - } } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/CheckConstraint.java b/hibernate-core/src/main/java/org/hibernate/mapping/CheckConstraint.java index 1b1fc3c678c9..d543ee21eff1 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/CheckConstraint.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/CheckConstraint.java @@ -85,8 +85,7 @@ public String constraintString(Dialect dialect) { @Override public boolean equals(Object object) { - if ( object instanceof CheckConstraint ) { - CheckConstraint other = (CheckConstraint) object; + if ( object instanceof CheckConstraint other ) { return Objects.equals( name, other.name ) && Objects.equals( constraint, other.constraint ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java index 66b09c9b9f6d..db94ae0c1c2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java @@ -493,14 +493,14 @@ private Type getTypeForComponentValue(MappingContext mappingContext, Type type, final Type[] subtypes = ( (ComponentType) type ).getSubtypes(); int typeStartIndex = 0; for ( Type subtype : subtypes ) { - final int columnSpan = subtype.getColumnSpan(mappingContext); + final int columnSpan = subtype.getColumnSpan( mappingContext ); if ( typeStartIndex + columnSpan > typeIndex ) { final int subtypeIndex = typeIndex - typeStartIndex; if ( subtype instanceof EntityType ) { - return getTypeForEntityValue(mappingContext, subtype, subtypeIndex); + return getTypeForEntityValue( mappingContext, subtype, subtypeIndex ); } if ( subtype instanceof ComponentType ) { - return getTypeForComponentValue(mappingContext, subtype, subtypeIndex); + return getTypeForComponentValue( mappingContext, subtype, subtypeIndex ); } if ( subtypeIndex == 0 ) { return subtype; diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Index.java b/hibernate-core/src/main/java/org/hibernate/mapping/Index.java index 7a8e6f026e99..8b0e975b7dab 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Index.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Index.java @@ -77,7 +77,7 @@ public Map getSelectableOrderMap() { */ @Deprecated(since = "6.3") public java.util.List getColumns() { - return selectables.stream().map( s -> (Column) s ).toList(); + return selectables.stream().map( selectable -> (Column) selectable ).toList(); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java index 1fb6d87a6fb1..fd452a17a237 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java @@ -325,8 +325,7 @@ private void checkTableDuplication() { * correct) we simply log a warning. */ private void checkCompositeIdentifier() { - if ( getIdentifier() instanceof Component ) { - final Component id = (Component) getIdentifier(); + if ( getIdentifier() instanceof Component id ) { if ( !id.isDynamic() ) { final Class idClass = id.getComponentClass(); if ( idClass != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Set.java b/hibernate-core/src/main/java/org/hibernate/mapping/Set.java index a8f81afca0b0..f9cd72b7936a 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Set.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Set.java @@ -89,8 +89,7 @@ void createPrimaryKey() { pk = new PrimaryKey( getCollectionTable() ); pk.addColumns( getKey() ); for ( Selectable selectable : getElement().getSelectables() ) { - if ( selectable instanceof Column ) { - Column col = (Column) selectable; + if ( selectable instanceof Column col ) { if ( !col.isNullable() ) { pk.addColumn( col ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java index c6659466d77a..b0346a357f0b 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java @@ -12,7 +12,6 @@ import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.internal.FilterConfiguration; import org.hibernate.internal.util.collections.JoinedList; -import org.hibernate.persister.entity.EntityPersister; /** * A mapping model object that represents a subclass in an entity class @@ -23,7 +22,6 @@ public class Subclass extends PersistentClass { private PersistentClass superclass; - private Class classPersisterClass; private final int subclassId; public Subclass(PersistentClass superclass, MetadataBuildingContext buildingContext) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/ToOne.java b/hibernate-core/src/main/java/org/hibernate/mapping/ToOne.java index 42c98ff52545..577ac7058392 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/ToOne.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/ToOne.java @@ -102,11 +102,6 @@ public boolean isTypeSpecified() { return referencedEntityName!=null; } - @Override - public Object accept(ValueVisitor visitor) { - return visitor.accept(this); - } - @Override public boolean isSame(SimpleValue other) { return other instanceof ToOne && isSame( (ToOne) other ); @@ -120,7 +115,7 @@ public boolean isSame(ToOne other) { @Override public boolean isValid(MappingContext mappingContext) throws MappingException { - if (referencedEntityName==null) { + if ( referencedEntityName==null ) { throw new MappingException("association must specify the referenced entity"); } return super.isValid( mappingContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Value.java b/hibernate-core/src/main/java/org/hibernate/mapping/Value.java index 41ee4c8c28c7..a48d8beac984 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Value.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Value.java @@ -87,15 +87,13 @@ default JdbcMapping getSelectableType(MappingContext mappingContext, int index) } private JdbcMapping getType(MappingContext factory, Type elementType, int index) { - if ( elementType instanceof CompositeType ) { - final Type[] subtypes = ( (CompositeType) elementType ).getSubtypes(); + if ( elementType instanceof CompositeType compositeType ) { + final Type[] subtypes = compositeType.getSubtypes(); for ( int i = 0; i < subtypes.length; i++ ) { final Type subtype = subtypes[i]; final int columnSpan; - if ( subtype instanceof EntityType ) { - final EntityType entityType = (EntityType) subtype; - final Type idType = getIdType( entityType ); - columnSpan = idType.getColumnSpan( factory ); + if ( subtype instanceof EntityType entityType ) { + columnSpan = getIdType( entityType ).getColumnSpan( factory ); } else { columnSpan = subtype.getColumnSpan( factory ); @@ -110,13 +108,11 @@ else if ( columnSpan != 0 ) { // Should never happen throw new IllegalStateException( "Type index is past the types column span!" ); } - else if ( elementType instanceof EntityType ) { - final EntityType entityType = (EntityType) elementType; - final Type idType = getIdType( entityType ); - return getType( factory, idType, index ); + else if ( elementType instanceof EntityType entityType ) { + return getType( factory, getIdType( entityType ), index ); } - else if ( elementType instanceof MetaType ) { - return (JdbcMapping) ( (MetaType) elementType ).getBaseType(); + else if ( elementType instanceof MetaType metaType ) { + return (JdbcMapping) metaType.getBaseType(); } return (JdbcMapping) elementType; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java index ac838fb4f4cd..744f834b6c95 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java @@ -49,7 +49,7 @@ public abstract class AbstractStandardBasicType private final ValueExtractor jdbcValueExtractor; private final JdbcLiteralFormatter jdbcLiteralFormatter; private final @Nullable Type typeForEqualsHashCode; - private final Class javaTypeClass; + private final Class javaTypeClass; private final MutabilityPlan mutabilityPlan; private final Comparator javatypeComparator; @@ -124,7 +124,7 @@ public final JdbcType getJdbcType() { } @Override - public final Class getReturnedClass() { + public final Class getReturnedClass() { return javaTypeClass; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index 6a9be0c6007a..9acb89579966 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -514,13 +514,10 @@ public Object replaceElements( // One thing to be careful of here is a "bare" original collection // in which case we should never ever ever reset the dirty flag // on the target because we simply do not know... - if ( original instanceof PersistentCollection && result instanceof PersistentCollection ) { - final PersistentCollection originalPersistentCollection = (PersistentCollection) original; - final PersistentCollection resultPersistentCollection = (PersistentCollection) result; - + if ( original instanceof PersistentCollection originalPersistentCollection + && result instanceof PersistentCollection resultPersistentCollection) { preserveSnapshot( originalPersistentCollection, resultPersistentCollection, elemType, owner, copyCache, session ); - - if ( ! originalPersistentCollection.isDirty() ) { + if ( !originalPersistentCollection.isDirty() ) { resultPersistentCollection.clearDirty(); } } @@ -582,10 +579,9 @@ else if ( originalSnapshot instanceof Map ) { } } - else if ( originalSnapshot instanceof Object[] ) { - Object[] arr = (Object[]) originalSnapshot; - for ( int i = 0; i < arr.length; i++ ) { - arr[i] = elemType.replace( arr[i], null, session, owner, copyCache ); + else if ( originalSnapshot instanceof Object[] array ) { + for ( int i = 0; i < array.length; i++ ) { + array[i] = elemType.replace( array[i], null, session, owner, copyCache ); } targetSnapshot = originalSnapshot; diff --git a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java index f9f421d7010c..9d792325b691 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java @@ -668,8 +668,8 @@ public final Type getIdentifierOrUniqueKeyType(MappingContext mappingContext) th } else { final Type type = mappingContext.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); - if ( type instanceof EntityType ) { - return ( (EntityType) type ).getIdentifierOrUniqueKeyType( mappingContext ); + if ( type instanceof EntityType entityType ) { + return entityType.getIdentifierOrUniqueKeyType( mappingContext ); } else { return type; diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java index 354de208cc72..8876fb3d3636 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java @@ -146,7 +146,7 @@ public final JdbcType getJdbcType() { } @Override - public final Class getReturnedClass() { + public final Class getReturnedClass() { return converter.getDomainJavaType().getJavaTypeClass(); }