From b23c2f48c16036e9181612412bc002c31a8a8724 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 1 Dec 2021 09:35:16 -0600 Subject: [PATCH] Introduce `VirtualIdEmbeddable` and `IdClassEmbeddable` + instantiators - Clean up Component Type, removing as many calls to its tuplizer as possible atm - Clean up ManagedMappingType, EntityPersister, etc - mainly work around getting and setting value(s) Still need to - integrate embedded forms. `VirtualIdEmbeddable` does not really need it as it can use the id-mapping itself as the embedded form. But `IdClassEmbedded` should really be integrated - integrate `VirtualKeyEmbeddable` and `VirtualKeyEmbedded` for use as inverse composite fks - share `#finishInit` handling for `EmbeddableMappingType`, `VirtualIdEmbeddable` and `IdClassEmbeddable` - ability to use the containing composite owner as the parent of a composite (legacy behavior is to always use the "first" entity - clean up ComponentType, esp wrt its use of ComponentTuplizer --- .../internal/PersistentArrayHolder.java | 4 +- .../internal/DefaultLoadEventListener.java | 2 +- .../java/org/hibernate/mapping/Component.java | 2 +- .../metamodel/internal/AttributeFactory.java | 24 ++++-- .../EmbeddableInstantiatorDynamicMap.java | 2 +- .../EmbeddableInstantiatorPojoOptimized.java | 2 +- .../EmbeddableInstantiatorPojoStandard.java | 2 +- .../metamodel/mapping/AttributeMapping.java | 17 +---- .../metamodel/mapping/ManagedMappingType.java | 12 ++- .../internal/AbstractEmbeddableMapping.java | 74 +++++++++++++++++++ .../BasicEntityIdentifierMappingImpl.java | 2 +- .../internal/EmbeddableMappingTypeImpl.java | 47 ++---------- .../EmbeddedIdentifierMappingImpl.java | 2 +- .../internal/GeneratedValuesProcessor.java | 2 +- .../mapping/internal/IdClassEmbeddable.java | 33 ++------- .../NonAggregatedIdentifierMappingImpl.java | 4 +- .../mapping/internal/VirtualIdEmbeddable.java | 43 +++-------- .../VirtualIdRepresentationStrategy.java | 2 +- .../entity/AbstractEntityPersister.java | 12 +-- .../persister/entity/EntityPersister.java | 34 +++++++-- .../internal/ChainedPropertyAccessImpl.java | 3 +- .../internal/PropertyAccessEmbeddedImpl.java | 3 +- .../internal/PropertyAccessMapImpl.java | 3 +- .../PropertyAccessStrategyBackRefImpl.java | 3 +- ...ropertyAccessStrategyIndexBackRefImpl.java | 3 +- .../PropertyAccessStrategyNoopImpl.java | 3 +- .../access/spi/EnhancedSetterImpl.java | 5 +- .../hibernate/property/access/spi/Setter.java | 12 +-- .../property/access/spi/SetterFieldImpl.java | 2 +- .../property/access/spi/SetterMethodImpl.java | 3 +- .../AbstractEmbeddableInitializer.java | 8 +- .../AliasToBeanResultTransformer.java | 7 +- .../component/AbstractComponentTuplizer.java | 2 +- .../org/hibernate/type/ComponentType.java | 31 ++++---- .../PropertyAccessStrategyMapTest.java | 2 +- .../GetterSetterSerializationTest.java | 4 +- .../mapper/ComponentPropertyMapper.java | 4 +- .../entities/mapper/SinglePropertyMapper.java | 2 +- .../entities/mapper/id/EmbeddedIdMapper.java | 2 +- .../entities/mapper/id/SingleIdMapper.java | 4 +- .../id/VirtualEntitySingleIdMapper.java | 8 +- .../relation/AbstractCollectionMapper.java | 2 +- .../mapper/relation/AbstractToOneMapper.java | 2 +- ...ModifiedEntitiesRevisionInfoGenerator.java | 2 +- .../RevisionTimestampValueResolver.java | 6 +- 45 files changed, 231 insertions(+), 217 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java index 2975710f33..81720a4728 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java @@ -133,7 +133,7 @@ public class PersistentArrayHolder extends AbstractPersistentCollection { public void initializeEmptyCollection(CollectionPersister persister) { assert array == null; array = Array.newInstance( persister.getElementClass(), 0 ); - persister.getAttributeMapping().getPropertyAccess().getSetter().set( getOwner(), array, getSession().getFactory() ); + persister.getAttributeMapping().getPropertyAccess().getSetter().set( getOwner(), array ); endRead(); } @@ -149,7 +149,7 @@ public class PersistentArrayHolder extends AbstractPersistentCollection { Array.set( array, i, loadingState.get( i ) ); } } - attributeMapping.getPropertyAccess().getSetter().set( getOwner(), array, getSession().getFactory() ); + attributeMapping.getPropertyAccess().getSetter().set( getOwner(), array ); } @SuppressWarnings("UnusedDeclaration") diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java index 6b5a11697c..2787b1f5b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java @@ -176,7 +176,7 @@ public class DefaultLoadEventListener implements LoadEventListener { final Object parent = doLoad( event, parentPersister, parentEntityKey, options ); final Object dependent = dependentIdType.instantiate(); - dependentIdType.getPartMappingType().setPropertyValues( + dependentIdType.getPartMappingType().setValues( dependent, new Object[] { parent } ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java index 13552155ec..2fb4313a5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java @@ -515,7 +515,7 @@ public class Component extends SimpleValue implements MetaAttributable { @Override public void execute(SharedSessionContractImplementor session, Object incomingObject, Object injectionContext) { final Object generatedValue = subGenerator.generate( session, incomingObject ); - injector.set( injectionContext, generatedValue, session.getFactory() ); + injector.set( injectionContext, generatedValue ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 36b970f8e1..09ead611fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -13,6 +13,8 @@ import java.lang.reflect.ParameterizedType; import java.util.Iterator; import org.hibernate.AssertionFailure; +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.PropertyNotFoundException; import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.mapping.Collection; @@ -26,6 +28,8 @@ import org.hibernate.mapping.Value; import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.mapping.AttributeMapping; +import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.model.domain.AbstractIdentifiableType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; @@ -608,23 +612,31 @@ public class AttributeFactory { private static final MemberResolver virtualIdentifierMemberResolver = (attributeContext, metadataContext) -> { - final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); + final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType, metadataContext ); if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) { throw new IllegalArgumentException( "expecting IdClass mapping" ); } + org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType(); if ( !(type instanceof EmbeddedComponentType) ) { throw new IllegalArgumentException( "expecting IdClass mapping" ); } - final EmbeddedComponentType componentType = (EmbeddedComponentType) type; final String attributeName = attributeContext.getPropertyMapping().getName(); + final EmbeddedComponentType componentType = (EmbeddedComponentType) type; + final EmbeddableValuedModelPart embeddedPart = ( (CompositeTypeImplementor) componentType ).getMappingModelPart(); + assert embeddedPart != null; + final EmbeddableMappingType embeddable = embeddedPart.getEmbeddableTypeDescriptor(); + final AttributeMapping attributeMapping = embeddable.findAttributeMapping( attributeName ); + if ( attributeMapping == null ) { + throw new PropertyNotFoundException( + "Unable to locate property named " + attributeName + " on " + embeddable.getJavaTypeDescriptor().getJavaTypeClass().getName() + ); + } - final Getter getter = componentType.getComponentTuplizer() - .getGetter( componentType.getPropertyIndex( attributeName ) ); - - return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter ) + final Getter getter = attributeMapping.getPropertyAccess().getGetter(); + return getter instanceof PropertyAccessMapImpl.GetterImpl ? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() ) : getter.getMember(); }; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java index 8167c3004d..2aaa1ff267 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java @@ -37,7 +37,7 @@ public class EmbeddableInstantiatorDynamicMap if ( valuesAccess != null ) { final EmbeddableMappingType mappingType = runtimeDescriptorAccess.get(); - mappingType.setPropertyValues( dataMap, valuesAccess.get() ); + mappingType.setValues( dataMap, valuesAccess.get() ); } return dataMap; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java index 5a4a29d8c5..157106a9d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java @@ -36,7 +36,7 @@ public class EmbeddableInstantiatorPojoOptimized extends AbstractPojoInstantiato public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { final Object embeddable = instantiationOptimizer.newInstance(); final EmbeddableMappingType embeddableMapping = embeddableMappingAccess.get(); - embeddableMapping.setPropertyValues( embeddable, valuesAccess.get() ); + embeddableMapping.setValues( embeddable, valuesAccess.get() ); return embeddable; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java index e5f187cab2..3612dc8d5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java @@ -74,7 +74,7 @@ public class EmbeddableInstantiatorPojoStandard extends AbstractPojoInstantiator // A possible alternative could be to initialize the resolved values for primitive fields to their default value, // but that might cause unexpected outcomes for Hibernate 5 users that use createEmptyCompositesEnabled when updating. // You can see the need for this by running EmptyCompositeEquivalentToNullTest - embeddableMappingAccess.get().setPropertyValues( instance, valuesAccess.get() ); + embeddableMappingAccess.get().setValues( instance, valuesAccess.get() ); } return instance; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java index 20e67b66e5..1702896938 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java @@ -39,23 +39,12 @@ public interface AttributeMapping extends ModelPart, ValueMapping, Fetchable, Pr /** * Convenient access to getting the value for this attribute from the "owner" */ - default Object getValue(Object container, SharedSessionContractImplementor session) { - return getValue( container, session.getSessionFactory() ); - } - - /** - * Convenient access to getting the value for this attribute from the "owner" - */ - default Object getValue(Object container, SessionFactoryImplementor sessionFactory) { + default Object getValue(Object container) { return getPropertyAccess().getGetter().get( container ); } - default void setValue(Object container, Object value, SharedSessionContractImplementor session) { - setValue( container, value, session.getSessionFactory() ); - } - - default void setValue(Object container, Object value, SessionFactoryImplementor sessionFactory) { - getPropertyAccess().getSetter().set( container, value, sessionFactory ); + default void setValue(Object container, Object value) { + getPropertyAccess().getSetter().set( container, value ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java index 29e78d311e..2f99f82fd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java @@ -64,9 +64,17 @@ public interface ManagedMappingType extends MappingType, FetchableContainer { } } - Object[] getPropertyValues(Object compositeInstance); + Object[] getValues(Object instance); - void setPropertyValues(Object compositeInstance, Object[] resolvedValues); + default Object getValue(Object instance, int position) { + return getAttributeMapping( position ).getValue( instance ); + } + + void setValues(Object instance, Object[] resolvedValues); + + 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 diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java new file mode 100644 index 0000000000..28df8c6d76 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -0,0 +1,74 @@ +/* + * 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.internal; + +import org.hibernate.bytecode.spi.ReflectionOptimizer; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; +import org.hibernate.property.access.spi.Getter; +import org.hibernate.type.descriptor.java.JavaType; + +/** + * Base support for EmbeddableMappingType implementations + */ +public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType { + protected final SessionFactoryImplementor sessionFactory; + + public AbstractEmbeddableMapping(MappingModelCreationProcess creationProcess) { + this( creationProcess.getCreationContext() ); + } + + public AbstractEmbeddableMapping(RuntimeModelCreationContext creationContext) { + this( creationContext.getSessionFactory() ); + } + + protected AbstractEmbeddableMapping(SessionFactoryImplementor sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public JavaType getMappedJavaTypeDescriptor() { + return getRepresentationStrategy().getMappedJavaTypeDescriptor(); + } + + @Override + public Object[] getValues(Object compositeInstance) { + if ( compositeInstance == PropertyAccessStrategyBackRefImpl.UNKNOWN ) { + return new Object[getNumberOfAttributeMappings()]; + } + + final ReflectionOptimizer optimizer = getRepresentationStrategy().getReflectionOptimizer(); + if ( optimizer != null && optimizer.getAccessOptimizer() != null ) { + return optimizer.getAccessOptimizer().getPropertyValues( compositeInstance ); + } + + final Object[] results = new Object[getNumberOfAttributeMappings()]; + forEachAttributeMapping( (position, attribute) -> { + final Getter getter = attribute.getAttributeMetadataAccess() + .resolveAttributeMetadata( null ) + .getPropertyAccess() + .getGetter(); + results[position] = getter.get( compositeInstance ); + } ); + return results; + } + + @Override + public void setValues(Object component, Object[] values) { + final ReflectionOptimizer optimizer = getRepresentationStrategy().getReflectionOptimizer(); + if ( optimizer != null && optimizer.getAccessOptimizer() != null ) { + optimizer.getAccessOptimizer().setPropertyValues( component, values ); + } + else { + forEachAttributeMapping( (position, attribute) -> { + attribute.getPropertyAccess().getSetter().set( component, values[position] ); + } ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index 8e85fd3f2f..0fbb1205d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -127,7 +127,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { - propertyAccess.getSetter().set( entity, id, session.getFactory() ); + propertyAccess.getSetter().set( entity, id ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 2c3b1b8e6b..a3b8077e54 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -18,7 +18,6 @@ import java.util.function.Function; import org.hibernate.MappingException; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.SharedSessionContract; -import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; import org.hibernate.engine.FetchTiming; @@ -50,14 +49,12 @@ 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.StateArrayContributorMapping; 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; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.query.NavigablePath; import org.hibernate.sql.ast.Clause; @@ -81,9 +78,12 @@ import org.hibernate.type.spi.CompositeTypeImplementor; import org.hibernate.type.spi.TypeConfiguration; /** - * @author Steve Ebersole + * Describes a "normal" embeddable. + * + * NOTE: At the moment, this class is used to describe some non-normal cases: mainly + * composite fks */ -public class EmbeddableMappingTypeImpl implements EmbeddableMappingType, SelectableMappings { +public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping implements SelectableMappings { public static EmbeddableMappingTypeImpl from( Component bootDescriptor, @@ -150,8 +150,6 @@ public class EmbeddableMappingTypeImpl implements EmbeddableMappingType, Selecta private final JavaType embeddableJtd; private final EmbeddableRepresentationStrategy representationStrategy; - private final SessionFactoryImplementor sessionFactory; - private final List attributeMappings = new ArrayList<>(); private SelectableMappings selectableMappings; @@ -163,14 +161,13 @@ public class EmbeddableMappingTypeImpl implements EmbeddableMappingType, Selecta Component bootDescriptor, Function embeddedPartBuilder, RuntimeModelCreationContext creationContext) { + super( creationContext ); this.representationStrategy = creationContext .getBootstrapContext() .getRepresentationStrategySelector() .resolveStrategy( bootDescriptor, () -> this, creationContext ); this.embeddableJtd = representationStrategy.getMappedJavaTypeDescriptor(); - this.sessionFactory = creationContext.getSessionFactory(); - this.valueMapping = embeddedPartBuilder.apply( this ); final ConfigurationService cs = sessionFactory.getServiceRegistry() @@ -190,9 +187,10 @@ public class EmbeddableMappingTypeImpl implements EmbeddableMappingType, Selecta SelectableMappings selectableMappings, EmbeddableMappingType inverseMappingType, MappingModelCreationProcess creationProcess) { + super( creationProcess ); + this.embeddableJtd = inverseMappingType.getJavaTypeDescriptor(); this.representationStrategy = inverseMappingType.getRepresentationStrategy(); - this.sessionFactory = creationProcess.getCreationContext().getSessionFactory(); this.valueMapping = valueMapping; this.createEmptyCompositesEnabled = inverseMappingType.isCreateEmptyCompositesEnabled(); this.selectableMappings = selectableMappings; @@ -787,35 +785,6 @@ public class EmbeddableMappingTypeImpl implements EmbeddableMappingType, Selecta visitAttributeMappings( consumer ); } - public Object[] getPropertyValues(Object compositeInstance) { - final Object[] results = new Object[attributeMappings.size()]; - for ( int i = 0; i < attributeMappings.size(); i++ ) { - final StateArrayContributorMapping attr = (StateArrayContributorMapping) attributeMappings.get( i ); - final Getter getter = attr.getAttributeMetadataAccess() - .resolveAttributeMetadata( null ) - .getPropertyAccess() - .getGetter(); - results[ attr.getStateArrayPosition() ] = getter.get( compositeInstance ); - } - return results; - } - - public void setPropertyValues(Object compositeInstance, Object[] resolvedValues) { - final ReflectionOptimizer reflectionOptimizer = representationStrategy.getReflectionOptimizer(); - if ( reflectionOptimizer != null ) { - final ReflectionOptimizer.AccessOptimizer accessOptimizer = reflectionOptimizer.getAccessOptimizer(); - if ( accessOptimizer != null ) { - accessOptimizer.setPropertyValues( compositeInstance, resolvedValues ); - } - return; - } - - for ( int i = 0; i < attributeMappings.size(); i++ ) { - final AttributeMapping attributeMapping = attributeMappings.get( i ); - attributeMapping.setValue( compositeInstance, resolvedValues[i], sessionFactory ); - } - } - public boolean isCreateEmptyCompositesEnabled() { return createEmptyCompositesEnabled; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java index 8c408f1ef9..608538a469 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedIdentifierMappingImpl.java @@ -88,7 +88,7 @@ public class EmbeddedIdentifierMappingImpl @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { - propertyAccess.getSetter().set( entity, id, session.getFactory() ); + propertyAccess.getSetter().set( entity, id ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java index e69029384f..e618d86801 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java @@ -185,7 +185,7 @@ public class GeneratedValuesProcessor { .resolveAttributeMetadata( entityDescriptor ) .getPropertyAccess() .getSetter() - .set( entity, generatedValue, sessionFactory ); + .set( entity, generatedValue ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java index 1561280e21..95c67287e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java @@ -78,10 +78,9 @@ import static org.hibernate.internal.util.collections.CollectionHelper.arrayList import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.getStateArrayContributorMetadataAccess; /** - * EmbeddableMappingType implementation describing an - * {@link jakarta.persistence.IdClass} + * EmbeddableMappingType implementation describing an {@link jakarta.persistence.IdClass} */ -public class IdClassEmbeddable implements IdentifierValueMapper { +public class IdClassEmbeddable extends AbstractEmbeddableMapping implements IdentifierValueMapper { private final NavigableRole navigableRole; private final NonAggregatedIdentifierMapping idMapping; private final VirtualIdEmbeddable virtualIdEmbeddable; @@ -93,8 +92,6 @@ public class IdClassEmbeddable implements IdentifierValueMapper { private final List attributeMappings; private SelectableMappings selectableMappings; - private final SessionFactoryImplementor sessionFactory; - public IdClassEmbeddable( Component idClassSource, RootClass bootEntityDescriptor, @@ -104,7 +101,7 @@ public class IdClassEmbeddable implements IdentifierValueMapper { String[] idColumns, VirtualIdEmbeddable virtualIdEmbeddable, MappingModelCreationProcess creationProcess) { - this.sessionFactory = creationProcess.getCreationContext().getSessionFactory(); + super( creationProcess ); this.navigableRole = idMapping.getNavigableRole().append( NavigablePath.IDENTIFIER_MAPPER_PROPERTY ); this.idMapping = idMapping; @@ -231,7 +228,7 @@ public class IdClassEmbeddable implements IdentifierValueMapper { } } - setPropertyValues( id, propertyValues ); + setValues( id, propertyValues ); return id; } @@ -270,7 +267,7 @@ public class IdClassEmbeddable implements IdentifierValueMapper { } ); - virtualIdEmbeddable.setPropertyValues( entity, propertyValues ); + virtualIdEmbeddable.setValues( entity, propertyValues ); } @@ -347,24 +344,6 @@ public class IdClassEmbeddable implements IdentifierValueMapper { } } - @Override - public Object[] getPropertyValues(Object composite) { - final Object[] values = new Object[ attributeMappings.size() ]; - for ( int i = 0; i < attributeMappings.size(); i++ ) { - final SingularAttributeMapping attributeMapping = attributeMappings.get( i ); - values[i] = attributeMapping.getPropertyAccess().getGetter().get( composite ); - } - return values; - } - - @Override - public void setPropertyValues(Object composite, Object[] resolvedValues) { - for ( int i = 0; i < attributeMappings.size(); i++ ) { - final SingularAttributeMapping attributeMapping = attributeMappings.get( i ); - attributeMapping.getPropertyAccess().getSetter().set( composite, resolvedValues[i], sessionFactory ); - } - } - @Override public int getNumberOfFetchables() { return getNumberOfAttributeMappings(); @@ -394,7 +373,7 @@ public class IdClassEmbeddable implements IdentifierValueMapper { @Override public void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session) { attributeMappings.forEach( (attribute) -> { - final Object attributeValue = attribute.getValue( domainValue, session ); + final Object attributeValue = attribute.getValue( domainValue ); attribute.breakDownJdbcValues( attributeValue, valueConsumer, session ); } ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index 4367919f2c..3d3b17fc28 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -284,7 +284,7 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif propertyValues[i] = o; } } - identifierValueMapper.setPropertyValues( id, propertyValues ); + identifierValueMapper.setValues( id, propertyValues ); return id; } else { @@ -325,7 +325,7 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif } } ); - getEmbeddableTypeDescriptor().setPropertyValues( entity, propertyValues ); + getEmbeddableTypeDescriptor().setValues( entity, propertyValues ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java index 9f0651f1b5..2186d36b4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java @@ -62,7 +62,6 @@ import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; -import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.spi.CompositeTypeImplementor; import org.hibernate.type.spi.TypeConfiguration; @@ -73,20 +72,14 @@ import static org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping.Ide /** * Embeddable describing the virtual-id aspect of a non-aggregated composite id */ -public class VirtualIdEmbeddable implements IdentifierValueMapper { - +public class VirtualIdEmbeddable extends AbstractEmbeddableMapping implements IdentifierValueMapper { private final NavigableRole navigableRole; private final NonAggregatedIdentifierMapping idMapping; - private final JavaType javaType; - - // private final VirtualIdEmbedded embedded; private final VirtualIdRepresentationStrategy representationStrategy; private final List attributeMappings; private SelectableMappings selectableMappings; - private final SessionFactoryImplementor sessionFactory; - public VirtualIdEmbeddable( Component virtualIdSource, NonAggregatedIdentifierMapping idMapping, @@ -94,12 +87,10 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { String rootTableExpression, String[] rootTableKeyColumnNames, MappingModelCreationProcess creationProcess) { - this.sessionFactory = creationProcess.getCreationContext().getSessionFactory(); + super( creationProcess ); this.navigableRole = idMapping.getNavigableRole(); this.idMapping = idMapping; - this.javaType = identifiedEntityMapping.getJavaTypeDescriptor(); - this.representationStrategy = new VirtualIdRepresentationStrategy( this, identifiedEntityMapping ); final CompositeType compositeType = (CompositeType) virtualIdSource.getType(); @@ -158,7 +149,7 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { @Override public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { return representationStrategy.getInstantiator().instantiate( - () -> getPropertyValues( entity ), + () -> getValues( entity ), session.getSessionFactory() ); } @@ -166,7 +157,7 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { if ( entity != id ) { - setPropertyValues( entity, getPropertyValues( id ) ); + setValues( entity, getValues( id ) ); } } @@ -184,11 +175,6 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { return idMapping.getPartName(); } - @Override - public JavaType getMappedJavaTypeDescriptor() { - return javaType; - } - @Override public EmbeddableValuedModelPart getEmbeddedValueMapping() { return getEmbeddedPart(); @@ -200,21 +186,14 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { } @Override - public Object[] getPropertyValues(Object composite) { - final Object[] values = new Object[ attributeMappings.size() ]; + public AttributeMapping findAttributeMapping(String name) { for ( int i = 0; i < attributeMappings.size(); i++ ) { - final SingularAttributeMapping attributeMapping = attributeMappings.get( i ); - values[i] = attributeMapping.getPropertyAccess().getGetter().get( composite ); - } - return values; - } - - @Override - public void setPropertyValues(Object composite, Object[] resolvedValues) { - for ( int i = 0; i < attributeMappings.size(); i++ ) { - final SingularAttributeMapping attributeMapping = attributeMappings.get( i ); - attributeMapping.getPropertyAccess().getSetter().set( composite, resolvedValues[i], sessionFactory ); + final AttributeMapping attr = attributeMappings.get( i ); + if ( name.equals( attr.getAttributeName() ) ) { + return attr; + } } + return null; } @Override @@ -338,7 +317,7 @@ public class VirtualIdEmbeddable implements IdentifierValueMapper { @Override public void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session) { attributeMappings.forEach( (attribute) -> { - final Object attributeValue = attribute.getValue( domainValue, session ); + final Object attributeValue = attribute.getValue( domainValue ); attribute.breakDownJdbcValues( attributeValue, valueConsumer, session ); } ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java index c50d9f3bbf..b168996907 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java @@ -75,7 +75,7 @@ public class VirtualIdRepresentationStrategy implements EmbeddableRepresentation if ( valuesAccess != null ) { final Object[] values = valuesAccess.get(); if ( values != null ) { - virtualIdEmbeddable.setPropertyValues( instantiated, values ); + virtualIdEmbeddable.setValues( instantiated, values ); } } return instantiated; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 17d629634d..57f464b5d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -4890,6 +4890,7 @@ public abstract class AbstractEntityPersister return proxyJavaTypeDescriptor != null ? proxyJavaTypeDescriptor.getJavaTypeClass() : javaTypeDescriptor.getJavaTypeClass(); } + @Override public void setPropertyValues(Object object, Object[] values) { if ( accessOptimizer != null ) { accessOptimizer.setPropertyValues( object, values ); @@ -4902,7 +4903,7 @@ public abstract class AbstractEntityPersister final Object value = values[stateArrayPosition]; if ( value != UNFETCHED_PROPERTY ) { final Setter setter = attribute.getPropertyAccess().getSetter(); - setter.set( object, value, getFactory() ); + setter.set( object, value ); } } ); @@ -4915,7 +4916,7 @@ public abstract class AbstractEntityPersister final Object value = values[stateArrayPosition]; if ( value != UNFETCHED_PROPERTY ) { final Setter setter = attribute.getPropertyAccess().getSetter(); - setter.set( object, value, getFactory() ); + setter.set( object, value ); } }, @@ -4925,11 +4926,13 @@ public abstract class AbstractEntityPersister } } + @Override public void setPropertyValue(Object object, int i, Object value) { final String propertyName = getPropertyNames()[i]; setPropertyValue( object, propertyName, value ); } + @Override public Object[] getPropertyValues(Object object) { if ( accessOptimizer != null ) { return accessOptimizer.getPropertyValues( object ); @@ -5103,8 +5106,7 @@ public abstract class AbstractEntityPersister if ( versionMapping != null ) { versionMapping.getVersionAttribute().getPropertyAccess().getSetter().set( entity, - versionMapping.getUnsavedStrategy().getDefaultValue( currentVersion ), - getFactory() + versionMapping.getUnsavedStrategy().getDefaultValue( currentVersion ) ); } } @@ -5284,7 +5286,7 @@ public abstract class AbstractEntityPersister public void setPropertyValue(Object object, String propertyName, Object value) { final AttributeMapping attributeMapping = (AttributeMapping) findSubPart( propertyName, this ); final AttributeMetadata attributeMetadata = attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( this ); - attributeMetadata.getPropertyAccess().getSetter().set( object, value, getFactory() ); + attributeMetadata.getPropertyAccess().getSetter().set( object, value ); } public static int getTableId(String tableName, String[] tables) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java index e873ea3490..f0064f3334 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java @@ -788,24 +788,48 @@ public interface EntityPersister */ Class getConcreteProxyClass(); + default void setValues(Object object, Object[] values) { + setPropertyValues( object, values ); + } + /** * Set the given values to the mapped properties of the given object + * + * @deprecated as of 6.0. Use {@link #setValues} instead */ + @Deprecated void setPropertyValues(Object object, Object[] values); + default void setValue(Object object, int i, Object value) { + setPropertyValue( object, i, value ); + } + /** * Set the value of a particular property + * + * @deprecated as of 6.0. Use {@link #setValue} instead */ + @Deprecated void setPropertyValue(Object object, int i, Object value); - /** - * Return the (loaded) values of the mapped properties of the object (not including backrefs) - */ - Object[] getPropertyValues(Object object); + default Object[] getValues(Object object) { + return getPropertyValues( object ); + } /** - * Get the value of a particular property + * @deprecated as of 6.0. Use {@link #getValues} instead */ + @Deprecated + Object[] getPropertyValues(Object object); + + default Object getValue(Object object, int i) { + return getValue( object, i ); + } + + /** + * @deprecated as of 6.0. Use {@link #getValue} instead + */ + @Deprecated Object getPropertyValue(Object object, int i) throws HibernateException; /** diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java index 8ee63ff70c..38c0502138 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java @@ -11,7 +11,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -61,7 +60,7 @@ public class ChainedPropertyAccessImpl implements PropertyAccess, Getter, Setter } @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { throw new UnsupportedOperationException(); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java index 79f2591b77..7b29fa12d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java @@ -11,7 +11,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -106,7 +105,7 @@ public class PropertyAccessEmbeddedImpl implements PropertyAccess { public static final SetterImpl INSTANCE = new SetterImpl(); @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { // nothing to do } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java index 8fb7dab0ba..e86de8062f 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java @@ -11,7 +11,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -104,7 +103,7 @@ public class PropertyAccessMapImpl implements PropertyAccess { @Override @SuppressWarnings("unchecked") - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { ( (Map) target ).put( propertyName, value ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java index 03a747e89f..5829c14920 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java @@ -12,7 +12,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -135,7 +134,7 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy public static final SetterImpl INSTANCE = new SetterImpl(); @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { // this page intentionally left blank :) } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java index 1e3feba148..dd7574b816 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java @@ -11,7 +11,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -118,7 +117,7 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr public static final SetterImpl INSTANCE = new SetterImpl(); @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { // this page intentionally left blank :) } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java index e98b301afa..ce663f0627 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java @@ -11,7 +11,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Map; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; @@ -107,7 +106,7 @@ public class PropertyAccessStrategyNoopImpl implements PropertyAccessStrategy { public static final SetterImpl INSTANCE = new SetterImpl(); @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java index 27dbb9efe3..e15dd791d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java @@ -36,9 +36,8 @@ public class EnhancedSetterImpl extends SetterFieldImpl { } @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { - - super.set( target, value, factory ); + public void set(Object target, Object value) { + super.set( target, value ); // This sets the component relation for dirty tracking purposes if ( target instanceof CompositeOwner && value instanceof CompositeTracker ) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java index 39c647f593..b3b47e0764 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java @@ -18,16 +18,8 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; * @author Steve Ebersole */ public interface Setter extends Serializable { - /** - * Set the property value from the given instance - * - * @param target The instance upon which to set the given value. - * @param value The value to be set on the target. - * @param factory The session factory from which this request originated. - * - * @throws org.hibernate.HibernateException - */ - void set(Object target, Object value, SessionFactoryImplementor factory); + + void set(Object target, Object value); /** * Optional operation (may return {@code null}) diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java index 822f4d928f..bdd33670ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java @@ -47,7 +47,7 @@ public class SetterFieldImpl implements Setter { } @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { try { field.set( target, value ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java index c42af3cbb2..f7ce9f0747 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java @@ -12,7 +12,6 @@ import java.lang.reflect.Method; import org.hibernate.PropertyAccessException; import org.hibernate.PropertySetterAccessException; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; @@ -39,7 +38,7 @@ public class SetterMethodImpl implements Setter { } @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) { + public void set(Object target, Object value) { try { setterMethod.invoke( target, value ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java index d6b123de26..01a9bb977d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java @@ -166,7 +166,7 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA final Initializer parentInitializer = processingState.resolveInitializer( navigablePath.getParent() ); if ( parentInitializer != this ) { ( (FetchParentAccess) parentInitializer ).registerResolutionListener( (entity) -> { - representationEmbeddable.setPropertyValues( entity, rowState ); + representationEmbeddable.setValues( entity, rowState ); stateInjected = true; } ); } @@ -188,9 +188,7 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA } } else if ( stateAllNull == FALSE && stateInjected != TRUE ) { - // todo (6.0) : i think this is still called for cases where - // we have already done the "ctor injection" - representationEmbeddable.setPropertyValues( compositeInstance, rowState ); + representationEmbeddable.setValues( compositeInstance, rowState ); stateInjected = true; } } @@ -335,7 +333,7 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA compositeInstance ); - parentInjectionAccess.getSetter().set( compositeInstance, parent, sessionFactory ); + parentInjectionAccess.getSetter().set( compositeInstance, parent ); } private Object determineParentInstance(RowProcessingState processingState) { diff --git a/hibernate-core/src/main/java/org/hibernate/transform/AliasToBeanResultTransformer.java b/hibernate-core/src/main/java/org/hibernate/transform/AliasToBeanResultTransformer.java index 1aeabd65e6..f4dd3dde6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/transform/AliasToBeanResultTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/transform/AliasToBeanResultTransformer.java @@ -75,14 +75,11 @@ public class AliasToBeanResultTransformer extends AliasedTupleSubsetResultTransf for ( int i = 0; i < aliases.length; i++ ) { if ( setters[i] != null ) { - setters[i].set( result, tuple[i], null ); + setters[i].set( result, tuple[i] ); } } } - catch ( InstantiationException e ) { - throw new HibernateException( "Could not instantiate resultclass: " + resultClass.getName() ); - } - catch ( IllegalAccessException e ) { + catch ( InstantiationException | IllegalAccessException e ) { throw new HibernateException( "Could not instantiate resultclass: " + resultClass.getName() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java index 90725bd276..eb2ef6534f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java @@ -65,7 +65,7 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { public void setPropertyValues(Object component, Object[] values) throws HibernateException { for ( int i = 0; i < propertySpan; i++ ) { - setters[i].set( component, values[i], null ); + setters[i].set( component, values[i] ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java index e369059e1b..17fce9e3eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -97,10 +97,6 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen return isKey; } - public ComponentTuplizer getComponentTuplizer() { - return componentTuplizer; - } - @Override public int getColumnSpan(Mapping mapping) throws MappingException { int span = 0; @@ -382,11 +378,11 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen return getPropertyValue( component, i ); } - public Object getPropertyValue(Object component, int i) - throws HibernateException { - if (component == null) { - component = new Object[propertySpan]; + public Object getPropertyValue(Object component, int i) { + if ( component == null ) { + return null; } + if ( component instanceof Object[] ) { // A few calls to hashCode pass the property values already in an // Object[] (ex: QueryKey hash codes for cached queries). @@ -395,7 +391,9 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen return ( (Object[]) component )[i]; } else { - return componentTuplizer.getPropertyValue( component, i ); + return mappingModelPart + .getEmbeddableTypeDescriptor() + .getValue( component, i ); } } @@ -407,9 +405,9 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen @Override public Object[] getPropertyValues(Object component) { if (component == null) { - component = new Object[propertySpan]; + return new Object[propertySpan]; } - if ( component instanceof Object[] ) { + else if ( component instanceof Object[] ) { // A few calls to hashCode pass the property values already in an // Object[] (ex: QueryKey hash codes for cached queries). // It's easiest to just check for the condition here prior to @@ -417,14 +415,15 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen return (Object[]) component; } else { - return componentTuplizer.getPropertyValues( component ); + return mappingModelPart + .getEmbeddableTypeDescriptor() + .getValues( component ); } } @Override - public void setPropertyValues(Object component, Object[] values) - throws HibernateException { - componentTuplizer.setPropertyValues( component, values ); + public void setPropertyValues(Object component, Object[] values) { + mappingModelPart.getEmbeddableTypeDescriptor().setValues( component, values ); } @Override @@ -486,7 +485,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen //equals()/hashCode() implementations final PropertyAccess parentAccess = mappingModelPart().getParentInjectionAttributePropertyAccess(); if ( parentAccess != null ) { - parentAccess.getSetter().set( result, parentAccess.getGetter().get( component ), factory ); + parentAccess.getSetter().set( result, parentAccess.getGetter().get( component ) ); } return result; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java index a45c574900..4af533011f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java @@ -58,7 +58,7 @@ public class PropertyAccessStrategyMapTest extends BaseUnitTestCase { final HashMap map = new HashMap<>(); - access.getSetter().set( map, value, null ); + access.getSetter().set( map, value ); assertEquals( value, map.get( key ) ); assertEquals( value, access.getGetter().get( map ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/serialization/GetterSetterSerializationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/serialization/GetterSetterSerializationTest.java index 5d52d0bd18..ca65699cd0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/serialization/GetterSetterSerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/serialization/GetterSetterSerializationTest.java @@ -82,7 +82,7 @@ public class GetterSetterSerializationTest { final Setter setterClone = (Setter) ois.readObject(); final PK pkNew = new PK( 2L ); - setterClone.set( entity, pkNew, null ); + setterClone.set( entity, pkNew ); assertSame( pkNew, getter.get( entity ) ); } @@ -132,7 +132,7 @@ public class GetterSetterSerializationTest { final Setter setterClone = (Setter) ois.readObject(); final PK pkNew = new PK( 2L ); - setterClone.set( entity, pkNew, null ); + setterClone.set( entity, pkNew ); assertSame( pkNew, getter.get( entity ) ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java index 4cf518510c..47d83b1be7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/ComponentPropertyMapper.java @@ -138,11 +138,11 @@ public class ComponentPropertyMapper extends AbstractPropertyMapper implements C if ( isAllPropertiesNull( data ) ) { // single property, but default value need not be null, so we'll set it to null anyway - setter.set( obj, null, null ); + setter.set( obj, null ); } else { // set the component - setter.set( obj, subObj, null ); + setter.set( obj, subObj ); delegate.mapToEntityFromMap( enversService, subObj, data, primaryKey, versionsReader, revision ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java index 1daae3a178..81fd9fb357 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java @@ -117,7 +117,7 @@ public class SinglePropertyMapper extends AbstractPropertyMapper implements Simp // We only set a null value if the field is not primitive. Otherwise, we leave it intact. if ( value != null || !isPrimitive( setter, propertyData, obj.getClass() ) ) { - setter.set( obj, value, null ); + setter.set( obj, value ); } return null; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java index abbc84872a..059345fbdd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/EmbeddedIdMapper.java @@ -83,7 +83,7 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl } if ( ret ) { - setter.set( obj, subObj, null ); + setter.set( obj, subObj ); } return ret; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java index b7690a953b..e104174b61 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/SingleIdMapper.java @@ -64,7 +64,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu propertyData, getServiceRegistry() ); - setter.set( obj, value, null ); + setter.set( obj, value ); return true; } } @@ -164,7 +164,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu getServiceRegistry() ); - setter.set( objTo, getter.get( objFrom ), null ); + setter.set( objTo, getter.get( objFrom ) ); return null; } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/VirtualEntitySingleIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/VirtualEntitySingleIdMapper.java index 46de765f3a..7b6e477931 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/VirtualEntitySingleIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/id/VirtualEntitySingleIdMapper.java @@ -95,11 +95,11 @@ public class VirtualEntitySingleIdMapper extends SingleIdMapper { } if ( !value.getClass().equals( propertyData.getVirtualReturnClass() ) ) { - setter.set( objTo, getAssociatedEntityIdMapper().mapToIdFromEntity( value ), null ); + setter.set( objTo, getAssociatedEntityIdMapper().mapToIdFromEntity( value ) ); } else { // This means we're setting the object - setter.set( objTo, value, null ); + setter.set( objTo, value ); } return null; @@ -135,10 +135,10 @@ public class VirtualEntitySingleIdMapper extends SingleIdMapper { ); if ( paramClass != null && paramClass.equals( propertyData.getVirtualReturnClass() ) ) { - setter.set( obj, getAssociatedEntityIdMapper().mapToIdFromEntity( value ), null ); + setter.set( obj, getAssociatedEntityIdMapper().mapToIdFromEntity( value ) ); } else { - setter.set( obj, value, null ); + setter.set( obj, value ); } return true; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index 29aefbaa74..5c34905b5e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -316,7 +316,7 @@ public abstract class AbstractCollectionMapper extends AbstractPropertyMapper enversService.getServiceRegistry() ); - setter.set( obj, collectionProxy, null ); + setter.set( obj, collectionProxy ); return null; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java index d338fd45af..3ebc142c60 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractToOneMapper.java @@ -105,7 +105,7 @@ public abstract class AbstractToOneMapper extends AbstractPropertyMapper { propertyData, serviceRegistry ); - setter.set( targetObject, value, null ); + setter.set( targetObject, value ); return null; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java index 4c284fc5b5..813186ac34 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/DefaultTrackingModifiedEntitiesRevisionInfoGenerator.java @@ -54,7 +54,7 @@ public class DefaultTrackingModifiedEntitiesRevisionInfoGenerator extends Defaul Set modifiedEntityNames = (Set) modifiedEntityNamesGetter.get( revisionEntity ); if ( modifiedEntityNames == null ) { modifiedEntityNames = new HashSet<>(); - modifiedEntityNamesSetter.set( revisionEntity, modifiedEntityNames, null ); + modifiedEntityNamesSetter.set( revisionEntity, modifiedEntityNames ); } modifiedEntityNames.add( entityName ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionTimestampValueResolver.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionTimestampValueResolver.java index bad7608fa9..6e82486271 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionTimestampValueResolver.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionTimestampValueResolver.java @@ -35,13 +35,13 @@ public class RevisionTimestampValueResolver { public void resolveNow(Object object) { if ( timestampData.isTimestampDate() ) { - revisionTimestampSetter.set( object, new Date(), null ); + revisionTimestampSetter.set( object, new Date() ); } else if ( timestampData.isTimestampLocalDateTime() ) { - revisionTimestampSetter.set(object, LocalDateTime.now(), null ); + revisionTimestampSetter.set(object, LocalDateTime.now() ); } else { - revisionTimestampSetter.set( object, System.currentTimeMillis(), null ); + revisionTimestampSetter.set( object, System.currentTimeMillis() ); } }