Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ private void handleGeneratedProperties(EntityEntry entry, GeneratedValues genera
*/
protected void handleDeleted(EntityEntry entry) {
if ( entry.getStatus() == Status.DELETED ) {
final var entityMetamodel = getPersister().getEntityMetamodel();
final var entityMetamodel = getPersister();
final boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned()
&& entityMetamodel.getOptimisticLockStyle().isAllOrDirty();
&& entityMetamodel.optimisticLockStyle().isAllOrDirty();
if ( isImpliedOptimisticLocking && entry.getLoadedState() != null ) {
// The entity will be deleted, and because we are going to create a delete statement
// that uses all the state values in the where clause, the entry state needs to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ public EntityRelatedState(EntityPersister persister,
// versioned, we need to fetch the current version.
this.initializeBeforeWrite =
!inLineDirtyChecking
|| !persister.getEntityMetamodel().isDynamicUpdate()
|| persister.isVersioned();
|| !persister.isDynamicUpdate()
|| persister.isVersioned();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public PersistentAttributeInterceptable createEnhancedProxy(EntityKey entityKey,
}

// inject the interceptor
persister.getEntityMetamodel()
.getBytecodeEnhancementMetadata()
persister.getBytecodeEnhancementMetadata()
.injectEnhancedEntityAsProxyInterceptor( entity, entityKey, session );

return entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ private static <T> boolean cascadeDeleteEnabled(CascadingAction<T> action, Colle

private static <T> boolean cascadeDeleteEnabled(CascadingAction<T> action, EntityPersister persister, int i) {
return action.directionAffectedByCascadeDelete() == ForeignKeyDirection.TO_PARENT
&& persister.getEntityMetamodel().getPropertyOnDeleteActions()[i] == OnDeleteAction.CASCADE;
&& persister.getPropertyOnDeleteActions()[i] == OnDeleteAction.CASCADE;
}

private static <T> boolean cascadeDeleteEnabled(CascadingAction<T> action, CompositeType componentType, int i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void postUpdate(Object entity, Object[] updatedState, Object nextVersion)

if ( persister.isVersioned() ) {
version = nextVersion;
persister.setValue( entity, persister.getVersionProperty(), nextVersion );
persister.setValue( entity, persister.getVersionPropertyIndex(), nextVersion );
}

processIfSelfDirtinessTracker( entity, EntityEntryImpl::clearDirtyAttributes );
Expand Down Expand Up @@ -421,7 +421,7 @@ public boolean isModifiableEntity() {
@Override
public void forceLocked(Object entity, Object nextVersion) {
version = nextVersion;
final int versionProperty = persister.getVersionProperty();
final int versionProperty = persister.getVersionPropertyIndex();
loadedState[versionProperty] = version;
setLockMode( PESSIMISTIC_FORCE_INCREMENT );
persister.setValue( entity, versionProperty, nextVersion );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void checkNullability(final Object[] values, final EntityPersister persis
final boolean[] nullability = persister.getPropertyNullability();
final boolean[] checkability = getCheckability( persister );
final Type[] propertyTypes = persister.getPropertyTypes();
final Generator[] generators = persister.getEntityMetamodel().getGenerators();
final Generator[] generators = persister.getGenerators();
for ( int i = 0; i < values.length; i++ ) {
if ( checkability[i]
&& !unfetched( values[i] )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public Object getNaturalIdSnapshot(Object id, EntityPersister persister) throws
return cachedValue;
}
// check to see if the natural id is mutable/immutable
else if ( persister.getEntityMetamodel().hasImmutableNaturalId() ) {
else if ( persister.hasImmutableNaturalId() ) {
// an immutable natural-id is not retrieved during a normal database-snapshot operation...
final Object naturalIdFromDb = persister.getNaturalIdentifierSnapshot( id, session );
naturalIdResolutions.cacheResolutionFromLoad( id, naturalIdFromDb, persister );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static boolean seedVersion(
Object[] fields,
EntityPersister persister,
SharedSessionContractImplementor session) {
final int versionProperty = persister.getVersionProperty();
final int versionProperty = persister.getVersionPropertyIndex();
final Object initialVersion = fields[versionProperty];
if ( isNullInitialVersion( initialVersion ) ) {
fields[versionProperty] = persister.getVersionGenerator().generate( session, entity, initialVersion, INSERT );
Expand Down Expand Up @@ -150,7 +150,7 @@ public static Object increment(Object version, EntityVersionMapping versionMappi
*/
public static void setVersion(Object[] fields, Object version, EntityPersister persister) {
if ( persister.isVersioned() ) {
fields[ persister.getVersionProperty() ] = version;
fields[ persister.getVersionPropertyIndex() ] = version;
}
}

Expand All @@ -162,7 +162,7 @@ public static void setVersion(Object[] fields, Object version, EntityPersister p
* @return The extracted optimistic locking value
*/
public static Object getVersion(Object[] fields, EntityPersister persister) {
return persister.isVersioned() ? fields[persister.getVersionProperty()] : null;
return persister.isVersioned() ? fields[persister.getVersionPropertyIndex()] : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ else if ( supportsReturning( dialect, timing ) && noCustomSql( persister, timing
}
else if ( timing == EventType.INSERT
&& persister.getNaturalIdentifierProperties() != null
&& !persister.getEntityMetamodel().isNaturalIdentifierInsertGenerated() ) {
&& !persister.isNaturalIdentifierInsertGenerated() ) {
return new UniqueKeySelectingDelegate( persister, getNaturalIdPropertyNames( persister ), timing );
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ else if ( sessionFactoryOptions.isGetGeneratedKeysEnabled() ) {
return dialect.getIdentityColumnSupport().buildGetGeneratedKeysDelegate( persister );
}
else if ( persister.getNaturalIdentifierProperties() != null
&& !persister.getEntityMetamodel().isNaturalIdentifierInsertGenerated() ) {
&& !persister.isNaturalIdentifierInsertGenerated() ) {
return new UniqueKeySelectingDelegate( persister, getNaturalIdPropertyNames( persister ), INSERT );
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static String[] getNaturalIdPropertyNames(EntityPersister persister) {
throw new IdentifierGenerationException( "Entity '" + persister.getEntityName()
+ "' has no '@NaturalId' property" );
}
if ( persister.getEntityMetamodel().isNaturalIdentifierInsertGenerated() ) {
if ( persister.isNaturalIdentifierInsertGenerated() ) {
throw new IdentifierGenerationException( "Entity '" + persister.getEntityName()
+ "' has a '@NaturalId' property which is also defined as insert-generated" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ protected Object versionToUpsert(Object entity, EntityPersister persister, Objec
}
// this is a nonsense but avoids setting version restriction
// parameter to null later on deep in the guts
return state[persister.getVersionProperty()];
return state[persister.getVersionPropertyIndex()];
}
else {
final Object newVersion = incrementVersion( entity, oldVersion, persister, this );
Expand Down Expand Up @@ -1013,8 +1013,7 @@ public Object internalLoad(

// first, check to see if we can use "bytecode proxies"

final var entityMetamodel = persister.getEntityMetamodel();
final var enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
final var enhancementMetadata = persister.getBytecodeEnhancementMetadata();
if ( enhancementMetadata.isEnhancedForLazyLoading() ) {
// if the entity defines a HibernateProxy factory, see if there is an
// existing proxy associated with the PC - and if so, use it
Expand All @@ -1031,14 +1030,14 @@ public Object internalLoad(
}

// specialized handling for entities with subclasses with a HibernateProxy factory
if ( entityMetamodel.hasSubclasses() ) {
if ( persister.hasSubclasses() ) {
// entities with subclasses that define a ProxyFactory can create a HibernateProxy.
LOG.trace( "Creating a HibernateProxy for to-one association with subclasses to honor laziness" );
return createProxy( entityKey );
}
return enhancementMetadata.createEnhancedProxy( entityKey, false, this );
}
else if ( !entityMetamodel.hasSubclasses() ) {
else if ( !persister.hasSubclasses() ) {
return enhancementMetadata.createEnhancedProxy( entityKey, false, this );
}
// If we get here, then the entity class has subclasses and there is no HibernateProxy factory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ private void initializeIfNecessary(Object result) {
}
}
else {
final var enhancementMetadata =
entityPersister.getEntityMetamodel().getBytecodeEnhancementMetadata();
final var enhancementMetadata = entityPersister.getBytecodeEnhancementMetadata();
if ( enhancementMetadata.isEnhancedForLazyLoading()
&& enhancementMetadata.extractLazyInterceptor( result )
instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.spi.EntityInstantiator;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.java.JavaType;

import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
Expand All @@ -20,31 +20,30 @@
* @author Steve Ebersole
*/
public abstract class AbstractEntityInstantiatorPojo extends AbstractPojoInstantiator implements EntityInstantiator {
private final EntityMetamodel entityMetamodel;

private final Class<?> proxyInterface;
private final boolean applyBytecodeInterception;
private final LazyAttributeLoadingInterceptor.EntityRelatedState loadingInterceptorState;

public AbstractEntityInstantiatorPojo(
EntityMetamodel entityMetamodel,
EntityPersister persister,
PersistentClass persistentClass,
JavaType<?> javaType) {
super( javaType.getJavaTypeClass() );
this.entityMetamodel = entityMetamodel;
this.proxyInterface = persistentClass.getProxyInterface();
proxyInterface = persistentClass.getProxyInterface();
//TODO this PojoEntityInstantiator appears to not be reused ?!
this.applyBytecodeInterception =
applyBytecodeInterception =
isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
if ( applyBytecodeInterception ) {
this.loadingInterceptorState = new LazyAttributeLoadingInterceptor.EntityRelatedState(
entityMetamodel.getName(),
entityMetamodel.getBytecodeEnhancementMetadata()
loadingInterceptorState = new LazyAttributeLoadingInterceptor.EntityRelatedState(
persister.getEntityName(),
persister.getBytecodeEnhancementMetadata()
.getLazyAttributesMetadata()
.getLazyAttributeNames()
);
}
else {
this.loadingInterceptorState = null;
loadingInterceptorState = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.java.JavaType;

/**
Expand All @@ -19,11 +19,11 @@ public class EntityInstantiatorPojoOptimized extends AbstractEntityInstantiatorP
private final InstantiationOptimizer instantiationOptimizer;

public EntityInstantiatorPojoOptimized(
EntityMetamodel entityMetamodel,
EntityPersister persister,
PersistentClass persistentClass,
JavaType<?> javaType,
InstantiationOptimizer instantiationOptimizer) {
super( entityMetamodel, persistentClass, javaType );
super( persister, persistentClass, javaType );
this.instantiationOptimizer = instantiationOptimizer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.java.JavaType;

import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
Expand All @@ -31,23 +31,23 @@ public class EntityInstantiatorPojoStandard extends AbstractEntityInstantiatorPo
private final Constructor<?> constructor;

public EntityInstantiatorPojoStandard(
EntityMetamodel entityMetamodel,
EntityPersister persister,
PersistentClass persistentClass,
JavaType<?> javaType) {
super( entityMetamodel, persistentClass, javaType );
super( persister, persistentClass, javaType );
proxyInterface = persistentClass.getProxyInterface();
constructor = isAbstract() ? null : resolveConstructor( getMappedPojoClass() );
applyBytecodeInterception = isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
if ( applyBytecodeInterception ) {
this.loadingInterceptorState = new LazyAttributeLoadingInterceptor.EntityRelatedState(
entityMetamodel.getName(),
entityMetamodel.getBytecodeEnhancementMetadata()
loadingInterceptorState = new LazyAttributeLoadingInterceptor.EntityRelatedState(
persister.getEntityName(),
persister.getBytecodeEnhancementMetadata()
.getLazyAttributesMetadata()
.getLazyAttributeNames()
);
}
else {
this.loadingInterceptorState = null;
loadingInterceptorState = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public EntityRepresentationStrategyPojoStandard(
propertyAccessMap = buildPropertyAccessMap( bootDescriptor );
reflectionOptimizer = resolveReflectionOptimizer( bytecodeProvider );

instantiator = determineInstantiator( bootDescriptor, runtimeDescriptor.getEntityMetamodel() );
instantiator = determineInstantiator( bootDescriptor, runtimeDescriptor );
}

private ProxyFactory resolveProxyFactory(
Expand All @@ -141,11 +141,10 @@ private ProxyFactory resolveProxyFactory(
return null;
}
else {
final var entityMetamodel = entityPersister.getEntityMetamodel();
if ( proxyJavaType != null && entityMetamodel.isLazy() ) {
if ( proxyJavaType != null && entityPersister.isLazy() ) {
final var proxyFactory = createProxyFactory( bootDescriptor, bytecodeProvider, creationContext );
if ( proxyFactory == null ) {
entityMetamodel.setLazy( false );
((EntityMetamodel) entityPersister).setLazy( false );
}
return proxyFactory;
}
Expand All @@ -163,17 +162,17 @@ private Map<String, PropertyAccess> buildPropertyAccessMap(PersistentClass bootD
return propertyAccessMap;
}

private EntityInstantiator determineInstantiator(PersistentClass bootDescriptor, EntityMetamodel entityMetamodel) {
private EntityInstantiator determineInstantiator(PersistentClass bootDescriptor, EntityPersister persister) {
if ( reflectionOptimizer != null && reflectionOptimizer.getInstantiationOptimizer() != null ) {
return new EntityInstantiatorPojoOptimized(
entityMetamodel,
persister,
bootDescriptor,
mappedJtd,
reflectionOptimizer.getInstantiationOptimizer()
);
}
else {
return new EntityInstantiatorPojoStandard( entityMetamodel, bootDescriptor, mappedJtd );
return new EntityInstantiatorPojoStandard( persister, bootDescriptor, mappedJtd );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ default int getJdbcTypeCount() {
* Whether this entity is defined as abstract using the Java {@code abstract} keyword
*/
default boolean isAbstract() {
return getEntityPersister().getEntityMetamodel().isAbstract();
return getEntityPersister().isAbstract();
}

/**
* Whether this entity mapping has any subtype mappings
*/
default boolean hasSubclasses() {
return getEntityPersister().getEntityMetamodel().hasSubclasses();
return getEntityPersister().hasSubclasses();
}

/**
Expand Down Expand Up @@ -221,11 +221,11 @@ default boolean isTypeOrSuperType(ManagedMappingType targetType) {
* inheritance hierarchy
*/
default int getSubclassId() {
return getEntityPersister().getEntityMetamodel().getSubclassId();
return getEntityPersister().getSubclassId();
}

default Set<String> getSubclassEntityNames() {
return getEntityPersister().getEntityMetamodel().getSubclassEntityNames();
return getEntityPersister().getSubclassEntityNames();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping ori

@Override
public Generator getGenerator() {
return findContainingEntityMapping().getEntityPersister().getEntityMetamodel().getGenerators()[getStateArrayPosition()];
return findContainingEntityMapping().getEntityPersister().getGenerators()[getStateArrayPosition()];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ private static boolean isSubsequentSelectDelayed(AssociationType type, SessionFa
return false;
}
else if ( type instanceof EntityType ) {
final EntityPersister entityPersister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
return entityPersister.getEntityMetamodel().isLazy();
final var entityPersister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
return entityPersister.isLazy();
}
else {
final CollectionPersister cp = ( (CollectionPersister) type.getAssociatedJoinable( sessionFactory ) );
return cp.isLazy() || cp.isExtraLazy();
final var collectionPersister = (CollectionPersister) type.getAssociatedJoinable( sessionFactory );
return collectionPersister.isLazy() || collectionPersister.isExtraLazy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private int numberOfGeneratedNonIdentifierProperties(EventType timing) {
public static List<AttributeMapping> getGeneratedAttributes(EntityMappingType entityDescriptor, EventType timing) {
// 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 Generator[] generators = entityDescriptor.getEntityPersister().getEntityMetamodel().getGenerators();
final Generator[] generators = entityDescriptor.getEntityPersister().getGenerators();
final List<AttributeMapping> generatedValuesToSelect = new ArrayList<>();
entityDescriptor.forEachAttributeMapping( mapping -> {
final Generator generator = generators[ mapping.getStateArrayPosition() ];
Expand Down
Loading
Loading