Skip to content

Commit 1f16a06

Browse files
committed
fix more warnings
1 parent 0c3b8fd commit 1f16a06

File tree

9 files changed

+165
-284
lines changed

9 files changed

+165
-284
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ else if ( columnOwner instanceof Join ) {
449449
// Now, for each column find the properties of the target entity
450450
// which are mapped to that column. (There might be multiple such
451451
// properties for each column.)
452-
if ( columnOwner instanceof PersistentClass ) {
453-
final PersistentClass persistentClass = (PersistentClass) columnOwner;
452+
if ( columnOwner instanceof PersistentClass persistentClass ) {
454453
// Process ToOne associations after Components, Basic and Id properties
455454
final List<Property> toOneProperties = new ArrayList<>();
456455
for ( Property property : persistentClass.getReferenceableProperties() ) {
@@ -969,22 +968,14 @@ private static EnumSet<CascadeType> convertToHibernateCascadeType(jakarta.persis
969968
}
970969

971970
private static CascadeType convertCascadeType(jakarta.persistence.CascadeType cascade) {
972-
switch ( cascade ) {
973-
case ALL:
974-
return CascadeType.ALL;
975-
case PERSIST:
976-
return CascadeType.PERSIST;
977-
case MERGE:
978-
return CascadeType.MERGE;
979-
case REMOVE:
980-
return CascadeType.REMOVE;
981-
case REFRESH:
982-
return CascadeType.REFRESH;
983-
case DETACH:
984-
return CascadeType.DETACH;
985-
default:
986-
throw new AssertionFailure("unknown cascade type: " + cascade);
987-
}
971+
return switch (cascade) {
972+
case ALL -> CascadeType.ALL;
973+
case PERSIST -> CascadeType.PERSIST;
974+
case MERGE -> CascadeType.MERGE;
975+
case REMOVE -> CascadeType.REMOVE;
976+
case REFRESH -> CascadeType.REFRESH;
977+
case DETACH -> CascadeType.DETACH;
978+
};
988979
}
989980

990981
private static String renderCascadeTypeList(EnumSet<CascadeType> cascadeTypes) {

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
179179
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
180180
import static org.hibernate.internal.util.StringHelper.qualify;
181+
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
181182
import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeBean;
182183

183184
/**
@@ -392,7 +393,7 @@ private static AnnotatedJoinColumns mapKeyJoinColumns(
392393
MemberDetails property) {
393394
// Comment comment) {
394395
return buildJoinColumnsWithDefaultColumnSuffix(
395-
mapKeyJoinColumnAnnotations( propertyHolder, inferredData, property, context ),
396+
mapKeyJoinColumnAnnotations( property, context ),
396397
// comment,
397398
null,
398399
entityBinder.getSecondaryTables(),
@@ -560,13 +561,8 @@ private static boolean hasMapKeyAnnotation(MemberDetails property) {
560561
}
561562

562563
private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) {
563-
if ( propertyHolder instanceof ComponentPropertyHolder ) {
564-
ComponentPropertyHolder componentPropertyHolder = (ComponentPropertyHolder) propertyHolder;
565-
return componentPropertyHolder.isWithinElementCollection();
566-
}
567-
else {
568-
return false;
569-
}
564+
return propertyHolder instanceof ComponentPropertyHolder componentPropertyHolder
565+
&& componentPropertyHolder.isWithinElementCollection();
570566
}
571567

572568
private static AnnotatedColumns elementColumns(
@@ -626,16 +622,14 @@ else if ( property.hasDirectAnnotationUsage( Columns.class ) ) {
626622
}
627623

628624
private static JoinColumn[] mapKeyJoinColumnAnnotations(
629-
PropertyHolder propertyHolder,
630-
PropertyData inferredData,
631625
MemberDetails property,
632626
MetadataBuildingContext context) {
633627
final MapKeyJoinColumn[] mapKeyJoinColumns = property.getRepeatedAnnotationUsages(
634628
JpaAnnotations.MAP_KEY_JOIN_COLUMN,
635629
context.getMetadataCollector().getSourceModelBuildingContext()
636630
);
637631

638-
if ( CollectionHelper.isEmpty( mapKeyJoinColumns ) ) {
632+
if ( isEmpty( mapKeyJoinColumns ) ) {
639633
return null;
640634
}
641635

@@ -945,7 +939,7 @@ private static CollectionBinder createBinderFromCustomTypeAnnotation(
945939
MemberDetails property,
946940
CollectionType typeAnnotation,
947941
MetadataBuildingContext buildingContext) {
948-
determineSemanticJavaType( property, buildingContext );
942+
determineSemanticJavaType( property );
949943
final ManagedBean<? extends UserCollectionType> customTypeBean = resolveCustomType(
950944
property,
951945
typeAnnotation,
@@ -1014,7 +1008,7 @@ private static CollectionClassification determineCollectionClassification(
10141008
final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext();
10151009

10161010
if ( !property.hasAnnotationUsage( Bag.class, sourceModelContext ) ) {
1017-
return determineCollectionClassification( determineSemanticJavaType( property, buildingContext ), property, buildingContext );
1011+
return determineCollectionClassification( determineSemanticJavaType( property ), property, buildingContext );
10181012
}
10191013

10201014
if ( property.hasAnnotationUsage( OrderColumn.class, sourceModelContext ) ) {
@@ -1126,7 +1120,7 @@ private static CollectionClassification determineCollectionClassification(
11261120
return null;
11271121
}
11281122

1129-
private static Class<?> determineSemanticJavaType(MemberDetails property, MetadataBuildingContext buildingContext) {
1123+
private static Class<?> determineSemanticJavaType(MemberDetails property) {
11301124
if ( property.isPlural() ) {
11311125
final ClassDetails collectionClassDetails = property.getType().determineRawClass();
11321126
final Class<?> collectionClass = collectionClassDetails.toJavaClass();
@@ -1536,25 +1530,23 @@ private void handleFetch() {
15361530

15371531
private void setHibernateFetchMode(org.hibernate.annotations.FetchMode fetchMode) {
15381532
switch ( fetchMode ) {
1539-
case JOIN -> {
1533+
case JOIN :
15401534
collection.setFetchMode( FetchMode.JOIN );
15411535
collection.setLazy( false );
1542-
}
1543-
case SELECT -> {
1536+
break;
1537+
case SELECT:
15441538
collection.setFetchMode( FetchMode.SELECT );
1545-
}
1546-
case SUBSELECT -> {
1539+
break;
1540+
case SUBSELECT:
15471541
collection.setFetchMode( FetchMode.SELECT );
15481542
collection.setSubselectLoadable( true );
15491543
collection.getOwner().setSubselectLoadableCollections( true );
1550-
}
1551-
default -> {
1544+
break;
1545+
default:
15521546
throw new AssertionFailure( "unknown fetch type" );
1553-
}
15541547
}
15551548
}
15561549

1557-
@SuppressWarnings("deprecation")
15581550
private void handleLazy() {
15591551
final FetchType jpaFetchType = getJpaFetchType();
15601552
collection.setLazy( jpaFetchType == LAZY );
@@ -1877,7 +1869,6 @@ private String getWhereOnCollectionClause() {
18771869
}
18781870

18791871
private String getWhereOnClassClause() {
1880-
final TypeDetails elementType = property.getElementType();
18811872
final SQLRestriction restrictionOnClass = getOverridableAnnotation(
18821873
property.getAssociatedType().determineRawClass(),
18831874
SQLRestriction.class,
@@ -2010,7 +2001,7 @@ private static String buildOrderById(PersistentClass associatedClass, String ord
20102001
public static String adjustUserSuppliedValueCollectionOrderingFragment(String orderByFragment) {
20112002
if ( orderByFragment != null ) {
20122003
orderByFragment = orderByFragment.trim();
2013-
if ( orderByFragment.length() == 0 || orderByFragment.equalsIgnoreCase( "asc" ) ) {
2004+
if ( orderByFragment.isEmpty() || orderByFragment.equalsIgnoreCase( "asc" ) ) {
20142005
// This indicates something like either:
20152006
// `@OrderBy()`
20162007
// `@OrderBy("asc")
@@ -2071,7 +2062,6 @@ private DependantValue buildCollectionKey(AnnotatedJoinColumns joinColumns, OnDe
20712062
if ( key.getForeignKeyName() == null
20722063
&& key.getForeignKeyDefinition() == null
20732064
&& collectionTableAnn.joinColumns().length == 1 ) {
2074-
//noinspection unchecked
20752065
final JoinColumn joinColumn = collectionTableAnn.joinColumns()[0];
20762066
final ForeignKey nestedForeignKey = joinColumn.foreignKey();
20772067
key.setForeignKeyName( nullIfEmpty( nestedForeignKey.name() ) );
@@ -2237,12 +2227,13 @@ private void handleElementCollection(TypeDetails elementType, String hqlOrderBy)
22372227
buildingContext
22382228
);
22392229

2240-
final Class<? extends CompositeUserType<?>> compositeUserType = resolveCompositeUserType( property, elementClass, buildingContext );
2241-
boolean isComposite = classType == EMBEDDABLE || compositeUserType != null;
2230+
final Class<? extends CompositeUserType<?>> compositeUserType =
2231+
resolveCompositeUserType( property, elementClass, buildingContext );
2232+
final boolean isComposite = classType == EMBEDDABLE || compositeUserType != null;
22422233
holder.prepare( property, isComposite );
22432234

22442235
if ( isComposite ) {
2245-
handleCompositeCollectionElement( hqlOrderBy, elementType, elementClass, holder, compositeUserType );
2236+
handleCompositeCollectionElement( hqlOrderBy, elementType, holder, compositeUserType );
22462237
}
22472238
else {
22482239
handleCollectionElement( elementType, hqlOrderBy, elementClass, holder );
@@ -2283,7 +2274,6 @@ private void handleCollectionElement(
22832274
private void handleCompositeCollectionElement(
22842275
String hqlOrderBy,
22852276
TypeDetails elementType,
2286-
ClassDetails elementClass,
22872277
CollectionPropertyHolder holder,
22882278
Class<? extends CompositeUserType<?>> compositeUserType) {
22892279
//TODO be smart with isNullable
@@ -2555,7 +2545,7 @@ private static void addCheckToCollection(Table collectionTable, Check check) {
25552545
private void processSoftDeletes() {
25562546
assert collection.getCollectionTable() != null;
25572547

2558-
final SoftDelete softDelete = extractSoftDelete( property, propertyHolder, buildingContext );
2548+
final SoftDelete softDelete = extractSoftDelete( property, buildingContext );
25592549
if ( softDelete == null ) {
25602550
return;
25612551
}
@@ -2568,20 +2558,18 @@ private void processSoftDeletes() {
25682558
);
25692559
}
25702560

2571-
private static SoftDelete extractSoftDelete(
2572-
MemberDetails property,
2573-
PropertyHolder propertyHolder,
2574-
MetadataBuildingContext context) {
2561+
private static SoftDelete extractSoftDelete(MemberDetails property, MetadataBuildingContext context) {
25752562
final SoftDelete fromProperty = property.getDirectAnnotationUsage( SoftDelete.class );
25762563
if ( fromProperty != null ) {
25772564
return fromProperty;
25782565
}
2579-
2580-
return extractFromPackage(
2581-
SoftDelete.class,
2582-
property.getDeclaringType(),
2583-
context
2584-
);
2566+
else {
2567+
return extractFromPackage(
2568+
SoftDelete.class,
2569+
property.getDeclaringType(),
2570+
context
2571+
);
2572+
}
25852573
}
25862574

25872575
private void handleUnownedManyToMany(

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionSecondPass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public void doSecondPass(Map<String, PersistentClass> persistentClasses)
6565
abstract public void secondPass(Map<String, PersistentClass> persistentClasses) throws MappingException;
6666

6767
private static String columns(Value val) {
68-
StringBuilder columns = new StringBuilder();
68+
final StringBuilder columns = new StringBuilder();
6969
for ( Selectable selectable : val.getSelectables() ) {
70-
if ( columns.length() > 0 ) {
70+
if ( !columns.isEmpty() ) {
7171
columns.append( ", " );
7272
}
7373
columns.append( selectable.getText() );

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public class EntityBinder {
175175
private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, EntityBinder.class.getName() );
176176
private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId";
177177

178-
private MetadataBuildingContext context;
178+
private final MetadataBuildingContext context;
179179

180180
private String name;
181181
private ClassDetails annotatedClass;
@@ -245,13 +245,13 @@ public static void bindEntityClass(
245245
entityBinder.handleIdentifier( holder, inheritanceStates, generators, inheritanceState );
246246

247247
final InFlightMetadataCollector collector = context.getMetadataCollector();
248-
if ( persistentClass instanceof RootClass ) {
249-
collector.addSecondPass( new CreateKeySecondPass( (RootClass) persistentClass ) );
250-
bindSoftDelete( clazzToProcess, (RootClass) persistentClass, inheritanceState, context );
248+
if ( persistentClass instanceof RootClass rootClass ) {
249+
collector.addSecondPass( new CreateKeySecondPass( rootClass ) );
250+
bindSoftDelete( clazzToProcess, rootClass, context );
251251
}
252-
if ( persistentClass instanceof Subclass) {
252+
if ( persistentClass instanceof Subclass subclass ) {
253253
assert superEntity != null;
254-
superEntity.addSubclass( (Subclass) persistentClass );
254+
superEntity.addSubclass( subclass );
255255
}
256256
collector.addEntityBinding( persistentClass );
257257
// process secondary tables and complementary definitions (ie o.h.a.Table)
@@ -306,12 +306,11 @@ private static void checkOverride(
306306
private static void bindSoftDelete(
307307
ClassDetails classDetails,
308308
RootClass rootClass,
309-
InheritanceState inheritanceState,
310309
MetadataBuildingContext context) {
311310
// todo (soft-delete) : do we assume all package-level registrations are already available?
312311
// or should this be a "second pass"?
313312

314-
final SoftDelete softDelete = extractSoftDelete( classDetails, inheritanceState, context );
313+
final SoftDelete softDelete = extractSoftDelete( classDetails, context );
315314
if ( softDelete != null ) {
316315
SoftDeleteHelper.bindSoftDeleteIndicator(
317316
softDelete,
@@ -322,10 +321,7 @@ private static void bindSoftDelete(
322321
}
323322
}
324323

325-
private static SoftDelete extractSoftDelete(
326-
ClassDetails classDetails,
327-
InheritanceState inheritanceState,
328-
MetadataBuildingContext context) {
324+
private static SoftDelete extractSoftDelete(ClassDetails classDetails, MetadataBuildingContext context) {
329325
final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext();
330326
final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, sourceModelContext );
331327
if ( fromClass != null ) {
@@ -381,9 +377,10 @@ private void callTypeBinders(PersistentClass persistentClass) {
381377
}
382378

383379
private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) {
384-
final Class<? extends TypeBinder<?>> binderClass = containingAnnotation.annotationType()
385-
.getAnnotation( TypeBinderType.class )
386-
.binder();
380+
final Class<? extends TypeBinder<?>> binderClass =
381+
containingAnnotation.annotationType()
382+
.getAnnotation( TypeBinderType.class )
383+
.binder();
387384

388385
try {
389386
//noinspection rawtypes
@@ -1096,7 +1093,7 @@ else if ( !missingEntityProperties.isEmpty() ) {
10961093
private static String getMissingPropertiesString(Set<String> propertyNames) {
10971094
final StringBuilder sb = new StringBuilder();
10981095
for ( String property : propertyNames ) {
1099-
if ( sb.length() > 0 ) {
1096+
if ( !sb.isEmpty() ) {
11001097
sb.append( ", " );
11011098
}
11021099
sb.append( "'" ).append( property ).append( "'" );
@@ -1113,16 +1110,11 @@ private static PersistentClass makePersistentClass(
11131110
return new RootClass( metadataBuildingContext );
11141111
}
11151112
else {
1116-
switch ( inheritanceState.getType() ) {
1117-
case SINGLE_TABLE:
1118-
return new SingleTableSubclass( superEntity, metadataBuildingContext );
1119-
case JOINED:
1120-
return new JoinedSubclass( superEntity, metadataBuildingContext );
1121-
case TABLE_PER_CLASS:
1122-
return new UnionSubclass( superEntity, metadataBuildingContext );
1123-
default:
1124-
throw new AssertionFailure( "Unknown inheritance type: " + inheritanceState.getType() );
1125-
}
1113+
return switch ( inheritanceState.getType() ) {
1114+
case SINGLE_TABLE -> new SingleTableSubclass( superEntity, metadataBuildingContext );
1115+
case JOINED -> new JoinedSubclass( superEntity, metadataBuildingContext );
1116+
case TABLE_PER_CLASS -> new UnionSubclass( superEntity, metadataBuildingContext );
1117+
};
11261118
}
11271119
}
11281120

@@ -1684,7 +1676,7 @@ private void bindRootClassCache(SharedCacheMode sharedCacheMode, MetadataBuildin
16841676
effectiveCache = buildCacheMock( annotatedClass, context );
16851677
isCached = isCacheable( sharedCacheMode, cacheable );
16861678
}
1687-
cacheConcurrentStrategy = resolveCacheConcurrencyStrategy( effectiveCache.usage() );
1679+
cacheConcurrentStrategy = getCacheConcurrencyStrategy( effectiveCache.usage() );
16881680
cacheRegion = effectiveCache.region();
16891681
cacheLazyProperty = isCacheLazy( effectiveCache, annotatedClass );
16901682

@@ -1723,11 +1715,6 @@ private static boolean isCacheable(SharedCacheMode sharedCacheMode, Cacheable ex
17231715
};
17241716
}
17251717

1726-
private static String resolveCacheConcurrencyStrategy(CacheConcurrencyStrategy strategy) {
1727-
final org.hibernate.cache.spi.access.AccessType accessType = strategy.toAccessType();
1728-
return accessType == null ? null : accessType.getExternalName();
1729-
}
1730-
17311718
private static Cache buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) {
17321719
final CacheAnnotation cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
17331720
cacheUsage.region( classDetails.getName() );

hibernate-core/src/main/java/org/hibernate/boot/model/internal/FkSecondPass.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ public int hashCode() {
5757
public abstract String getReferencedEntityName();
5858

5959
public abstract boolean isInPrimaryKey();
60-
61-
6260
}

0 commit comments

Comments
 (0)