From 20e7f1be9caf647a81cc11328ee57859b957ea01 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Tue, 13 Dec 2022 17:07:03 +0000 Subject: [PATCH] HHH-15761 Change some scopes for Hibernate Reactive Make it possible for Hibernate Reactive to call or override some methods. --- .../CollectionLoaderSubSelectFetch.java | 4 ++++ .../entity/AbstractEntityPersister.java | 6 ++--- .../entity/mutation/DeleteCoordinator.java | 12 +++++----- .../entity/mutation/InsertCoordinator.java | 18 ++++++++------ .../mutation/UpdateCoordinatorStandard.java | 24 ++++++++++++------- .../query/sql/internal/NativeQueryImpl.java | 8 +++++-- .../sqm/internal/SimpleDeleteQueryPlan.java | 2 +- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CollectionLoaderSubSelectFetch.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CollectionLoaderSubSelectFetch.java index 83f6a96a2f..b60b7455e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CollectionLoaderSubSelectFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CollectionLoaderSubSelectFetch.java @@ -72,6 +72,10 @@ public class CollectionLoaderSubSelectFetch implements CollectionLoader { return attributeMapping; } + protected SelectStatement getSqlAst() { + return sqlAst; + } + @Override public PersistentCollection load(Object triggerKey, SharedSessionContractImplementor session) { final CollectionKey collectionKey = new CollectionKey( attributeMapping.getCollectionDescriptor(), triggerKey ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 43c204d7e6..41a46ca4e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -3293,11 +3293,11 @@ public abstract class AbstractEntityPersister protected abstract boolean isIdentifierTable(String tableExpression); - private InsertCoordinator buildInsertCoordinator() { + protected InsertCoordinator buildInsertCoordinator() { return new InsertCoordinator( this, factory ); } - private UpdateCoordinator buildUpdateCoordinator() { + protected UpdateCoordinator buildUpdateCoordinator() { // we only have updates to issue for entities with one or more singular attributes for ( AttributeMapping attributeMapping : attributeMappings ) { if ( attributeMapping instanceof SingularAttributeMapping ) { @@ -3309,7 +3309,7 @@ public abstract class AbstractEntityPersister return new UpdateCoordinatorNoOp( this ); } - private DeleteCoordinator buildDeleteCoordinator() { + protected DeleteCoordinator buildDeleteCoordinator() { return new DeleteCoordinator( this, factory ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java index 3f3a7ae37b..1848c25727 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java @@ -83,7 +83,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { } } - private void doDynamicDelete( + protected void doDynamicDelete( Object entity, Object id, Object rowId, @@ -134,7 +134,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { } } - private void applyLocking( + protected void applyLocking( Object version, Object[] loadedState, MutationExecutor mutationExecutor, @@ -205,7 +205,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { } } - private void applyId( + protected void applyId( Object id, Object rowId, MutationExecutor mutationExecutor, @@ -250,7 +250,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { } ); } - private void doStaticDelete( + protected void doStaticDelete( Object entity, Object id, Object version, @@ -308,7 +308,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { mutationExecutor.release(); } - private MutationOperationGroup resolveNoVersionDeleteGroup(SharedSessionContractImplementor session) { + protected MutationOperationGroup resolveNoVersionDeleteGroup(SharedSessionContractImplementor session) { if ( noVersionDeleteGroup == null ) { noVersionDeleteGroup = generateOperationGroup( null, false, session ); } @@ -316,7 +316,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { return noVersionDeleteGroup; } - private MutationOperationGroup generateOperationGroup( + protected MutationOperationGroup generateOperationGroup( Object[] loadedState, boolean applyVersion, SharedSessionContractImplementor session) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java index aa06959bdf..380f91e040 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java @@ -72,6 +72,10 @@ public class InsertCoordinator extends AbstractMutationCoordinator { return staticInsertGroup; } + public BasicBatchKey getInsertBatchKey() { + return insertBatchKey; + } + /** * Perform the insert(s). * @@ -116,7 +120,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { } } - private static class InsertValuesAnalysis implements ValuesAnalysis { + protected static class InsertValuesAnalysis implements ValuesAnalysis { private final List tablesWithNonNullValues = new ArrayList<>(); public InsertValuesAnalysis(EntityMutationTarget mutationTarget, Object[] values) { @@ -136,7 +140,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { } } - private Object doStaticInserts(Object id, Object[] values, Object object, SharedSessionContractImplementor session) { + protected Object doStaticInserts(Object id, Object[] values, Object object, SharedSessionContractImplementor session) { final InsertValuesAnalysis insertValuesAnalysis = new InsertValuesAnalysis( entityPersister(), values ); final TableInclusionChecker tableInclusionChecker = getTableInclusionChecker( insertValuesAnalysis ); @@ -183,7 +187,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { } } - private void decomposeForInsert( + protected void decomposeForInsert( MutationExecutor mutationExecutor, Object id, Object[] values, @@ -259,7 +263,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { } ); } - private Object doDynamicInserts(Object id, Object[] values, Object object, SharedSessionContractImplementor session) { + protected Object doDynamicInserts(Object id, Object[] values, Object object, SharedSessionContractImplementor session) { final boolean[] insertability = getPropertiesToInsert( values ); final MutationOperationGroup insertGroup = generateDynamicInsertSqlGroup( insertability ); @@ -301,8 +305,8 @@ public class InsertCoordinator extends AbstractMutationCoordinator { } } - private static TableInclusionChecker getTableInclusionChecker(InsertValuesAnalysis insertValuesAnalysis) { - return (tableMapping) -> !tableMapping.isOptional() || insertValuesAnalysis.hasNonNullBindings( tableMapping ); + protected static TableInclusionChecker getTableInclusionChecker(InsertValuesAnalysis insertValuesAnalysis) { + return tableMapping -> !tableMapping.isOptional() || insertValuesAnalysis.hasNonNullBindings( tableMapping ); } @@ -319,7 +323,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { return notNull; } - private MutationOperationGroup generateDynamicInsertSqlGroup(boolean[] insertable) { + protected MutationOperationGroup generateDynamicInsertSqlGroup(boolean[] insertable) { assert entityPersister().getEntityMetamodel().isDynamicInsert(); final MutationGroupBuilder insertGroupBuilder = new MutationGroupBuilder( MutationType.INSERT, entityPersister() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java index 1d21affba7..a35551898a 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java @@ -101,6 +101,14 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple return staticUpdateGroup; } + protected MutationOperationGroup getVersionUpdateGroup() { + return versionUpdateGroup; + } + + protected BatchKey getBatchKey() { + return batchKey; + } + public final boolean isModifiableEntity(EntityEntry entry) { return ( entry == null ? entityPersister().isMutable() : entry.isModifiableEntity() ); } @@ -361,7 +369,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple : entityPersister().getPropertyUpdateability(); } - private void doVersionUpdate( + protected void doVersionUpdate( Object entity, Object id, Object version, @@ -612,7 +620,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple } } - private void doStaticUpdate( + protected void doStaticUpdate( Object entity, Object id, Object rowId, @@ -663,7 +671,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple } } - private void decomposeForUpdate( + protected void decomposeForUpdate( Object id, Object rowId, Object[] values, @@ -789,7 +797,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple } ); } - private void doDynamicUpdate( + protected void doDynamicUpdate( Object entity, Object id, Object rowId, @@ -866,7 +874,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple } } - private MutationOperationGroup generateDynamicUpdateGroup( + protected MutationOperationGroup generateDynamicUpdateGroup( Object id, Object rowId, Object[] oldValues, @@ -1041,7 +1049,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple * what SQL UPDATE statement(s) should be used to update the entity * and to drive parameter binding */ - private class UpdateValuesAnalysisImpl implements UpdateValuesAnalysis { + protected class UpdateValuesAnalysisImpl implements UpdateValuesAnalysis { private final Object[] values; private final int[] dirtyAttributeIndexes; private final InclusionChecker dirtinessChecker; @@ -1451,12 +1459,12 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple } @FunctionalInterface - private interface InclusionChecker { + protected interface InclusionChecker { boolean include(int position, SingularAttributeMapping attribute); } @FunctionalInterface - private interface DirtinessChecker { + protected interface DirtinessChecker { boolean isDirty(int position, AttributeMapping attribute); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index c245187529..305e3f11aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -343,6 +343,10 @@ public class NativeQueryImpl this.resultMappingSuppliedToCtor = true; } + public List getParameterOccurrences() { + return parameterOccurrences; + } + private ParameterInterpretation resolveParameterInterpretation( String sqlString, SharedSessionContractImplementor session) { @@ -614,7 +618,7 @@ public class NativeQueryImpl return resolveSelectQueryPlan().performList( this ); } - private SelectQueryPlan resolveSelectQueryPlan() { + protected SelectQueryPlan resolveSelectQueryPlan() { if ( isCacheableQuery() ) { final QueryInterpretationCache.Key cacheKey = generateSelectInterpretationsKey( resultSetMapping ); return getSession().getFactory().getQueryEngine().getInterpretationCache() @@ -659,7 +663,7 @@ public class NativeQueryImpl .createQueryPlan( queryDefinition, getSessionFactory() ); } - private String expandParameterLists() { + protected String expandParameterLists() { if ( parameterOccurrences == null || parameterOccurrences.isEmpty() ) { return sqlString; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java index 41b177430a..48e87b5ede 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java @@ -63,7 +63,7 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan { this.domainParameterXref = domainParameterXref; } - private SqlAstTranslator createDeleteTranslator(DomainQueryExecutionContext executionContext) { + protected SqlAstTranslator createDeleteTranslator(DomainQueryExecutionContext executionContext) { final SessionFactoryImplementor factory = executionContext.getSession().getFactory(); final QueryEngine queryEngine = factory.getQueryEngine();