HHH-14474 Refactor internal visibility to allow Hibernate Reactive to implement non-primary key associations

see https://github.com/hibernate/hibernate-reactive/issues/565
This commit is contained in:
Gavin King 2021-02-14 01:42:49 +01:00 committed by Sanne Grinovero
parent 6868c68278
commit 4fad616d4b
4 changed files with 25 additions and 5 deletions

View File

@ -61,6 +61,11 @@ public abstract class AbstractEntityLoader
return load( session, id, optionalObject, id, lockOptions, readOnly ); return load( session, id, optionalObject, id, lockOptions, readOnly );
} }
@Override
public Object load(Object id, SharedSessionContractImplementor session, LockOptions lockOptions) {
return load( session, id, null, null, lockOptions, null );
}
protected Object load( protected Object load(
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
Object id, Object id,

View File

@ -172,10 +172,18 @@ public class EntityLoader extends AbstractEntityLoader {
} }
} }
/**
* @deprecated will be removed. Use one of the load methods on {@link AbstractEntityLoader} instead.
*/
@Deprecated
public Object loadByUniqueKey(SharedSessionContractImplementor session, Object key) { public Object loadByUniqueKey(SharedSessionContractImplementor session, Object key) {
return loadByUniqueKey( session, key, null ); return loadByUniqueKey( session, key, null );
} }
/**
* @deprecated will be removed. Use one of the load methods on {@link AbstractEntityLoader} instead.
*/
@Deprecated
public Object loadByUniqueKey(SharedSessionContractImplementor session, Object key, Boolean readOnly) { public Object loadByUniqueKey(SharedSessionContractImplementor session, Object key, Boolean readOnly) {
return load( session, key, null, null, LockOptions.NONE, readOnly ); return load( session, key, null, null, LockOptions.NONE, readOnly );
} }

View File

@ -60,4 +60,11 @@ public interface UniqueEntityLoader {
Boolean readOnly) { Boolean readOnly) {
return load( id, optionalObject, session, lockOptions ); return load( id, optionalObject, session, lockOptions );
} }
default Object load(
Object id,
SharedSessionContractImplementor session,
LockOptions lockOptions) {
throw new UnsupportedOperationException();
}
} }

View File

@ -256,7 +256,7 @@ public abstract class AbstractEntityPersister
private final EntityLoaderLazyCollection loaders = new EntityLoaderLazyCollection(); private final EntityLoaderLazyCollection loaders = new EntityLoaderLazyCollection();
private volatile Map<String,EntityLoader> uniqueKeyLoaders; private volatile Map<String,UniqueEntityLoader> uniqueKeyLoaders;
private volatile Map<LockMode,EntityLoader> naturalIdLoaders; private volatile Map<LockMode,EntityLoader> naturalIdLoaders;
// SQL strings // SQL strings
@ -2480,7 +2480,7 @@ public abstract class AbstractEntityPersister
Object uniqueKey, Object uniqueKey,
SharedSessionContractImplementor session) throws HibernateException { SharedSessionContractImplementor session) throws HibernateException {
return getAppropriateUniqueKeyLoader( propertyName, session ) return getAppropriateUniqueKeyLoader( propertyName, session )
.loadByUniqueKey( session, uniqueKey ); .load( uniqueKey, session, LockOptions.NONE );
} }
public Object loadByNaturalId( public Object loadByNaturalId(
@ -2488,7 +2488,7 @@ public abstract class AbstractEntityPersister
LockOptions lockOptions, LockOptions lockOptions,
SharedSessionContractImplementor session) throws HibernateException { SharedSessionContractImplementor session) throws HibernateException {
return getAppropriateNaturalIdLoader( determineValueNullness( naturalIdValues ), lockOptions, session ) return getAppropriateNaturalIdLoader( determineValueNullness( naturalIdValues ), lockOptions, session )
.loadByUniqueKey( session, naturalIdValues ); .load( naturalIdValues, session, LockOptions.NONE );
} }
private EntityLoader getAppropriateNaturalIdLoader( private EntityLoader getAppropriateNaturalIdLoader(
@ -2511,7 +2511,7 @@ public abstract class AbstractEntityPersister
&& !loadQueryInfluencers.hasEnabledFetchProfiles(); && !loadQueryInfluencers.hasEnabledFetchProfiles();
} }
private EntityLoader getAppropriateUniqueKeyLoader( private UniqueEntityLoader getAppropriateUniqueKeyLoader(
String propertyName, String propertyName,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers(); LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
@ -2560,7 +2560,7 @@ public abstract class AbstractEntityPersister
} }
} }
private EntityLoader createUniqueKeyLoader( protected UniqueEntityLoader createUniqueKeyLoader(
Type uniqueKeyType, Type uniqueKeyType,
String[] columns, String[] columns,
LoadQueryInfluencers loadQueryInfluencers) { LoadQueryInfluencers loadQueryInfluencers) {