HHH-16242 Change scopes in AbstractEntityInitializer

and add getters/setters.

Hibernate Reactive needs custom initializers
This commit is contained in:
Davide D'Alto 2023-03-01 10:16:27 +00:00 committed by Christian Beikov
parent 353d24c7a2
commit 79c03e784c
1 changed files with 47 additions and 11 deletions

View File

@ -455,7 +455,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
return false; return false;
} }
private void resolveEntityInstance( protected void resolveEntityInstance(
RowProcessingState rowProcessingState, RowProcessingState rowProcessingState,
LoadingEntityEntry existingLoadingEntry, LoadingEntityEntry existingLoadingEntry,
Object entityIdentifier) { Object entityIdentifier) {
@ -593,6 +593,10 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
protected boolean isOwningInitializer() {
return isOwningInitializer;
}
private Object resolveInstance( private Object resolveInstance(
Object entityIdentifier, Object entityIdentifier,
LoadingEntityEntry existingLoadingEntry, LoadingEntityEntry existingLoadingEntry,
@ -615,7 +619,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private Object resolveEntityInstance(Object entityIdentifier, RowProcessingState rowProcessingState) { protected Object resolveEntityInstance(Object entityIdentifier, RowProcessingState rowProcessingState) {
final Object resolved = resolveToOptionalInstance( rowProcessingState ); final Object resolved = resolveToOptionalInstance( rowProcessingState );
if ( resolved != null ) { if ( resolved != null ) {
registerLoadingEntity( rowProcessingState, resolved ); registerLoadingEntity( rowProcessingState, resolved );
@ -638,7 +642,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private Object instantiateEntity(Object entityIdentifier, SharedSessionContractImplementor session) { protected Object instantiateEntity(Object entityIdentifier, SharedSessionContractImplementor session) {
final Object instance = session.instantiate( concreteDescriptor.getEntityName(), entityKey.getIdentifier() ); final Object instance = session.instantiate( concreteDescriptor.getEntityName(), entityKey.getIdentifier() );
if ( EntityLoadingLogging.DEBUG_ENABLED ) { if ( EntityLoadingLogging.DEBUG_ENABLED ) {
EntityLoadingLogging.ENTITY_LOADING_LOGGER.debugf( EntityLoadingLogging.ENTITY_LOADING_LOGGER.debugf(
@ -728,7 +732,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private boolean consistentInstance(Object toInitialize, RowProcessingState rowProcessingState) { protected boolean consistentInstance(Object toInitialize, RowProcessingState rowProcessingState) {
final PersistenceContext persistenceContextInternal = final PersistenceContext persistenceContextInternal =
rowProcessingState.getSession().getPersistenceContextInternal(); rowProcessingState.getSession().getPersistenceContextInternal();
// Only call PersistenceContext#getEntity within the assert expression, as it is costly // Only call PersistenceContext#getEntity within the assert expression, as it is costly
@ -815,7 +819,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private void updateCaches( protected void updateCaches(
Object toInitialize, Object toInitialize,
RowProcessingState rowProcessingState, RowProcessingState rowProcessingState,
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
@ -829,7 +833,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private void registerNaturalIdResolution(PersistenceContext persistenceContext, Object entityIdentifier) { protected void registerNaturalIdResolution(PersistenceContext persistenceContext, Object entityIdentifier) {
if ( entityDescriptor.getNaturalIdMapping() != null ) { if ( entityDescriptor.getNaturalIdMapping() != null ) {
final Object naturalId = final Object naturalId =
entityDescriptor.getNaturalIdMapping().extractNaturalIdFromEntityState( resolvedEntityState ); entityDescriptor.getNaturalIdMapping().extractNaturalIdFromEntityState( resolvedEntityState );
@ -838,7 +842,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private void takeSnapshot( protected void takeSnapshot(
RowProcessingState rowProcessingState, RowProcessingState rowProcessingState,
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
PersistenceContext persistenceContext, PersistenceContext persistenceContext,
@ -938,7 +942,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private void registerPossibleUniqueKeyEntries(Object toInitialize, SharedSessionContractImplementor session) { protected void registerPossibleUniqueKeyEntries(Object toInitialize, SharedSessionContractImplementor session) {
for ( Type propertyType : concreteDescriptor.getPropertyTypes() ) { for ( Type propertyType : concreteDescriptor.getPropertyTypes() ) {
if ( propertyType instanceof AssociationType ) { if ( propertyType instanceof AssociationType ) {
final AssociationType associationType = (AssociationType) propertyType; final AssociationType associationType = (AssociationType) propertyType;
@ -968,7 +972,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private Object[] extractConcreteTypeStateValues(RowProcessingState rowProcessingState) { protected Object[] extractConcreteTypeStateValues(RowProcessingState rowProcessingState) {
final Object[] values = new Object[concreteDescriptor.getNumberOfAttributeMappings()]; final Object[] values = new Object[concreteDescriptor.getNumberOfAttributeMappings()];
final DomainResultAssembler<?>[] concreteAssemblers = assemblers[concreteDescriptor.getSubclassId()]; final DomainResultAssembler<?>[] concreteAssemblers = assemblers[concreteDescriptor.getSubclassId()];
for ( int i = 0; i < values.length; i++ ) { for ( int i = 0; i < values.length; i++ ) {
@ -978,7 +982,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
return values; return values;
} }
private boolean skipInitialization(Object toInitialize, RowProcessingState rowProcessingState) { protected boolean skipInitialization(Object toInitialize, RowProcessingState rowProcessingState) {
final EntityEntry entry = final EntityEntry entry =
rowProcessingState.getSession().getPersistenceContextInternal().getEntry( toInitialize ); rowProcessingState.getSession().getPersistenceContextInternal().getEntry( toInitialize );
if ( entry == null ) { if ( entry == null ) {
@ -1022,7 +1026,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
return readOnly == null ? persistenceContext.isDefaultReadOnly() : readOnly; return readOnly == null ? persistenceContext.isDefaultReadOnly() : readOnly;
} }
private void preLoad(RowProcessingState rowProcessingState) { protected void preLoad(RowProcessingState rowProcessingState) {
final SharedSessionContractImplementor session = rowProcessingState.getSession(); final SharedSessionContractImplementor session = rowProcessingState.getSession();
if ( session.isEventSource() ) { if ( session.isEventSource() ) {
final PreLoadEvent preLoadEvent = rowProcessingState.getJdbcValuesSourceProcessingState().getPreLoadEvent(); final PreLoadEvent preLoadEvent = rowProcessingState.getJdbcValuesSourceProcessingState().getPreLoadEvent();
@ -1046,11 +1050,43 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
return isInitialized; return isInitialized;
} }
protected void setEntityInitialized(boolean isInitialized) {
this.isInitialized = isInitialized;
}
protected void setEntityInstanceForNotify(Object entityInstanceForNotify) {
this.entityInstanceForNotify = entityInstanceForNotify;
}
protected Object getEntityInstanceForNotify() {
return entityInstanceForNotify;
}
protected void setResolvedEntityState(Object[] resolvedEntityState) {
this.resolvedEntityState = resolvedEntityState;
}
protected Object[] getResolvedEntityState() {
return resolvedEntityState;
}
@Override @Override
public EntityPersister getConcreteDescriptor() { public EntityPersister getConcreteDescriptor() {
return concreteDescriptor == null ? entityDescriptor : concreteDescriptor; return concreteDescriptor == null ? entityDescriptor : concreteDescriptor;
} }
protected DomainResultAssembler<?> getVersionAssembler() {
return versionAssembler;
}
protected DomainResultAssembler<Object> getRowIdAssembler() {
return rowIdAssembler;
}
protected LockMode getLockMode() {
return lockMode;
}
@Override @Override
public void finishUpRow(RowProcessingState rowProcessingState) { public void finishUpRow(RowProcessingState rowProcessingState) {
// reset row state // reset row state