Get rid of StateArrayContributor

This commit is contained in:
Christian Beikov 2022-03-08 23:10:27 +01:00
parent af9edd50d6
commit 34b4e873df
29 changed files with 103 additions and 180 deletions

View File

@ -143,17 +143,19 @@ class DatabaseSnapshotExecutor {
);
entityDescriptor.visitStateArrayContributors( (contributorMapping) -> {
final NavigablePath navigablePath = rootPath.append( contributorMapping.getAttributeName() );
domainResults.add(
contributorMapping.createSnapshotDomainResult(
navigablePath,
rootTableGroup,
null,
state
)
);
} );
entityDescriptor.visitAttributeMappings(
attributeMapping -> {
final NavigablePath navigablePath = rootPath.append( attributeMapping.getAttributeName() );
domainResults.add(
attributeMapping.createSnapshotDomainResult(
navigablePath,
rootTableGroup,
null,
state
)
);
}
);
final SelectStatement selectStatement = new SelectStatement( rootQuerySpec, domainResults );

View File

@ -30,6 +30,11 @@ public interface AttributeMapping
return getAttributeName();
}
/**
* The attribute's position within the container's state array
*/
int getStateArrayPosition();
/**
* Access to AttributeMetadata
*/

View File

@ -319,7 +319,7 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel
// todo (6.0) : getNumberOfAttributeMappings() needs to be fixed for this to work - bad walking of hierarchy
final Object[] values = new Object[ getNumberOfAttributeMappings() ];
visitStateArrayContributors(
visitAttributeMappings(
attribute -> {
final DomainResultAssembler assembler = assemblerMapping.get( attribute );
final Object value;
@ -337,14 +337,6 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel
return values;
}
@Override
default void visitStateArrayContributors(Consumer<StateArrayContributorMapping> mappingConsumer) {
visitAttributeMappings(
attributeMapping -> mappingConsumer.accept( (StateArrayContributorMapping) attributeMapping )
);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -75,18 +75,4 @@ public interface ManagedMappingType extends MappingType, FetchableContainer {
default void setValue(Object instance, int position, Object value) {
getAttributeMapping( position ).setValue( instance, value );
}
/**
* @todo (6.0) : consider dropping this in favor of a form passing the ManagedMappingType
* which indicates the type to limit the attribute search to (the type and its super-type)
*/
default void visitStateArrayContributors(Consumer<StateArrayContributorMapping> mappingConsumer) {
visitAttributeMappings(
modelPart -> {
if ( modelPart instanceof StateArrayContributorMapping ) {
mappingConsumer.accept( ( (StateArrayContributorMapping) modelPart ) );
}
}
);
}
}

View File

@ -32,7 +32,7 @@ import org.hibernate.sql.results.graph.basic.BasicResult;
* @author Steve Ebersole
*/
public interface PluralAttributeMapping
extends AttributeMapping, StateArrayContributorMapping, TableGroupJoinProducer, FetchableContainer, Loadable, Restrictable {
extends AttributeMapping, TableGroupJoinProducer, FetchableContainer, Loadable, Restrictable {
CollectionPersister getCollectionDescriptor();

View File

@ -11,5 +11,5 @@ package org.hibernate.metamodel.mapping;
*
* @author Steve Ebersole
*/
public interface SingularAttributeMapping extends AttributeMapping, StateArrayContributorMapping {
public interface SingularAttributeMapping extends AttributeMapping {
}

View File

@ -1,26 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.metamodel.mapping;
import org.hibernate.sql.results.graph.Fetchable;
/**
* Describes a model-part which contributes state to the array of values
* for a container it is part of. For example, an attribute contributes
* a value to the state array for its declarer
*
* @author Steve Ebersole
*/
public interface StateArrayContributorMapping extends AttributeMapping, Fetchable {
/**
* The attribute's position within the container's state array
*/
int getStateArrayPosition();
@Override
StateArrayContributorMetadataAccess getAttributeMetadataAccess();
}

View File

@ -1,13 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.metamodel.mapping;
/**
* @author Steve Ebersole
*/
public interface StateArrayContributorMetadata extends AttributeMetadata {
}

View File

@ -1,15 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.metamodel.mapping;
/**
* @author Steve Ebersole
*/
public interface StateArrayContributorMetadataAccess extends AttributeMetadataAccess {
@Override
StateArrayContributorMetadata resolveAttributeMetadata(EntityMappingType entityMappingType);
}

View File

@ -27,9 +27,9 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -270,7 +270,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
mutabilityPlan = ImmutableMutabilityPlan.INSTANCE;
}
final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() {
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;

View File

@ -8,9 +8,9 @@ package org.hibernate.metamodel.mapping.internal;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.sql.results.graph.FetchOptions;
import org.hibernate.tuple.ValueGeneration;
@ -28,7 +28,7 @@ public abstract class AbstractSingularAttributeMapping
public AbstractSingularAttributeMapping(
String name,
int stateArrayPosition,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchOptions mappedFetchOptions,
ManagedMappingType declaringType,
PropertyAccess propertyAccess,
@ -43,7 +43,7 @@ public abstract class AbstractSingularAttributeMapping
public AbstractSingularAttributeMapping(
String name,
int stateArrayPosition,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchTiming fetchTiming,
FetchStyle fetchStyle,
ManagedMappingType declaringType,

View File

@ -8,9 +8,8 @@ package org.hibernate.metamodel.mapping.internal;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.StateArrayContributorMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.sql.results.graph.FetchOptions;
/**
@ -18,9 +17,9 @@ import org.hibernate.sql.results.graph.FetchOptions;
*/
public abstract class AbstractStateArrayContributorMapping
extends AbstractAttributeMapping
implements StateArrayContributorMapping, FetchOptions {
implements FetchOptions {
private final StateArrayContributorMetadataAccess attributeMetadataAccess;
private final AttributeMetadataAccess attributeMetadataAccess;
private final FetchTiming fetchTiming;
private final FetchStyle fetchStyle;
private final int stateArrayPosition;
@ -28,7 +27,7 @@ public abstract class AbstractStateArrayContributorMapping
public AbstractStateArrayContributorMapping(
String name,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchTiming fetchTiming,
FetchStyle fetchStyle,
int stateArrayPosition,
@ -42,7 +41,7 @@ public abstract class AbstractStateArrayContributorMapping
public AbstractStateArrayContributorMapping(
String name,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchOptions mappedFetchOptions,
int stateArrayPosition,
ManagedMappingType declaringType) {
@ -62,7 +61,7 @@ public abstract class AbstractStateArrayContributorMapping
}
@Override
public StateArrayContributorMetadataAccess getAttributeMetadataAccess() {
public AttributeMetadataAccess getAttributeMetadataAccess() {
return attributeMetadataAccess;
}

View File

@ -12,6 +12,7 @@ import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.ConvertibleModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
@ -21,7 +22,6 @@ import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.property.access.spi.PropertyAccess;
@ -70,7 +70,7 @@ public class BasicAttributeMapping
String attributeName,
NavigableRole navigableRole,
int stateArrayPosition,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
String tableExpression,
@ -133,7 +133,7 @@ public class BasicAttributeMapping
SelectableMapping selectableMapping) {
String attributeName = null;
int stateArrayPosition = 0;
StateArrayContributorMetadataAccess attributeMetadataAccess = null;
AttributeMetadataAccess attributeMetadataAccess = null;
BasicValueConverter<?, ?> valueConverter = null;
if ( original instanceof SingleAttributeIdentifierMapping ) {
final SingleAttributeIdentifierMapping mapping = (SingleAttributeIdentifierMapping) original;

View File

@ -25,6 +25,7 @@ import org.hibernate.loader.ast.spi.MultiNaturalIdLoader;
import org.hibernate.loader.ast.spi.NaturalIdLoader;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingType;
@ -32,7 +33,6 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.NavigablePath;
import org.hibernate.sql.ast.Clause;
@ -96,7 +96,7 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
MappingModelCreationProcess creationProcess) {
for ( int i = 0; i < attributes.size(); i++ ) {
final SingularAttributeMapping attributeMapping = attributes.get( i );
final StateArrayContributorMetadataAccess metadataAccess = attributeMapping.getAttributeMetadataAccess();
final AttributeMetadataAccess metadataAccess = attributeMapping.getAttributeMetadataAccess();
if ( ! metadataAccess.resolveAttributeMetadata( entityDescriptor ).isUpdatable() ) {
return false;

View File

@ -18,6 +18,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
@ -27,7 +28,6 @@ import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.spi.NavigablePath;
@ -70,7 +70,7 @@ public class DiscriminatedAssociationAttributeMapping
JavaType<?> baseAssociationJtd,
ManagedMappingType declaringType,
int stateArrayPosition,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchTiming fetchTiming,
PropertyAccess propertyAccess,
Property bootProperty,

View File

@ -35,6 +35,8 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
@ -46,8 +48,6 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -418,7 +418,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
mutabilityPlan = ImmutableMutabilityPlan.INSTANCE;
}
final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() {
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;

View File

@ -15,6 +15,7 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
@ -23,7 +24,6 @@ import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
import org.hibernate.property.access.spi.PropertyAccess;
@ -73,7 +73,7 @@ public class EmbeddedAttributeMapping
NavigableRole navigableRole,
int stateArrayPosition,
String tableExpression,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
String parentInjectionAttributeName,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
@ -102,7 +102,7 @@ public class EmbeddedAttributeMapping
NavigableRole navigableRole,
int stateArrayPosition,
String tableExpression,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
PropertyAccess parentInjectionAttributePropertyAccess,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,

View File

@ -18,10 +18,10 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.GeneratedValueResolver;
import org.hibernate.metamodel.mapping.InDatabaseGeneratedValueResolver;
import org.hibernate.metamodel.mapping.StateArrayContributorMapping;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
@ -59,18 +59,13 @@ public class GeneratedValuesProcessor {
// NOTE: we only care about db-generated values here. in-memory generation
// is applied before the insert/update happens.
final List<StateArrayContributorMapping> generatedValuesToSelect = new ArrayList<>();
final List<AttributeMapping> generatedValuesToSelect = new ArrayList<>();
// todo (6.0): for now, we rely on the entity metamodel as composite attributes report GenerationTiming.NEVER
// even if they have attributes that would need generation
final InDatabaseValueGenerationStrategy[] inDatabaseValueGenerationStrategies = entityDescriptor.getEntityPersister()
.getEntityMetamodel()
.getInDatabaseValueGenerationStrategies();
entityDescriptor.visitAttributeMappings( (attr) -> {
//noinspection RedundantClassCall
if ( ! StateArrayContributorMapping.class.isInstance( attr ) ) {
return;
}
final StateArrayContributorMapping mapping = (StateArrayContributorMapping) attr;
entityDescriptor.visitAttributeMappings( mapping -> {
final InDatabaseValueGenerationStrategy inDatabaseValueGenerationStrategy = inDatabaseValueGenerationStrategies[mapping.getStateArrayPosition()];
if ( inDatabaseValueGenerationStrategy.getGenerationTiming() == GenerationTiming.NEVER ) {
return;
@ -191,9 +186,9 @@ public class GeneratedValuesProcessor {
private static class GeneratedValueDescriptor {
public final GeneratedValueResolver resolver;
public final StateArrayContributorMapping attribute;
public final AttributeMapping attribute;
public GeneratedValueDescriptor(GeneratedValueResolver resolver, StateArrayContributorMapping attribute) {
public GeneratedValueDescriptor(GeneratedValueResolver resolver, AttributeMapping attribute) {
this.resolver = resolver;
this.attribute = attribute;
}

View File

@ -20,6 +20,7 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.RootClass;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
@ -33,7 +34,6 @@ import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy;
import org.hibernate.persister.entity.EntityPersister;
@ -52,7 +52,7 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.spi.CompositeTypeImplementor;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.getStateArrayContributorMetadataAccess;
import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.getAttributeMetadataAccess;
/**
* EmbeddableMappingType implementation describing an {@link jakarta.persistence.IdClass}
@ -96,7 +96,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
null,
EntityIdentifierMapping.ROLE_LOCAL_NAME,
true );
final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess(
final AttributeMetadataAccess attributeMetadataAccess = getAttributeMetadataAccess(
propertyAccess
);

View File

@ -50,6 +50,8 @@ import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor;
import org.hibernate.metamodel.mapping.CollectionMappingType;
@ -68,8 +70,6 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.PropertyBasedMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.mapping.VirtualModelPart;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.metamodel.model.domain.NavigableRole;
@ -190,7 +190,7 @@ public class MappingModelCreationHelper {
final BasicValueConverter<?,?> valueConverter = resolution.getValueConverter();
final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() {
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan();
private final boolean nullable = value.isNullable();
private final boolean insertable = bootProperty.isInsertable();
@ -337,7 +337,7 @@ public class MappingModelCreationHelper {
PropertyAccess propertyAccess,
CascadeStyle cascadeStyle,
MappingModelCreationProcess creationProcess) {
final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess(
final AttributeMetadataAccess attributeMetadataAccess = getAttributeMetadataAccess(
bootProperty,
attrType,
propertyAccess,
@ -392,13 +392,13 @@ public class MappingModelCreationHelper {
}
@SuppressWarnings("rawtypes")
protected static StateArrayContributorMetadataAccess getStateArrayContributorMetadataAccess(
protected static AttributeMetadataAccess getAttributeMetadataAccess(
Property bootProperty,
Type attrType,
PropertyAccess propertyAccess,
CascadeStyle cascadeStyle,
MappingModelCreationProcess creationProcess) {
return entityMappingType -> new StateArrayContributorMetadata() {
return entityMappingType -> new AttributeMetadata() {
private final boolean nullable = bootProperty.getValue().isNullable();
private final boolean insertable = bootProperty.isInsertable();
private final boolean updateable = bootProperty.isUpdateable();
@ -483,9 +483,9 @@ public class MappingModelCreationHelper {
}
@SuppressWarnings("rawtypes")
public static StateArrayContributorMetadataAccess getStateArrayContributorMetadataAccess(PropertyAccess propertyAccess) {
return new StateArrayContributorMetadataAccess() {
final StateArrayContributorMetadata contributorMetadata = new StateArrayContributorMetadata() {
public static AttributeMetadataAccess getAttributeMetadataAccess(PropertyAccess propertyAccess) {
return new AttributeMetadataAccess() {
final AttributeMetadata attributeMetadata = new AttributeMetadata() {
private final MutabilityPlan mutabilityPlan = ImmutableMutabilityPlan.INSTANCE;
@Override
@ -533,8 +533,8 @@ public class MappingModelCreationHelper {
};
@Override
public StateArrayContributorMetadata resolveAttributeMetadata(EntityMappingType entityMappingType) {
return contributorMetadata;
public AttributeMetadata resolveAttributeMetadata(EntityMappingType entityMappingType) {
return attributeMetadata;
}
};
}
@ -717,7 +717,7 @@ public class MappingModelCreationHelper {
}
}
final StateArrayContributorMetadata contributorMetadata = new StateArrayContributorMetadata() {
final AttributeMetadata attributeMetadata = new AttributeMetadata() {
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
@ -777,7 +777,7 @@ public class MappingModelCreationHelper {
attrName,
bootValueMapping,
propertyAccess,
entityMappingType -> contributorMetadata,
entityMappingType -> attributeMetadata,
collectionMappingType,
stateArrayPosition,
elementDescriptor,
@ -1597,7 +1597,7 @@ public class MappingModelCreationHelper {
if ( bootProperty.getValue() instanceof ToOne ) {
final ToOne value = (ToOne) bootProperty.getValue();
final EntityPersister entityPersister = creationProcess.getEntityPersister( value.getReferencedEntityName() );
final StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess = getStateArrayContributorMetadataAccess(
final AttributeMetadataAccess attributeMetadataAccess = getAttributeMetadataAccess(
bootProperty,
attrType,
propertyAccess,
@ -1642,7 +1642,7 @@ public class MappingModelCreationHelper {
navigableRole,
stateArrayPosition,
(ToOne) bootProperty.getValue(),
stateArrayContributorMetadataAccess,
attributeMetadataAccess,
fetchTiming,
fetchStyle,
entityPersister,

View File

@ -22,6 +22,7 @@ import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.List;
import org.hibernate.mapping.Map;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor;
import org.hibernate.metamodel.mapping.CollectionMappingType;
import org.hibernate.metamodel.mapping.CollectionPart;
@ -32,7 +33,6 @@ import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.Queryable;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.mapping.ordering.OrderByFragment;
import org.hibernate.metamodel.mapping.ordering.OrderByFragmentTranslator;
import org.hibernate.metamodel.mapping.ordering.TranslationContext;
@ -88,7 +88,7 @@ public class PluralAttributeMappingImpl
private final CollectionMappingType collectionMappingType;
private final int stateArrayPosition;
private final PropertyAccess propertyAccess;
private final StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess;
private final AttributeMetadataAccess attributeMetadataAccess;
private final String referencedPropertyName;
private final String mapKeyPropertyName;
@ -116,7 +116,7 @@ public class PluralAttributeMappingImpl
String attributeName,
Collection bootDescriptor,
PropertyAccess propertyAccess,
StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
CollectionMappingType<?> collectionMappingType,
int stateArrayPosition,
CollectionPart elementDescriptor,
@ -129,7 +129,7 @@ public class PluralAttributeMappingImpl
CollectionPersister collectionDescriptor) {
super( attributeName, declaringType );
this.propertyAccess = propertyAccess;
this.stateArrayContributorMetadataAccess = stateArrayContributorMetadataAccess;
this.attributeMetadataAccess = attributeMetadataAccess;
this.collectionMappingType = collectionMappingType;
this.stateArrayPosition = stateArrayPosition;
this.elementDescriptor = elementDescriptor;
@ -315,8 +315,8 @@ public class PluralAttributeMappingImpl
}
@Override
public StateArrayContributorMetadataAccess getAttributeMetadataAccess() {
return stateArrayContributorMetadataAccess;
public AttributeMetadataAccess getAttributeMetadataAccess() {
return attributeMetadataAccess;
}
@Override

View File

@ -34,6 +34,7 @@ import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.mapping.AssociationKey;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.CollectionPart;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityAssociationMapping;
@ -46,7 +47,6 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.ModelPartContainer;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.mapping.VirtualModelPart;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.persister.collection.QueryableCollection;
@ -161,7 +161,7 @@ public class ToOneAttributeMapping
NavigableRole navigableRole,
int stateArrayPosition,
ToOne bootValue,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchOptions mappedFetchOptions,
EntityMappingType entityMappingType,
ManagedMappingType declaringType,
@ -187,7 +187,7 @@ public class ToOneAttributeMapping
NavigableRole navigableRole,
int stateArrayPosition,
ToOne bootValue,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
EntityMappingType entityMappingType,

View File

@ -9,11 +9,11 @@ package org.hibernate.metamodel.mapping.internal;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.mapping.VirtualModelPart;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.property.access.spi.PropertyAccess;
@ -30,7 +30,7 @@ public class VirtualEmbeddedAttributeMapping extends EmbeddedAttributeMapping im
NavigableRole navigableRole,
int stateArrayPosition,
String tableExpression,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
String parentInjectionAttributeName,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
@ -58,7 +58,7 @@ public class VirtualEmbeddedAttributeMapping extends EmbeddedAttributeMapping im
NavigableRole navigableRole,
int stateArrayPosition,
String tableExpression,
StateArrayContributorMetadataAccess attributeMetadataAccess,
AttributeMetadataAccess attributeMetadataAccess,
PropertyAccess parentInjectionAttributePropertyAccess,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,

View File

@ -173,8 +173,6 @@ import org.hibernate.metamodel.mapping.Queryable;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.VirtualModelPart;
import org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl;
import org.hibernate.metamodel.mapping.internal.CompoundNaturalIdMapping;
@ -1866,8 +1864,8 @@ public abstract class AbstractEntityPersister
}
FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming();
final boolean selectable;
if ( fetchable instanceof StateArrayContributorMapping ) {
final int propertyNumber = ( (StateArrayContributorMapping) fetchable ).getStateArrayPosition();
if ( fetchable instanceof AttributeMapping ) {
final int propertyNumber = ( (AttributeMapping) fetchable ).getStateArrayPosition();
final int tableNumber = getSubclassPropertyTableNumber( propertyNumber );
selectable = !isSubclassTableSequentialSelect( tableNumber )
&& propertySelectable[propertyNumber];
@ -2497,7 +2495,7 @@ public abstract class AbstractEntityPersister
final String currentAttributeName = attributeNames[index];
if ( currentAttributeName.startsWith( attributeName ) && (
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
fields.add( ( (StateArrayContributorMapping) attributeMapping ).getStateArrayPosition() );
fields.add( attributeMapping.getStateArrayPosition() );
index++;
if ( index < attributeNames.length ) {
// Skip duplicates
@ -2563,7 +2561,7 @@ public abstract class AbstractEntityPersister
final String attributeName = attributeMapping.getAttributeName();
final int nameLength = attributeName.length();
final String currentAttributeName = attributeNames[index];
int position = ( (StateArrayContributorMapping) attributeMapping ).getStateArrayPosition();
final int position = attributeMapping.getStateArrayPosition();
if ( currentAttributeName.startsWith( attributeName ) && (
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
if ( propertyUpdateability[position] && !fields.contains( position ) ) {
@ -4984,7 +4982,7 @@ public abstract class AbstractEntityPersister
if ( hasSubclasses() ) {
visitAttributeMappings(
attribute -> {
final int stateArrayPosition = ( (StateArrayContributorMapping) attribute ).getStateArrayPosition();
final int stateArrayPosition = attribute.getStateArrayPosition();
final Object value = values[stateArrayPosition];
if ( value != UNFETCHED_PROPERTY ) {
final Setter setter = attribute.getPropertyAccess().getSetter();
@ -4997,7 +4995,7 @@ public abstract class AbstractEntityPersister
visitFetchables(
fetchable -> {
final AttributeMapping attribute = (AttributeMapping) fetchable;
final int stateArrayPosition = ( (StateArrayContributorMapping) attribute ).getStateArrayPosition();
final int stateArrayPosition = attribute.getStateArrayPosition();
final Object value = values[stateArrayPosition];
if ( value != UNFETCHED_PROPERTY ) {
final Setter setter = attribute.getPropertyAccess().getSetter();
@ -6272,7 +6270,7 @@ public abstract class AbstractEntityPersister
baseAssociationJtd,
this,
stateArrayPosition,
entityMappingType -> new StateArrayContributorMetadata() {
entityMappingType -> new AttributeMetadata() {
private final MutabilityPlan<?> mutabilityPlan = new DiscriminatedAssociationAttributeMapping.MutabilityPlanImpl( anyType );

View File

@ -196,17 +196,17 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
Object[] source,
Object[] target,
EntityPersister concreteDescriptor) {
containerDescriptor.visitStateArrayContributors(
contributor -> {
if ( contributor.getAttributeMetadataAccess().resolveAttributeMetadata( concreteDescriptor ).isUpdatable() ) {
final int position = contributor.getStateArrayPosition();
containerDescriptor.visitAttributeMappings(
attributeMapping -> {
if ( attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( concreteDescriptor ).isUpdatable() ) {
final int position = attributeMapping.getStateArrayPosition();
Object result;
if ( source[position] == LazyPropertyInitializer.UNFETCHED_PROPERTY
|| source[position] == PropertyAccessStrategyBackRefImpl.UNKNOWN ) {
result = source[position];
}
else {
result = contributor.getAttributeMetadataAccess()
result = attributeMapping.getAttributeMetadataAccess()
.resolveAttributeMetadata(null)
.getMutabilityPlan()
.deepCopy( source[position] );

View File

@ -6,9 +6,9 @@
*/
package org.hibernate.orm.test.mapping.naturalid.cid;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.internal.SimpleNaturalIdMapping;
import org.hibernate.persister.entity.EntityPersister;
@ -31,7 +31,7 @@ public abstract class AbstractCompositeIdAndNaturalIdTest {
public void testNaturalIdNullability(SessionFactoryScope scope) {
final EntityMappingType accountMapping = scope.getSessionFactory().getRuntimeMetamodels().getEntityMappingType( Account.class );
final SingularAttributeMapping shortCodeMapping = ((SimpleNaturalIdMapping) accountMapping.getNaturalIdMapping()).getAttribute();
final StateArrayContributorMetadata shortCodeMetadata = shortCodeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata shortCodeMetadata = shortCodeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertThat( shortCodeMetadata.isNullable(), is( false ) );
final EntityPersister rootEntityPersister = accountMapping.getRootEntityDescriptor().getEntityPersister();

View File

@ -7,10 +7,10 @@
package org.hibernate.orm.test.mapping.naturalid.immutable;
import org.hibernate.metamodel.RuntimeMetamodels;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityMetamodel;
@ -62,12 +62,12 @@ public class ImmutableManyToOneNaturalIdAnnotationTest {
// access by list-index should again be alphabetically sorted
final SingularAttributeMapping first = naturalIdMapping.getNaturalIdAttributes().get( 0 );
assertThat( first.getAttributeName(), is( "name" ) );
final StateArrayContributorMetadata firstMetadata = first.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata firstMetadata = first.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertFalse( firstMetadata.getMutabilityPlan().isMutable() );
final SingularAttributeMapping second = naturalIdMapping.getNaturalIdAttributes().get( 1 );
assertThat( second.getAttributeName(), is( "parent" ) );
final StateArrayContributorMetadata secondMetadata = second.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata secondMetadata = second.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertFalse( secondMetadata.getMutabilityPlan().isMutable() );
}
}

View File

@ -10,10 +10,10 @@ import jakarta.persistence.PersistenceException;
import org.hibernate.cfg.Environment;
import org.hibernate.metamodel.RuntimeMetamodels;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityMetamodel;
@ -100,12 +100,12 @@ public class ImmutableManyToOneNaturalIdHbmTest {
final SingularAttributeMapping first = naturalIdMapping.getNaturalIdAttributes().get( 0 );
assertThat( first.getAttributeName(), is( "name" ) );
final StateArrayContributorMetadata firstMetadata = first.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata firstMetadata = first.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertFalse( firstMetadata.getMutabilityPlan().isMutable() );
final SingularAttributeMapping second = naturalIdMapping.getNaturalIdAttributes().get( 1 );
assertThat( second.getAttributeName(), is( "parent" ) );
final StateArrayContributorMetadata secondMetadata = second.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata secondMetadata = second.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertFalse( secondMetadata.getMutabilityPlan().isMutable() );
}

View File

@ -7,9 +7,9 @@
package org.hibernate.orm.test.mapping.naturalid.inheritance;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.internal.SimpleNaturalIdMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.spi.StatisticsImplementor;
@ -46,7 +46,7 @@ public class InheritedNaturalIdTest {
final SingularAttributeMapping uidMapping = ((SimpleNaturalIdMapping) userMapping.getNaturalIdMapping()).getAttribute();
assertThat( uidMapping.getAttributeName(), is ("uid" ) );
final StateArrayContributorMetadata uidMetadata = uidMapping.getAttributeMetadataAccess().resolveAttributeMetadata( null );
final AttributeMetadata uidMetadata = uidMapping.getAttributeMetadataAccess().resolveAttributeMetadata( null );
assertThat( uidMetadata.isNullable(), is( true ) );
final EntityPersister rootEntityPersister = userMapping.getEntityPersister();