minor code changes (use of final)

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-06-04 14:04:35 +02:00
parent 1a93a081e1
commit 7b9b495f31
2 changed files with 21 additions and 21 deletions

View File

@ -419,7 +419,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
} }
else { else {
//otherwise recreate the mapping between the collection and its key //otherwise recreate the mapping between the collection and its key
CollectionKey collectionKey = new CollectionKey( final CollectionKey collectionKey = new CollectionKey(
collectionEntry.getLoadedPersister(), collectionEntry.getLoadedPersister(),
collectionEntry.getLoadedKey() collectionEntry.getLoadedKey()
); );

View File

@ -494,10 +494,11 @@ public abstract class EntityType extends AbstractType implements AssociationType
if ( type.isEntityType() ) { if ( type.isEntityType() ) {
return ( (EntityType) type ).getIdentifier( propertyValue, session ); return ( (EntityType) type ).getIdentifier( propertyValue, session );
} }
else {
return propertyValue; return propertyValue;
} }
} }
}
protected final Object getIdentifier(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException { protected final Object getIdentifier(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
if ( isReferenceToIdentifierProperty() ) { if ( isReferenceToIdentifierProperty() ) {
@ -509,19 +510,20 @@ public abstract class EntityType extends AbstractType implements AssociationType
return null; return null;
} }
else { else {
EntityPersister entityPersister = getAssociatedEntityPersister( sessionFactory ); final EntityPersister entityPersister = getAssociatedEntityPersister( sessionFactory );
Object propertyValue = entityPersister.getPropertyValue( value, uniqueKeyPropertyName ); final Object propertyValue = entityPersister.getPropertyValue( value, uniqueKeyPropertyName );
// We now have the value of the property-ref we reference. However, // We now have the value of the property-ref we reference. However,
// we need to dig a little deeper, as that property might also be // we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identifier // an entity type, in which case we need to resolve its identifier
Type type = entityPersister.getPropertyType( uniqueKeyPropertyName ); final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type.isEntityType() ) {
propertyValue = ( (EntityType) type ).getIdentifier( propertyValue, sessionFactory ); return ( (EntityType) type ).getIdentifier( propertyValue, sessionFactory );
} }
else {
return propertyValue; return propertyValue;
} }
} }
}
/** /**
* Generate a loggable representation of an instance of the value mapped by this type. * Generate a loggable representation of an instance of the value mapped by this type.
@ -638,13 +640,15 @@ public abstract class EntityType extends AbstractType implements AssociationType
return getIdentifierType( factory ); return getIdentifierType( factory );
} }
else { else {
Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); final Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type.isEntityType() ) {
type = ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory ); return ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory );
} }
else {
return type; return type;
} }
} }
}
/** /**
* The name of the property on the associated entity to which our FK * The name of the property on the associated entity to which our FK
@ -687,16 +691,12 @@ public abstract class EntityType extends AbstractType implements AssociationType
*/ */
protected final Object resolveIdentifier(Object id, SharedSessionContractImplementor session, Boolean overridingEager) throws HibernateException { protected final Object resolveIdentifier(Object id, SharedSessionContractImplementor session, Boolean overridingEager) throws HibernateException {
boolean isProxyUnwrapEnabled = unwrapProxy && final boolean isProxyUnwrapEnabled = unwrapProxy &&
getAssociatedEntityPersister( session.getFactory() ) getAssociatedEntityPersister( session.getFactory() )
.isInstrumented(); .isInstrumented();
Object proxyOrEntity = session.internalLoad( final Object proxyOrEntity =
getAssociatedEntityName(), session.internalLoad( getAssociatedEntityName(), id, isEager( overridingEager ), isNullable() );
id,
isEager( overridingEager ),
isNullable()
);
final LazyInitializer lazyInitializer = extractLazyInitializer( proxyOrEntity ); final LazyInitializer lazyInitializer = extractLazyInitializer( proxyOrEntity );
if ( lazyInitializer != null ) { if ( lazyInitializer != null ) {
@ -732,14 +732,14 @@ public abstract class EntityType extends AbstractType implements AssociationType
Object key, Object key,
SharedSessionContractImplementor session) throws HibernateException { SharedSessionContractImplementor session) throws HibernateException {
final SessionFactoryImplementor factory = session.getFactory(); final SessionFactoryImplementor factory = session.getFactory();
UniqueKeyLoadable persister = (UniqueKeyLoadable) factory final UniqueKeyLoadable persister = (UniqueKeyLoadable) factory
.getRuntimeMetamodels() .getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( entityName ); .getEntityDescriptor( entityName );
//TODO: implement 2nd level caching?! natural id caching ?! proxies?! //TODO: implement 2nd level caching?! natural id caching ?! proxies?!
EntityUniqueKey euk = new EntityUniqueKey( final EntityUniqueKey euk = new EntityUniqueKey(
entityName, entityName,
uniqueKeyPropertyName, uniqueKeyPropertyName,
key, key,