Removed use of EntityPersister#getEntityTuplizer()

This commit is contained in:
Andrea Boriero 2021-03-04 16:14:17 +01:00
parent ddf434df7e
commit cb603a337b
3 changed files with 45 additions and 16 deletions

View File

@ -8,6 +8,7 @@ package org.hibernate.bytecode.enhance.spi.interceptor;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.EntityMode;
@ -19,8 +20,8 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
@ -103,7 +104,6 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
final EntityPersister entityPersister = session.getFactory()
.getMetamodel()
.entityPersister( getEntityName() );
final EntityTuplizer entityTuplizer = entityPersister.getEntityTuplizer();
if ( writtenFieldNames != null && !writtenFieldNames.isEmpty() ) {
@ -111,7 +111,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
if ( writtenFieldNames.contains( attributeName ) ) {
// the requested attribute was one of the attributes explicitly set, we can just return the explicitly set value
return entityTuplizer.getPropertyValue( target, attributeName );
return entityPersister.getPropertyValue( target, attributeName );
}
// otherwise we want to save all of the explicitly set values in anticipation of
@ -122,7 +122,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
int index = 0;
for ( String writtenFieldName : writtenFieldNames ) {
writtenValues[index] = entityTuplizer.getPropertyValue( target, writtenFieldName );
writtenValues[index] = entityPersister.getPropertyValue( target, writtenFieldName );
index++;
}
}
@ -141,9 +141,17 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
if ( writtenValues != null ) {
// here is the replaying of the explicitly set values we prepared above
int index = 0;
for ( String writtenFieldName : writtenFieldNames ) {
entityTuplizer.setPropertyValue( target, writtenFieldName, writtenValues[index++] );
List<AttributeMapping> attributeMappings = entityPersister.getAttributeMappings();
for ( int index = 0; index < attributeMappings.size(); index++ ) {
if ( writtenFieldName.contains( attributeMappings.get( index ).getAttributeName() ) ) {
entityPersister.setPropertyValue(
target,
index,
writtenValues[index]
);
}
}
}
writtenFieldNames.clear();
}

View File

@ -99,6 +99,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LoadEvent;
import org.hibernate.id.Assigned;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.PostInsertIdentifierGenerator;
import org.hibernate.id.PostInsertIdentityPersister;
@ -223,6 +224,7 @@ import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.entity.internal.EntityResultImpl;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.InDatabaseValueGenerationStrategy;
import org.hibernate.tuple.InMemoryValueGenerationStrategy;
import org.hibernate.tuple.NonIdentifierAttribute;
@ -230,6 +232,7 @@ import org.hibernate.tuple.ValueGeneration;
import org.hibernate.tuple.entity.EntityBasedAssociationAttribute;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.VersionProperty;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType;
@ -5375,10 +5378,7 @@ public abstract class AbstractEntityPersister
public void setPropertyValue(Object object, int i, Object value) {
final String propertyName = getPropertyNames()[i];
final AttributeMapping attributeMapping = (AttributeMapping) findSubPart( propertyName, this );
final AttributeMetadata attributeMetadata = attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( this );
attributeMetadata.getPropertyAccess().getSetter().set( object, value, getFactory() );
setPropertyValue( object, propertyName, value );
}
public Object[] getPropertyValues(Object object) {
@ -5487,7 +5487,25 @@ public abstract class AbstractEntityPersister
Object currentId,
Object currentVersion,
SharedSessionContractImplementor session) {
getEntityTuplizer().resetIdentifier( entity, currentId, currentVersion, session );
final IdentifierProperty identifierProperty = entityMetamodel.getIdentifierProperty();
if ( identifierProperty.getIdentifierGenerator() instanceof Assigned ) {
}
else {
//reset the id
Object result = identifierProperty
.getUnsavedValue()
.getDefaultValue( currentId );
setIdentifier( entity, result, session );
//reset the version
VersionProperty versionProperty = entityMetamodel.getVersionProperty();
if ( entityMetamodel.isVersioned() ) {
setPropertyValue(
entity,
entityMetamodel.getVersionPropertyIndex(),
versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
);
}
}
}
@Override
@ -5760,7 +5778,9 @@ public abstract class AbstractEntityPersister
}
public void setPropertyValue(Object object, String propertyName, Object value) {
getEntityTuplizer().setPropertyValue( object, propertyName, value );
final AttributeMapping attributeMapping = (AttributeMapping) findSubPart( propertyName, this );
final AttributeMetadata attributeMetadata = attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( this );
attributeMetadata.getPropertyAccess().getSetter().set( object, value, getFactory() );
}
public static int getTableId(String tableName, String[] tables) {

View File

@ -77,9 +77,10 @@ public class EntityInstantiator {
// If it is not in the cache, creating a new entity instance
Object ret = versionsReader.getSessionImplementor()
.getFactory()
.getEntityPersister( entityName )
.getEntityTuplizer()
.instantiate( null, versionsReader.getSessionImplementor() );
.getMetamodel()
.entityPersister( entityName )
.getRepresentationStrategy().getInstantiator()
.instantiate( versionsReader.getSessionImplementor().getSessionFactory() );
// Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
// relation is present (which is eagerly loaded).