Skip to content

Commit 6da6276

Browse files
committed
squash more warnings
1 parent 8b83a53 commit 6da6276

20 files changed

+120
-151
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.hibernate.type.OneToOneType;
3737
import org.hibernate.type.Type;
3838

39+
import static java.util.Collections.EMPTY_LIST;
3940
import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy;
4041
import static org.hibernate.engine.spi.CascadingActions.CHECK_ON_FLUSH;
4142
import static org.hibernate.pretty.MessageHelper.infoString;
@@ -89,7 +90,8 @@ public static <T> void cascade(
8990
LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() );
9091
}
9192
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
92-
final boolean enhancedForLazyLoading = persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();
93+
final boolean enhancedForLazyLoading =
94+
persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();
9395
final EntityEntry entry;
9496
if ( enhancedForLazyLoading ) {
9597
entry = persistenceContext.getEntry( parent );
@@ -112,8 +114,9 @@ public static <T> void cascade(
112114
final String propertyName = propertyNames[ i ];
113115
final Type type = types[i];
114116
final boolean isUninitializedProperty =
115-
hasUninitializedLazyProperties &&
116-
!persister.getBytecodeEnhancementMetadata().isAttributeLoaded( parent, propertyName );
117+
hasUninitializedLazyProperties
118+
&& !persister.getBytecodeEnhancementMetadata()
119+
.isAttributeLoaded( parent, propertyName );
117120

118121
if ( style.doCascade( action ) ) {
119122
final Object child;
@@ -129,14 +132,13 @@ public static <T> void cascade(
129132
// parent was not in the PersistenceContext
130133
continue;
131134
}
132-
if ( type instanceof CollectionType ) {
135+
if ( type instanceof CollectionType collectionType ) {
133136
// CollectionType#getCollection gets the PersistentCollection
134137
// that corresponds to the uninitialized collection from the
135138
// PersistenceContext. If not present, an uninitialized
136139
// PersistentCollection will be added to the PersistenceContext.
137140
// The action may initialize it later, if necessary.
138141
// This needs to be done even when action.performOnLazyProperty() returns false.
139-
final CollectionType collectionType = (CollectionType) type;
140142
child = collectionType.getCollection(
141143
collectionType.getKeyOfOwner( parent, eventSource ),
142144
eventSource,
@@ -146,15 +148,14 @@ public static <T> void cascade(
146148
}
147149
else if ( type instanceof AnyType || type instanceof ComponentType ) {
148150
// Hibernate does not support lazy embeddables, so this shouldn't happen.
149-
throw new UnsupportedOperationException(
150-
"Lazy components are not supported."
151-
);
151+
throw new UnsupportedOperationException( "Lazy embeddables are not supported" );
152152
}
153153
else if ( action.performOnLazyProperty() && type instanceof EntityType ) {
154154
// Only need to initialize a lazy entity attribute when action.performOnLazyProperty()
155155
// returns true.
156-
LazyAttributeLoadingInterceptor interceptor = persister.getBytecodeEnhancementMetadata()
157-
.extractInterceptor( parent );
156+
final LazyAttributeLoadingInterceptor interceptor =
157+
persister.getBytecodeEnhancementMetadata()
158+
.extractInterceptor( parent );
158159
child = interceptor.fetchAttribute( parent, propertyName );
159160

160161
}
@@ -238,10 +239,10 @@ private static <T> void cascadeProperty(
238239
style,
239240
anything,
240241
isCascadeDeleteEnabled
241-
);
242+
);
242243
}
243244
}
244-
else if ( type instanceof ComponentType ) {
245+
else if ( type instanceof ComponentType componentType ) {
245246
if ( componentPath == null && propertyName != null ) {
246247
componentPath = new ArrayList<>();
247248
}
@@ -255,7 +256,7 @@ else if ( type instanceof ComponentType ) {
255256
componentPath,
256257
parent,
257258
child,
258-
(CompositeType) type,
259+
componentType,
259260
anything
260261
);
261262
if ( componentPath != null ) {
@@ -273,7 +274,8 @@ else if ( type instanceof ComponentType ) {
273274
type,
274275
style,
275276
propertyName,
276-
isCascadeDeleteEnabled );
277+
isCascadeDeleteEnabled
278+
);
277279
}
278280
}
279281

@@ -376,8 +378,8 @@ private static <T> void cascadeLogicalOneToOneOrphanRemoval(
376378

377379
private static boolean isForeignKeyToParent(Type type) {
378380
return type instanceof CollectionType
379-
|| type instanceof OneToOneType
380-
&& ((OneToOneType) type).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT;
381+
|| type instanceof OneToOneType oneToOneType
382+
&& oneToOneType.getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT;
381383
}
382384

383385
/**
@@ -389,7 +391,7 @@ private static boolean isForeignKeyToParent(Type type) {
389391
* @return True if the attribute represents a logical one to one association
390392
*/
391393
private static boolean isLogicalOneToOne(Type type) {
392-
return type instanceof EntityType && ( (EntityType) type ).isLogicalOneToOne();
394+
return type instanceof EntityType entityType && entityType.isLogicalOneToOne();
393395
}
394396

395397
private static boolean cascadeAssociationNow(
@@ -399,24 +401,22 @@ private static boolean cascadeAssociationNow(
399401
SessionFactoryImplementor factory,
400402
boolean unownedTransient) {
401403
return associationType.getForeignKeyDirection().cascadeNow( cascadePoint )
402-
// For check on flush, we should only check unowned associations when strictness is enforced
403-
&& ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) );
404+
// For check on flush, we should only check unowned associations when strictness is enforced
405+
&& ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) );
404406
}
405407

406408
private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) {
407-
if ( associationType instanceof ManyToOneType ) {
408-
final ManyToOneType manyToOne = (ManyToOneType) associationType;
409+
if ( associationType instanceof ManyToOneType manyToOne ) {
409410
// logical one-to-one + non-null unique key property name indicates unowned
410411
return manyToOne.isLogicalOneToOne() && manyToOne.getRHSUniqueKeyPropertyName() != null;
411412
}
412-
else if ( associationType instanceof OneToOneType ) {
413-
final OneToOneType oneToOne = (OneToOneType) associationType;
413+
else if ( associationType instanceof OneToOneType oneToOne ) {
414414
// constrained false + non-null unique key property name indicates unowned
415415
return oneToOne.isNullable() && oneToOne.getRHSUniqueKeyPropertyName() != null;
416416
}
417-
else if ( associationType instanceof CollectionType ) {
417+
else if ( associationType instanceof CollectionType collectionType ) {
418418
// for collections, we can ask the persister if we're on the inverse side
419-
return ( (CollectionType) associationType ).isInverse( factory );
419+
return collectionType.isInverse( factory );
420420
}
421421
return false;
422422
}
@@ -454,7 +454,7 @@ private static <T> void cascadeComponent(
454454
subPropertyName,
455455
anything,
456456
false
457-
);
457+
);
458458
}
459459
}
460460
}
@@ -473,7 +473,7 @@ private static <T> void cascadeAssociation(
473473
if ( type instanceof EntityType || type instanceof AnyType ) {
474474
cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled );
475475
}
476-
else if ( type instanceof CollectionType ) {
476+
else if ( type instanceof CollectionType collectionType ) {
477477
cascadeCollection(
478478
action,
479479
cascadePoint,
@@ -483,7 +483,7 @@ else if ( type instanceof CollectionType ) {
483483
child,
484484
style,
485485
anything,
486-
(CollectionType) type
486+
collectionType
487487
);
488488
}
489489
}
@@ -505,17 +505,13 @@ private static <T> void cascadeCollection(
505505
eventSource.getFactory().getMappingMetamodel()
506506
.getCollectionDescriptor( type.getRole() );
507507
final Type elemType = persister.getElementType();
508-
509-
CascadePoint elementsCascadePoint = cascadePoint;
510-
if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE ) {
511-
elementsCascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
512-
}
513-
514508
//cascade to current collection elements
515509
if ( elemType instanceof EntityType || elemType instanceof AnyType || elemType instanceof ComponentType ) {
516510
cascadeCollectionElements(
517511
action,
518-
elementsCascadePoint,
512+
cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE
513+
? CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION
514+
: cascadePoint,
519515
eventSource,
520516
componentPath,
521517
parent,
@@ -541,9 +537,10 @@ private static <T> void cascadeToOne(
541537
final CascadeStyle style,
542538
final T anything,
543539
final boolean isCascadeDeleteEnabled) {
544-
final String entityName = type instanceof EntityType
545-
? ( (EntityType) type ).getAssociatedEntityName()
546-
: null;
540+
final String entityName =
541+
type instanceof EntityType entityType
542+
? entityType.getAssociatedEntityName()
543+
: null;
547544
if ( style.reallyDoCascade( action ) ) {
548545
//not really necessary, but good for consistency...
549546
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
@@ -572,6 +569,7 @@ private static <T> void cascadeCollectionElements(
572569
final Type elemType,
573570
final T anything,
574571
final boolean isCascadeDeleteEnabled) throws HibernateException {
572+
575573
final boolean reallyDoCascade = style.reallyDoCascade( action )
576574
&& child != CollectionType.UNFETCHED_COLLECTION;
577575

@@ -581,15 +579,15 @@ private static <T> void cascadeCollectionElements(
581579
LOG.tracev( "Cascade {0} for collection: {1}", action, collectionType.getRole() );
582580
}
583581

584-
final Iterator<?> itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
585-
while ( itr.hasNext() ) {
582+
final Iterator<?> iterator = action.getCascadableChildrenIterator( eventSource, collectionType, child );
583+
while ( iterator.hasNext() ) {
586584
cascadeProperty(
587585
action,
588586
cascadePoint,
589587
eventSource,
590588
componentPath,
591589
parent,
592-
itr.next(),
590+
iterator.next(),
593591
elemType,
594592
style,
595593
collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ),
@@ -606,9 +604,9 @@ private static <T> void cascadeCollectionElements(
606604
final boolean deleteOrphans = style.hasOrphanDelete()
607605
&& action.deleteOrphans()
608606
&& elemType instanceof EntityType
609-
&& child instanceof PersistentCollection
607+
&& child instanceof PersistentCollection<?> persistentCollection
610608
// a newly instantiated collection can't have orphans
611-
&& ! ( (PersistentCollection<?>) child ).isNewlyInstantiated();
609+
&& !persistentCollection.isNewlyInstantiated();
612610

613611
if ( deleteOrphans ) {
614612
final boolean traceEnabled = LOG.isTraceEnabled();
@@ -634,10 +632,8 @@ private static void deleteOrphans(EventSource eventSource, String entityName, Pe
634632
//TODO: suck this logic into the collection!
635633
final Collection<?> orphans;
636634
if ( pc.wasInitialized() ) {
637-
final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry( pc );
638-
orphans = ce==null
639-
? java.util.Collections.EMPTY_LIST
640-
: ce.getOrphans( entityName, pc );
635+
final CollectionEntry entry = eventSource.getPersistenceContextInternal().getCollectionEntry( pc );
636+
orphans = entry == null ? EMPTY_LIST : entry.getOrphans( entityName, pc );
641637
}
642638
else {
643639
orphans = pc.getQueuedOrphans( entityName );

hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,7 @@ private void addDirectDependency(Type type, @Nullable Object value, IdentityHash
11671167
if ( value == null ) {
11681168
return;
11691169
}
1170-
if ( type instanceof EntityType ) {
1171-
final EntityType entityType = (EntityType) type;
1170+
if ( type instanceof EntityType entityType ) {
11721171
final InsertInfo insertInfo = insertInfosByEntity.get( value );
11731172
if ( insertInfo != null ) {
11741173
if ( entityType.isOneToOne()
@@ -1188,8 +1187,7 @@ private void addDirectDependency(Type type, @Nullable Object value, IdentityHash
11881187
}
11891188
}
11901189
}
1191-
else if ( type instanceof CollectionType ) {
1192-
CollectionType collectionType = (CollectionType) type;
1190+
else if ( type instanceof CollectionType collectionType ) {
11931191
final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession()
11941192
.getFactory()
11951193
.getMappingMetamodel()
@@ -1212,9 +1210,8 @@ else if ( type instanceof CollectionType ) {
12121210
}
12131211
}
12141212
}
1215-
else if ( type instanceof ComponentType ) {
1213+
else if ( type instanceof ComponentType compositeType ) {
12161214
// Support recursive checks of composite type properties for associations and collections.
1217-
ComponentType compositeType = (ComponentType) type;
12181215
final SharedSessionContractImplementor session = insertAction.getSession();
12191216
final Object[] componentValues = compositeType.getPropertyValues( value, session );
12201217
for ( int j = 0; j < componentValues.length; ++j ) {

hibernate-core/src/main/java/org/hibernate/engine/spi/CascadeStyle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface CascadeStyle extends Serializable {
2222
*
2323
* @return True if the action should be cascaded under this style; false otherwise.
2424
*/
25-
boolean doCascade(CascadingAction action);
25+
boolean doCascade(CascadingAction<?> action);
2626

2727
/**
2828
* Probably more aptly named something like doCascadeToCollectionElements(); it is
@@ -38,7 +38,7 @@ public interface CascadeStyle extends Serializable {
3838
* @return True if the action should be really cascaded under this style;
3939
* false otherwise.
4040
*/
41-
boolean reallyDoCascade(CascadingAction action);
41+
boolean reallyDoCascade(CascadingAction<?> action);
4242

4343
/**
4444
* Do we need to delete orphaned collection elements?

0 commit comments

Comments
 (0)