Skip to content

Commit 25d0922

Browse files
committed
fix up lots of warnings, esp. unused parameters
1 parent b4e26b3 commit 25d0922

29 files changed

+271
-443
lines changed

hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void integrate(
9191
Metadata metadata,
9292
BootstrapContext bootstrapContext,
9393
SessionFactoryImplementor sessionFactory) {
94-
ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
94+
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
9595
final ConfigurationService cfgService = serviceRegistry.requireService( ConfigurationService.class );
9696
// IMPL NOTE : see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
9797
Object modeSetting = cfgService.getSettings().get( JAKARTA_MODE_PROPERTY );

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.hibernate.event.service.spi.EventListenerGroup;
4747
import org.hibernate.event.service.spi.EventListenerRegistry;
4848
import org.hibernate.event.spi.EventType;
49-
import org.hibernate.internal.util.collections.CollectionHelper;
5049
import org.hibernate.mapping.Collection;
5150
import org.hibernate.mapping.Column;
5251
import org.hibernate.mapping.Component;

hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/**
3838
* Allows the collection cache to be automatically evicted if an element is inserted/removed/updated *without* properly
3939
* managing both sides of the association (ie, the ManyToOne collection is changed w/o properly managing the OneToMany).
40-
*
40+
* <p>
4141
* For this functionality to be used, {@value org.hibernate.cfg.AvailableSettings#AUTO_EVICT_COLLECTION_CACHE} must be
4242
* enabled. For performance reasons, it's disabled by default.
4343
*
@@ -90,7 +90,8 @@ private void integrate(SessionFactoryImplementor sessionFactory) {
9090
// Nothing to do, if caching is disabled
9191
return;
9292
}
93-
final EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry().requireService( EventListenerRegistry.class );
93+
final EventListenerRegistry eventListenerRegistry =
94+
sessionFactory.getServiceRegistry().requireService( EventListenerRegistry.class );
9495
eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
9596
eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
9697
eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.hibernate.metamodel.mapping.AttributeMapping;
3131
import org.hibernate.metamodel.mapping.CollectionPart;
3232
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
33-
import org.hibernate.metamodel.mapping.EntityMappingType;
3433
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
3534
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
3635
import org.hibernate.metamodel.mapping.ModelPart;

hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ default EntityPersister locateEntityPersister(Class<?> byClass) {
202202
<T> void addNamedEntityGraph(String graphName, RootGraphImplementor<T> entityGraph);
203203
void forEachNamedGraph(Consumer<RootGraph<?>> action);
204204
RootGraph<?> defaultGraph(String entityName);
205-
RootGraph<?> defaultGraph(Class entityJavaType);
205+
RootGraph<?> defaultGraph(Class<?> entityJavaType);
206206
RootGraph<?> defaultGraph(EntityPersister entityDescriptor);
207207
RootGraph<?> defaultGraph(EntityDomainType<?> entityDomainType);
208208

209-
List<RootGraph<?>> findRootGraphsForType(Class baseEntityJavaType);
209+
List<RootGraph<?>> findRootGraphsForType(Class<?> baseEntityJavaType);
210210
List<RootGraph<?>> findRootGraphsForType(String baseEntityName);
211211
List<RootGraph<?>> findRootGraphsForType(EntityPersister baseEntityDescriptor);
212212
}

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import org.hibernate.graph.spi.SubGraphImplementor;
1212
import org.hibernate.metamodel.MappingMetamodel;
1313
import org.hibernate.metamodel.mapping.EntityMappingType;
14-
import org.hibernate.metamodel.mapping.MappingModelHelper;
1514
import org.hibernate.metamodel.mapping.ModelPart;
1615
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
1716
import org.hibernate.metamodel.model.domain.EntityDomainType;
1817
import org.hibernate.metamodel.model.domain.JpaMetamodel;
1918
import org.hibernate.metamodel.model.domain.ManagedDomainType;
2019
import org.hibernate.metamodel.model.domain.PersistentAttribute;
21-
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
20+
21+
import static org.hibernate.metamodel.mapping.MappingModelHelper.isCompatibleModelPart;
2222

2323
/**
2424
* Helper containing utilities useful for domain model handling
@@ -38,16 +38,16 @@ public static <T, S extends T> ManagedDomainType<S> resolveSubType(
3838
}
3939

4040
// first, try to find it by name directly
41-
ManagedDomainType<S> subManagedType = jpaMetamodel.resolveHqlEntityReference( subTypeName );
41+
final ManagedDomainType<S> subManagedType = jpaMetamodel.resolveHqlEntityReference( subTypeName );
4242
if ( subManagedType != null ) {
4343
return subManagedType;
4444
}
4545

4646
// it could still be a mapped-superclass
4747
try {
48-
final Class<?> javaType = jpaMetamodel.getServiceRegistry()
49-
.requireService( ClassLoaderService.class )
50-
.classForName( subTypeName );
48+
final Class<?> javaType =
49+
jpaMetamodel.getServiceRegistry().requireService( ClassLoaderService.class )
50+
.classForName( subTypeName );
5151
return (ManagedDomainType<S>) jpaMetamodel.managedType( javaType );
5252
}
5353
catch (Exception ignore) {
@@ -59,27 +59,19 @@ public static <T, S extends T> ManagedDomainType<S> resolveSubType(
5959
static boolean isCompatible(
6060
PersistentAttribute<?, ?> attribute1,
6161
PersistentAttribute<?, ?> attribute2,
62-
JpaMetamodel jpaMetamodel) {
62+
MappingMetamodel mappingMetamodel) {
6363
if ( attribute1 == attribute2 ) {
6464
return true;
6565
}
66-
final MappingMetamodel runtimeMetamodels =
67-
//TODO: eliminate this cast!
68-
((JpaMetamodelImplementor) jpaMetamodel).getMappingMetamodel();
69-
final ModelPart modelPart1 = getEntityAttributeModelPart(
70-
attribute1,
71-
attribute1.getDeclaringType(),
72-
runtimeMetamodels
73-
);
74-
final ModelPart modelPart2 = getEntityAttributeModelPart(
75-
attribute2,
76-
attribute2.getDeclaringType(),
77-
runtimeMetamodels
78-
);
79-
return modelPart1 != null && modelPart2 != null && MappingModelHelper.isCompatibleModelPart(
80-
modelPart1,
81-
modelPart2
82-
);
66+
else {
67+
final ModelPart modelPart1 =
68+
getEntityAttributeModelPart( attribute1, attribute1.getDeclaringType(), mappingMetamodel );
69+
final ModelPart modelPart2 =
70+
getEntityAttributeModelPart( attribute2, attribute2.getDeclaringType(), mappingMetamodel );
71+
return modelPart1 != null
72+
&& modelPart2 != null
73+
&& isCompatibleModelPart( modelPart1, modelPart2 );
74+
}
8375
}
8476

8577
static ModelPart getEntityAttributeModelPart(
@@ -95,7 +87,7 @@ static ModelPart getEntityAttributeModelPart(
9587
for ( ManagedDomainType<?> subType : domainType.getSubTypes() ) {
9688
final ModelPart modelPart = getEntityAttributeModelPart( attribute, subType, mappingMetamodel );
9789
if ( modelPart != null ) {
98-
if ( candidate != null && !MappingModelHelper.isCompatibleModelPart( candidate, modelPart ) ) {
90+
if ( candidate != null && !isCompatibleModelPart( candidate, modelPart ) ) {
9991
return null;
10092
}
10193
candidate = modelPart;

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.metamodel.model.domain.internal;
88

99
import java.io.ObjectStreamException;
10+
import java.io.Serial;
1011
import java.io.Serializable;
1112
import java.util.Collection;
1213
import java.util.Locale;
@@ -75,16 +76,13 @@ public EntityTypeImpl(
7576
metamodel.getMappingMetamodel()
7677
.getEntityDescriptor( getHibernateEntityName() );
7778
final DiscriminatorMetadata discriminatorMetadata = entityDescriptor.getTypeDiscriminatorMetadata();
78-
final DomainType discriminatorType =
79+
final DomainType<?> discriminatorType =
7980
discriminatorMetadata != null
80-
? (DomainType) discriminatorMetadata.getResolutionType()
81+
? (DomainType<?>) discriminatorMetadata.getResolutionType()
8182
: metamodel.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING );
8283

83-
this.discriminatorPathSource = discriminatorType == null ? null : new EntityDiscriminatorSqmPathSource(
84-
discriminatorType,
85-
this,
86-
entityDescriptor
87-
);
84+
this.discriminatorPathSource = discriminatorType == null ? null
85+
: new EntityDiscriminatorSqmPathSource<>( discriminatorType, this, entityDescriptor );
8886
}
8987

9088
public EntityTypeImpl(
@@ -147,16 +145,16 @@ public SqmPathSource<?> findSubPathSource(String name) {
147145
if ( attribute != null ) {
148146
return (SqmPathSource<?>) attribute;
149147
}
150-
151-
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
148+
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
152149
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
153150
}
154151

155-
if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
152+
else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
156153
return discriminatorPathSource;
157154
}
158-
159-
return null;
155+
else {
156+
return null;
157+
}
160158
}
161159

162160
@Override
@@ -165,29 +163,31 @@ public SqmPathSource<?> findSubPathSource(String name, JpaMetamodel metamodel) {
165163
if ( attribute != null ) {
166164
return (SqmPathSource<?>) attribute;
167165
}
168-
169-
PersistentAttribute<?, ?> subtypeAttribute = findSubtypeAttribute( name, metamodel );
170-
if ( subtypeAttribute != null ) {
171-
return (SqmPathSource<?>) subtypeAttribute;
172-
}
173-
174-
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
175-
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
176-
}
177-
178-
if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
179-
return discriminatorPathSource;
166+
else {
167+
//TODO: eliminate this cast!
168+
final PersistentAttribute<?, ?> subtypeAttribute = findSubtypeAttribute( name );
169+
if ( subtypeAttribute != null ) {
170+
return (SqmPathSource<?>) subtypeAttribute;
171+
}
172+
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
173+
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
174+
}
175+
else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
176+
return discriminatorPathSource;
177+
}
178+
else {
179+
return null;
180+
}
180181
}
181-
182-
return null;
183182
}
184183

185-
private PersistentAttribute<?, ?> findSubtypeAttribute(String name, JpaMetamodel metamodel) {
184+
private PersistentAttribute<?, ?> findSubtypeAttribute(String name) {
186185
PersistentAttribute<?,?> subtypeAttribute = null;
187186
for ( ManagedDomainType<?> subtype : getSubTypes() ) {
188187
final PersistentAttribute<?,?> candidate = subtype.findSubTypesAttribute( name );
189188
if ( candidate != null ) {
190-
if ( subtypeAttribute != null && !isCompatible( subtypeAttribute, candidate, metamodel ) ) {
189+
if ( subtypeAttribute != null
190+
&& !isCompatible( subtypeAttribute, candidate, metamodel.getMappingMetamodel() ) ) {
191191
throw new PathException(
192192
String.format(
193193
Locale.ROOT,
@@ -211,12 +211,12 @@ public SqmPathSource<?> findSubPathSource(String name, JpaMetamodel metamodel) {
211211
if ( attribute != null ) {
212212
return attribute;
213213
}
214-
215-
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
214+
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
216215
return findIdAttribute();
217216
}
218-
219-
return null;
217+
else {
218+
return null;
219+
}
220220
}
221221

222222
@Override
@@ -255,6 +255,7 @@ public SqmPath<J> createSqmPath(SqmPath<?> lhs, SqmPathSource<?> intermediatePat
255255
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256256
// Serialization
257257

258+
@Serial
258259
protected Object writeReplace() throws ObjectStreamException {
259260
return new SerialForm( metamodel, getHibernateEntityName() );
260261
}
@@ -268,6 +269,7 @@ public SerialForm(JpaMetamodel jpaMetamodel, String hibernateEntityName) {
268269
this.hibernateEntityName = hibernateEntityName;
269270
}
270271

272+
@Serial
271273
private Object readResolve() {
272274
return jpaMetamodel.entity( hibernateEntityName );
273275
}

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.lang.reflect.Field;
1313
import java.util.ArrayList;
1414
import java.util.Collection;
15-
import java.util.Collections;
1615
import java.util.HashMap;
1716
import java.util.HashSet;
1817
import java.util.List;
@@ -70,6 +69,8 @@
7069
import jakarta.persistence.metamodel.ManagedType;
7170
import jakarta.persistence.metamodel.Type;
7271

72+
import static java.util.Collections.emptySet;
73+
7374
/**
7475
*
7576
* @author Steve Ebersole
@@ -247,17 +248,12 @@ public <X> EmbeddableDomainType<X> embeddable(Class<X> cls) {
247248
}
248249

249250
private Collection<ManagedDomainType<?>> getAllManagedTypes() {
250-
switch ( jpaMetaModelPopulationSetting ) {
251-
case IGNORE_UNSUPPORTED:
252-
return managedTypeByClass.values();
253-
case ENABLED:
254-
return managedTypeByName.values();
255-
case DISABLED:
256-
return Collections.emptySet();
257-
default:
258-
// should never happen
259-
throw new AssertionError();
260-
}
251+
// should never happen
252+
return switch (jpaMetaModelPopulationSetting) {
253+
case IGNORE_UNSUPPORTED -> managedTypeByClass.values();
254+
case ENABLED -> managedTypeByName.values();
255+
case DISABLED -> emptySet();
256+
};
261257
}
262258

263259
@Override
@@ -649,9 +645,8 @@ public void processJpa(
649645
}
650646
}
651647

652-
typeConfiguration.getJavaTypeRegistry().forEachDescriptor( (descriptor) -> {
653-
if ( descriptor instanceof EnumJavaType ) {
654-
final EnumJavaType<? extends Enum<?>> enumJavaType = (EnumJavaType<? extends Enum<?>>) descriptor;
648+
typeConfiguration.getJavaTypeRegistry().forEachDescriptor( descriptor -> {
649+
if ( descriptor instanceof EnumJavaType<? extends Enum<?>> enumJavaType ) {
655650
final Class<? extends Enum<?>> enumJavaClass = enumJavaType.getJavaTypeClass();
656651
final Enum<?>[] enumConstants = enumJavaClass.getEnumConstants();
657652
for ( Enum<?> enumConstant : enumConstants ) {

0 commit comments

Comments
 (0)