Skip to content

Commit 8205506

Browse files
committed
deal with some warnings
1 parent 9f59f93 commit 8205506

File tree

8 files changed

+52
-63
lines changed

8 files changed

+52
-63
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.hibernate.boot.spi.MetadataBuildingContext;
3434
import org.hibernate.boot.spi.PropertyData;
3535
import org.hibernate.internal.log.DeprecationLogger;
36-
import org.hibernate.internal.util.StringHelper;
3736
import org.hibernate.internal.util.collections.ArrayHelper;
3837
import org.hibernate.mapping.Any;
3938
import org.hibernate.mapping.AttributeContainer;
@@ -882,9 +881,10 @@ static PropertyData getPropertyOverriddenByMapperOrMapsId(
882881
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getMetadataCollector()
883882
.getSourceModelBuildingContext()
884883
.getClassDetailsRegistry();
885-
final String name = StringHelper.isEmpty( propertyHolder.getPersistentClass().getClassName() )
886-
? propertyHolder.getPersistentClass().getEntityName()
887-
: propertyHolder.getPersistentClass().getClassName();
884+
final PersistentClass persistentClass = propertyHolder.getPersistentClass();
885+
final String name = isEmpty( persistentClass.getClassName() )
886+
? persistentClass.getEntityName()
887+
: persistentClass.getClassName();
888888
final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( name );
889889
final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector();
890890
if ( propertyHolder.isInIdClass() ) {

hibernate-core/src/main/java/org/hibernate/mapping/Component.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ public List<Column> getAggregatedColumns() {
242242

243243
private void collectAggregatedColumns(List<Column> aggregatedColumns, Component component) {
244244
for ( Property property : component.getProperties() ) {
245-
final Value value = property.getValue();
246-
if ( value instanceof Component ) {
247-
final Component subComponent = (Component) value;
245+
if ( property.getValue() instanceof Component subComponent ) {
248246
final AggregateColumn subAggregate = subComponent.getAggregateColumn();
249247
if ( subAggregate != null ) {
250248
aggregatedColumns.add( subAggregate );
@@ -254,7 +252,7 @@ private void collectAggregatedColumns(List<Column> aggregatedColumns, Component
254252
}
255253
}
256254
else {
257-
aggregatedColumns.addAll( value.getColumns() );
255+
aggregatedColumns.addAll( property.getValue().getColumns() );
258256
}
259257
}
260258
if ( component.isPolymorphic() ) {
@@ -267,17 +265,16 @@ private void notifyPropertiesAboutAggregateColumn(AggregateColumn aggregateColum
267265
// Let the BasicValue of every sub-column know about the aggregate,
268266
// which is needed in type resolution
269267
final Value value = property.getValue();
270-
if ( value instanceof BasicValue ) {
271-
assert ( (BasicValue) value ).getResolution() == null;
272-
( (BasicValue) value ).setAggregateColumn( aggregateColumn );
268+
if ( value instanceof BasicValue basicValue ) {
269+
assert basicValue.getResolution() == null;
270+
basicValue.setAggregateColumn( aggregateColumn );
273271
}
274-
else if ( value instanceof Component ) {
275-
final Component subComponent = (Component) value;
272+
else if ( value instanceof Component subComponent ) {
276273
if ( subComponent.getAggregateColumn() == null ) {
277274
subComponent.notifyPropertiesAboutAggregateColumn( aggregateColumn, subComponent );
278275
}
279276
else {
280-
( (Component) value ).setParentAggregateColumn( aggregateColumn );
277+
subComponent.setParentAggregateColumn( aggregateColumn );
281278
}
282279
}
283280
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.hibernate.sql.exec.spi.JdbcParametersList;
3131
import org.hibernate.sql.results.internal.RowTransformerArrayImpl;
3232

33-
import static org.hibernate.internal.util.NullnessUtil.castNonNull;
3433
import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER;
3534

3635
/**

hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinatorStandard.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public GeneratedValues coordinateInsert(
119119
SharedSessionContractImplementor session) {
120120
// apply any pre-insert in-memory value generation
121121
final boolean needsDynamicInsert = preInsertInMemoryValueGeneration( values, entity, session );
122-
123-
final EntityMetamodel entityMetamodel = entityPersister().getEntityMetamodel();
124-
final boolean forceIdentifierBinding = entityPersister().getGenerator().generatedOnExecution() && id != null;
125-
if ( entityMetamodel.isDynamicInsert() || needsDynamicInsert || forceIdentifierBinding ) {
122+
final EntityPersister persister = entityPersister();
123+
final boolean forceIdentifierBinding = persister.getGenerator().generatedOnExecution() && id != null;
124+
if ( persister.getEntityMetamodel().isDynamicInsert()
125+
|| needsDynamicInsert || forceIdentifierBinding ) {
126126
return doDynamicInserts( id, values, entity, session, forceIdentifierBinding );
127127
}
128128
else {
@@ -430,7 +430,7 @@ else if ( isValueGenerationInSql( generator, factory.getJdbcServices().getDialec
430430
if ( tableMapping.isIdentifierTable() && entityPersister().isIdentifierAssignedByInsert() && !forceIdentifierBinding ) {
431431
assert entityPersister().getInsertDelegate() != null;
432432
final OnExecutionGenerator generator = (OnExecutionGenerator) entityPersister().getGenerator();
433-
if ( generator.referenceColumnsInSql( dialect() ) ) {
433+
if ( generator.referenceColumnsInSql( dialect ) ) {
434434
final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityPersister().getIdentifierMapping();
435435
final String[] columnValues = generator.getReferencedColumnValues( dialect );
436436
tableMapping.getKeyMapping().forEachKeyColumn( (i, column) -> tableInsertBuilder.addKeyColumn(
@@ -448,8 +448,8 @@ else if ( isValueGenerationInSql( generator, factory.getJdbcServices().getDialec
448448

449449
private static boolean isValueGenerated(Generator generator) {
450450
return generator != null
451-
&& generator.generatesOnInsert()
452-
&& generator.generatedOnExecution();
451+
&& generator.generatesOnInsert()
452+
&& generator.generatedOnExecution();
453453
}
454454

455455
private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) {

hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Locale;
1010
import java.util.function.Supplier;
1111

12-
import org.hibernate.AssertionFailure;
1312
import org.hibernate.HibernateException;
1413
import org.hibernate.Internal;
1514
import org.hibernate.StaleObjectStateException;
@@ -198,7 +197,6 @@ public GeneratedValues update(
198197

199198
final boolean[] attributeUpdateability;
200199
boolean forceDynamicUpdate;
201-
202200
if ( entityPersister().getEntityMetamodel().isDynamicUpdate() && dirtyAttributeIndexes != null ) {
203201
attributeUpdateability = getPropertiesToUpdate( dirtyAttributeIndexes, hasDirtyCollection );
204202
forceDynamicUpdate = true;
@@ -372,21 +370,15 @@ private static boolean includedInLock(
372370
int position,
373371
SingularAttributeMapping attribute,
374372
EntityPersister persister) {
375-
switch ( persister.optimisticLockStyle() ) {
376-
case NONE:
377-
return false;
378-
case VERSION:
379-
return versionMapping != null
380-
&& versionMapping.getVersionAttribute() == attribute;
373+
return switch ( persister.optimisticLockStyle() ) {
374+
case NONE -> false;
375+
case VERSION -> versionMapping != null
376+
&& versionMapping.getVersionAttribute() == attribute;
381377
// && updateableAttributeIndexes[position];
382-
case ALL:
383-
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking();
384-
case DIRTY:
385-
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking()
386-
&& dirtinessChecker.include( position, attribute );
387-
default:
388-
throw new AssertionFailure( "unknown OptimisticLockStyle" );
389-
}
378+
case ALL -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking();
379+
case DIRTY -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking()
380+
&& dirtinessChecker.include( position, attribute );
381+
};
390382
}
391383

392384
protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncrement(
@@ -986,7 +978,7 @@ private MutationExecutor updateVersionExecutor(
986978
boolean dynamicUpdate,
987979
boolean batching) {
988980
if ( batching ) {
989-
return updateVersionExecutor(session, group,dynamicUpdate);
981+
return updateVersionExecutor( session, group, dynamicUpdate );
990982
}
991983
return mutationExecutorService.createExecutor( NoBatchKeyAccess.INSTANCE, group, session );
992984

@@ -1226,9 +1218,7 @@ private void applyAttributeUpdateDetails(
12261218
TableUpdateBuilder<?> tableUpdateBuilder,
12271219
SharedSessionContractImplementor session) {
12281220
final Generator generator = attributeMapping.getGenerator();
1229-
if ( isValueGenerated( generator )
1230-
&& ( session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
1231-
&& isValueGenerationInSql( generator, dialect ) ) {
1221+
if ( needsValueGeneration( entity, session, generator ) ) {
12321222
handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator );
12331223
}
12341224
else if ( versionMapping != null
@@ -1245,6 +1235,12 @@ else if ( versionMapping != null
12451235
}
12461236
}
12471237

1238+
private boolean needsValueGeneration(Object entity, SharedSessionContractImplementor session, Generator generator) {
1239+
return isValueGenerated( generator )
1240+
&& (session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
1241+
&& isValueGenerationInSql( generator, dialect );
1242+
}
1243+
12481244
/**
12491245
* Contains the aggregated analysis of the update values to determine
12501246
* what SQL UPDATE statement(s) should be used to update the entity
@@ -1606,19 +1602,19 @@ private MutationOperationGroup buildStaticUpdateGroup() {
16061602
null,
16071603
null,
16081604
null,
1609-
(index,attribute) -> isValueGenerated( attribute.getGenerator() ) && isValueGenerationInSql( attribute.getGenerator(), dialect() )
1605+
(index,attribute) ->
1606+
isValueGenerated( attribute.getGenerator() )
1607+
&& isValueGenerationInSql( attribute.getGenerator(), dialect() )
16101608
|| entityPersister().getPropertyUpdateability()[index],
1611-
(index,attribute) -> {
1612-
switch ( entityPersister().optimisticLockStyle() ) {
1613-
case ALL:
1614-
return true;
1615-
case VERSION:
1616-
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
1617-
return versionMapping != null && attribute == versionMapping.getVersionAttribute();
1618-
default:
1619-
return false;
1620-
}
1621-
},
1609+
(index,attribute) ->
1610+
switch ( entityPersister().optimisticLockStyle() ) {
1611+
case ALL -> true;
1612+
case VERSION -> {
1613+
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
1614+
yield versionMapping != null && attribute == versionMapping.getVersionAttribute();
1615+
}
1616+
default -> false;
1617+
},
16221618
(index,attribute) -> true,
16231619
"", // pass anything here to generate the row id restriction if possible
16241620
false,

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@
402402
import org.hibernate.sql.results.graph.FetchParent;
403403
import org.hibernate.sql.results.graph.Fetchable;
404404
import org.hibernate.sql.results.graph.FetchableContainer;
405-
import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch;
406405
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
407406
import org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation;
408407
import org.hibernate.sql.results.graph.internal.ImmutableFetchList;

hibernate-core/src/main/java/org/hibernate/type/MappingContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
2-
* Hibernate, Relational Persistence for Idiomatic Java
3-
*
4-
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5-
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
64
*/
75
package org.hibernate.type;
86

hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/NativeGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public void configure(GeneratorCreationContext creationContext, Properties param
6363

6464
@Override
6565
public void registerExportables(Database database) {
66-
if ( generator instanceof ExportableProducer ) {
67-
((ExportableProducer) generator).registerExportables(database);
66+
if ( generator instanceof ExportableProducer exportableProducer ) {
67+
exportableProducer.registerExportables(database);
6868
}
6969
}
7070

7171
@Override
7272
public void initialize(SqlStringGenerationContext context) {
73-
if ( generator instanceof Configurable ) {
74-
((Configurable) generator).initialize(context);
73+
if ( generator instanceof Configurable configurable ) {
74+
configurable.initialize(context);
7575
}
7676
}
7777

0 commit comments

Comments
 (0)