deal with some warnings

This commit is contained in:
Gavin King 2024-09-16 10:35:39 +02:00
parent 9f59f93b6e
commit 8205506104
8 changed files with 52 additions and 63 deletions

View File

@ -33,7 +33,6 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.PropertyData; import org.hibernate.boot.spi.PropertyData;
import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.Any; import org.hibernate.mapping.Any;
import org.hibernate.mapping.AttributeContainer; import org.hibernate.mapping.AttributeContainer;
@ -882,9 +881,10 @@ public class BinderHelper {
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getMetadataCollector() final ClassDetailsRegistry classDetailsRegistry = buildingContext.getMetadataCollector()
.getSourceModelBuildingContext() .getSourceModelBuildingContext()
.getClassDetailsRegistry(); .getClassDetailsRegistry();
final String name = StringHelper.isEmpty( propertyHolder.getPersistentClass().getClassName() ) final PersistentClass persistentClass = propertyHolder.getPersistentClass();
? propertyHolder.getPersistentClass().getEntityName() final String name = isEmpty( persistentClass.getClassName() )
: propertyHolder.getPersistentClass().getClassName(); ? persistentClass.getEntityName()
: persistentClass.getClassName();
final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( name ); final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( name );
final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector(); final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector();
if ( propertyHolder.isInIdClass() ) { if ( propertyHolder.isInIdClass() ) {

View File

@ -242,9 +242,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
private void collectAggregatedColumns(List<Column> aggregatedColumns, Component component) { private void collectAggregatedColumns(List<Column> aggregatedColumns, Component component) {
for ( Property property : component.getProperties() ) { for ( Property property : component.getProperties() ) {
final Value value = property.getValue(); if ( property.getValue() instanceof Component subComponent ) {
if ( value instanceof Component ) {
final Component subComponent = (Component) value;
final AggregateColumn subAggregate = subComponent.getAggregateColumn(); final AggregateColumn subAggregate = subComponent.getAggregateColumn();
if ( subAggregate != null ) { if ( subAggregate != null ) {
aggregatedColumns.add( subAggregate ); aggregatedColumns.add( subAggregate );
@ -254,7 +252,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
} }
} }
else { else {
aggregatedColumns.addAll( value.getColumns() ); aggregatedColumns.addAll( property.getValue().getColumns() );
} }
} }
if ( component.isPolymorphic() ) { if ( component.isPolymorphic() ) {
@ -267,17 +265,16 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
// Let the BasicValue of every sub-column know about the aggregate, // Let the BasicValue of every sub-column know about the aggregate,
// which is needed in type resolution // which is needed in type resolution
final Value value = property.getValue(); final Value value = property.getValue();
if ( value instanceof BasicValue ) { if ( value instanceof BasicValue basicValue ) {
assert ( (BasicValue) value ).getResolution() == null; assert basicValue.getResolution() == null;
( (BasicValue) value ).setAggregateColumn( aggregateColumn ); basicValue.setAggregateColumn( aggregateColumn );
} }
else if ( value instanceof Component ) { else if ( value instanceof Component subComponent ) {
final Component subComponent = (Component) value;
if ( subComponent.getAggregateColumn() == null ) { if ( subComponent.getAggregateColumn() == null ) {
subComponent.notifyPropertiesAboutAggregateColumn( aggregateColumn, subComponent ); subComponent.notifyPropertiesAboutAggregateColumn( aggregateColumn, subComponent );
} }
else { else {
( (Component) value ).setParentAggregateColumn( aggregateColumn ); subComponent.setParentAggregateColumn( aggregateColumn );
} }
} }
} }

View File

@ -30,7 +30,6 @@ import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.exec.spi.JdbcParametersList;
import org.hibernate.sql.results.internal.RowTransformerArrayImpl; import org.hibernate.sql.results.internal.RowTransformerArrayImpl;
import static org.hibernate.internal.util.NullnessUtil.castNonNull;
import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER; import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER;
/** /**

View File

@ -119,10 +119,10 @@ public class InsertCoordinatorStandard extends AbstractMutationCoordinator imple
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
// apply any pre-insert in-memory value generation // apply any pre-insert in-memory value generation
final boolean needsDynamicInsert = preInsertInMemoryValueGeneration( values, entity, session ); final boolean needsDynamicInsert = preInsertInMemoryValueGeneration( values, entity, session );
final EntityPersister persister = entityPersister();
final EntityMetamodel entityMetamodel = entityPersister().getEntityMetamodel(); final boolean forceIdentifierBinding = persister.getGenerator().generatedOnExecution() && id != null;
final boolean forceIdentifierBinding = entityPersister().getGenerator().generatedOnExecution() && id != null; if ( persister.getEntityMetamodel().isDynamicInsert()
if ( entityMetamodel.isDynamicInsert() || needsDynamicInsert || forceIdentifierBinding ) { || needsDynamicInsert || forceIdentifierBinding ) {
return doDynamicInserts( id, values, entity, session, forceIdentifierBinding ); return doDynamicInserts( id, values, entity, session, forceIdentifierBinding );
} }
else { else {
@ -430,7 +430,7 @@ public class InsertCoordinatorStandard extends AbstractMutationCoordinator imple
if ( tableMapping.isIdentifierTable() && entityPersister().isIdentifierAssignedByInsert() && !forceIdentifierBinding ) { if ( tableMapping.isIdentifierTable() && entityPersister().isIdentifierAssignedByInsert() && !forceIdentifierBinding ) {
assert entityPersister().getInsertDelegate() != null; assert entityPersister().getInsertDelegate() != null;
final OnExecutionGenerator generator = (OnExecutionGenerator) entityPersister().getGenerator(); final OnExecutionGenerator generator = (OnExecutionGenerator) entityPersister().getGenerator();
if ( generator.referenceColumnsInSql( dialect() ) ) { if ( generator.referenceColumnsInSql( dialect ) ) {
final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityPersister().getIdentifierMapping(); final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityPersister().getIdentifierMapping();
final String[] columnValues = generator.getReferencedColumnValues( dialect ); final String[] columnValues = generator.getReferencedColumnValues( dialect );
tableMapping.getKeyMapping().forEachKeyColumn( (i, column) -> tableInsertBuilder.addKeyColumn( tableMapping.getKeyMapping().forEachKeyColumn( (i, column) -> tableInsertBuilder.addKeyColumn(
@ -448,8 +448,8 @@ public class InsertCoordinatorStandard extends AbstractMutationCoordinator imple
private static boolean isValueGenerated(Generator generator) { private static boolean isValueGenerated(Generator generator) {
return generator != null return generator != null
&& generator.generatesOnInsert() && generator.generatesOnInsert()
&& generator.generatedOnExecution(); && generator.generatedOnExecution();
} }
private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) { private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) {

View File

@ -9,7 +9,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
@ -198,7 +197,6 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
final boolean[] attributeUpdateability; final boolean[] attributeUpdateability;
boolean forceDynamicUpdate; boolean forceDynamicUpdate;
if ( entityPersister().getEntityMetamodel().isDynamicUpdate() && dirtyAttributeIndexes != null ) { if ( entityPersister().getEntityMetamodel().isDynamicUpdate() && dirtyAttributeIndexes != null ) {
attributeUpdateability = getPropertiesToUpdate( dirtyAttributeIndexes, hasDirtyCollection ); attributeUpdateability = getPropertiesToUpdate( dirtyAttributeIndexes, hasDirtyCollection );
forceDynamicUpdate = true; forceDynamicUpdate = true;
@ -372,21 +370,15 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
int position, int position,
SingularAttributeMapping attribute, SingularAttributeMapping attribute,
EntityPersister persister) { EntityPersister persister) {
switch ( persister.optimisticLockStyle() ) { return switch ( persister.optimisticLockStyle() ) {
case NONE: case NONE -> false;
return false; case VERSION -> versionMapping != null
case VERSION: && versionMapping.getVersionAttribute() == attribute;
return versionMapping != null
&& versionMapping.getVersionAttribute() == attribute;
// && updateableAttributeIndexes[position]; // && updateableAttributeIndexes[position];
case ALL: case ALL -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking();
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking(); case DIRTY -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking()
case DIRTY: && dirtinessChecker.include( position, attribute );
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking() };
&& dirtinessChecker.include( position, attribute );
default:
throw new AssertionFailure( "unknown OptimisticLockStyle" );
}
} }
protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncrement( protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncrement(
@ -986,7 +978,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
boolean dynamicUpdate, boolean dynamicUpdate,
boolean batching) { boolean batching) {
if ( batching ) { if ( batching ) {
return updateVersionExecutor(session, group,dynamicUpdate); return updateVersionExecutor( session, group, dynamicUpdate );
} }
return mutationExecutorService.createExecutor( NoBatchKeyAccess.INSTANCE, group, session ); return mutationExecutorService.createExecutor( NoBatchKeyAccess.INSTANCE, group, session );
@ -1226,9 +1218,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
TableUpdateBuilder<?> tableUpdateBuilder, TableUpdateBuilder<?> tableUpdateBuilder,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
final Generator generator = attributeMapping.getGenerator(); final Generator generator = attributeMapping.getGenerator();
if ( isValueGenerated( generator ) if ( needsValueGeneration( entity, session, generator ) ) {
&& ( session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
&& isValueGenerationInSql( generator, dialect ) ) {
handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator ); handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator );
} }
else if ( versionMapping != null else if ( versionMapping != null
@ -1245,6 +1235,12 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
} }
} }
private boolean needsValueGeneration(Object entity, SharedSessionContractImplementor session, Generator generator) {
return isValueGenerated( generator )
&& (session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
&& isValueGenerationInSql( generator, dialect );
}
/** /**
* Contains the aggregated analysis of the update values to determine * Contains the aggregated analysis of the update values to determine
* what SQL UPDATE statement(s) should be used to update the entity * what SQL UPDATE statement(s) should be used to update the entity
@ -1606,19 +1602,19 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
null, null,
null, null,
null, null,
(index,attribute) -> isValueGenerated( attribute.getGenerator() ) && isValueGenerationInSql( attribute.getGenerator(), dialect() ) (index,attribute) ->
isValueGenerated( attribute.getGenerator() )
&& isValueGenerationInSql( attribute.getGenerator(), dialect() )
|| entityPersister().getPropertyUpdateability()[index], || entityPersister().getPropertyUpdateability()[index],
(index,attribute) -> { (index,attribute) ->
switch ( entityPersister().optimisticLockStyle() ) { switch ( entityPersister().optimisticLockStyle() ) {
case ALL: case ALL -> true;
return true; case VERSION -> {
case VERSION: final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping(); yield versionMapping != null && attribute == versionMapping.getVersionAttribute();
return versionMapping != null && attribute == versionMapping.getVersionAttribute(); }
default: default -> false;
return false; },
}
},
(index,attribute) -> true, (index,attribute) -> true,
"", // pass anything here to generate the row id restriction if possible "", // pass anything here to generate the row id restriction if possible
false, false,

View File

@ -402,7 +402,6 @@ import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.FetchableContainer; import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch;
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode; import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
import org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation; import org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation;
import org.hibernate.sql.results.graph.internal.ImmutableFetchList; import org.hibernate.sql.results.graph.internal.ImmutableFetchList;

View File

@ -1,8 +1,6 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * SPDX-License-Identifier: LGPL-2.1-or-later
* * Copyright Red Hat Inc. and Hibernate Authors
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.type; package org.hibernate.type;

View File

@ -63,15 +63,15 @@ public class NativeGenerator
@Override @Override
public void registerExportables(Database database) { public void registerExportables(Database database) {
if ( generator instanceof ExportableProducer ) { if ( generator instanceof ExportableProducer exportableProducer ) {
((ExportableProducer) generator).registerExportables(database); exportableProducer.registerExportables(database);
} }
} }
@Override @Override
public void initialize(SqlStringGenerationContext context) { public void initialize(SqlStringGenerationContext context) {
if ( generator instanceof Configurable ) { if ( generator instanceof Configurable configurable ) {
((Configurable) generator).initialize(context); configurable.initialize(context);
} }
} }