From 5380316ba76693d5c44d0007980640d4fd80e522 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 1 Jun 2023 11:48:28 +0100 Subject: [PATCH 1/6] Upgrade to Hibernate ORM 6.2.4.Final --- README.md | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b1f05987..136d743f4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Hibernate Reactive has been tested with: - CockroachDB 22.1 - MS SQL Server 2019 - Oracle 21.3 -- [Hibernate ORM][] 6.2.3.Final +- [Hibernate ORM][] 6.2.4.Final - [Vert.x Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) 4.4.2 - [Vert.x Reactive MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/) 4.4.2 - [Vert.x Reactive Db2 Client](https://vertx.io/docs/vertx-db2-client/java/) 4.4.2 diff --git a/build.gradle b/build.gradle index e8a538b0a..aad7dfbf2 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ version = projectVersion // ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT ext { if ( !project.hasProperty('hibernateOrmVersion') ) { - hibernateOrmVersion = '6.2.3.Final' + hibernateOrmVersion = '6.2.4.Final' } if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) { // Same as ORM as default From e857a21c39ce9f36ea5e22333da9fe9940860fa0 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 26 May 2023 10:10:30 +0100 Subject: [PATCH 2/6] Migration from List to JdbcParametersList types --- .../ast/internal/DatabaseSnapshotExecutor.java | 12 ++++++------ .../ReactiveCollectionBatchLoaderArrayParam.java | 4 ++-- .../ReactiveCollectionBatchLoaderInPredicate.java | 10 +++++----- .../internal/ReactiveCollectionLoaderSingleKey.java | 13 ++++++------- .../ReactiveEntityBatchLoaderInPredicate.java | 9 +++++---- .../loader/ast/internal/ReactiveLoaderHelper.java | 4 ++-- .../ReactiveMultiIdEntityLoaderArrayParam.java | 4 ++-- .../ReactiveMultiIdEntityLoaderStandard.java | 8 ++++---- .../ast/internal/ReactiveMultiKeyLoadChunker.java | 7 +++---- .../internal/ReactiveNaturalIdLoaderDelegate.java | 9 ++++----- .../ast/internal/ReactiveSingleIdArrayLoadPlan.java | 5 ++--- .../ReactiveSingleIdEntityLoaderStandardImpl.java | 9 ++++----- .../ast/internal/ReactiveSingleIdLoadPlan.java | 4 ++-- ...ReactiveSingleUniqueKeyEntityLoaderStandard.java | 13 +++++++------ .../impl/ReactiveAbstractEntityPersister.java | 7 ++++--- .../impl/ReactiveGeneratedValuesProcessor.java | 6 +++--- .../iternal/ConcreteSqmSelectReactiveQueryPlan.java | 12 ++++++------ .../sqm/iternal/ReactiveSimpleDeleteQueryPlan.java | 4 ++-- .../sqm/iternal/ReactiveSimpleInsertQueryPlan.java | 4 ++-- .../sqm/iternal/ReactiveSimpleUpdateQueryPlan.java | 4 ++-- 20 files changed, 73 insertions(+), 75 deletions(-) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/DatabaseSnapshotExecutor.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/DatabaseSnapshotExecutor.java index 625a64d25..077c62c97 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/DatabaseSnapshotExecutor.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/DatabaseSnapshotExecutor.java @@ -40,6 +40,7 @@ import org.hibernate.sql.exec.internal.JdbcParameterImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.internal.ImmutableFetchList; @@ -57,15 +58,14 @@ class DatabaseSnapshotExecutor { private final EntityMappingType entityDescriptor; private final JdbcOperationQuerySelect jdbcSelect; - private final List jdbcParameters; + private final JdbcParametersList jdbcParameters; DatabaseSnapshotExecutor( EntityMappingType entityDescriptor, SessionFactoryImplementor sessionFactory) { this.entityDescriptor = entityDescriptor; - this.jdbcParameters = new ArrayList<>( - entityDescriptor.getIdentifierMapping().getJdbcTypeCount() - ); + JdbcParametersList.Builder jdbcParametersBuilder = JdbcParametersList.newBuilder( + entityDescriptor.getIdentifierMapping().getJdbcTypeCount() ); final QuerySpec rootQuerySpec = new QuerySpec( true ); @@ -118,7 +118,7 @@ class DatabaseSnapshotExecutor { ); final JdbcParameter jdbcParameter = new JdbcParameterImpl( selection.getJdbcMapping() ); - jdbcParameters.add( jdbcParameter ); + jdbcParametersBuilder.add( jdbcParameter ); final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver .resolveSqlExpression( tableReference, selection ); @@ -132,7 +132,7 @@ class DatabaseSnapshotExecutor { ); } ); - + this.jdbcParameters = jdbcParametersBuilder.build(); entityDescriptor.forEachAttributeMapping( attributeMapping -> { diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderArrayParam.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderArrayParam.java index 6d4a7bcf2..4185d3646 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderArrayParam.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderArrayParam.java @@ -6,7 +6,6 @@ package org.hibernate.reactive.loader.ast.internal; import java.lang.reflect.Array; -import java.util.Collections; import java.util.concurrent.CompletionStage; import org.hibernate.LockOptions; @@ -33,6 +32,7 @@ import org.hibernate.sql.exec.internal.JdbcParameterImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; import org.hibernate.type.BasicType; @@ -145,7 +145,7 @@ private CompletionStage initializeKeys(Object[] keysToInitialize, SharedSe final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler = SubselectFetch.createRegistrationHandler( session.getPersistenceContext().getBatchFetchQueue(), sqlSelect, - Collections.singletonList( jdbcParameter ), + JdbcParametersList.singleton( jdbcParameter ), jdbcParameterBindings ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderInPredicate.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderInPredicate.java index 8d0aac6c9..92a995620 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderInPredicate.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionBatchLoaderInPredicate.java @@ -6,7 +6,6 @@ package org.hibernate.reactive.loader.ast.internal; import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CompletionStage; import org.hibernate.LockOptions; @@ -22,10 +21,10 @@ import org.hibernate.loader.ast.internal.LoaderSelectBuilder; import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.query.spi.QueryOptions; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import static org.hibernate.loader.ast.internal.MultiKeyLoadLogging.MULTI_KEY_LOAD_DEBUG_ENABLED; import static org.hibernate.loader.ast.internal.MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER; @@ -37,7 +36,7 @@ public class ReactiveCollectionBatchLoaderInPredicate extends ReactiveAbstractCo private final int keyColumnCount; private final int sqlBatchSize; - private final List jdbcParameters; + private final JdbcParametersList jdbcParameters; private final SelectStatement sqlAst; private final JdbcOperationQuerySelect jdbcSelect; @@ -64,7 +63,7 @@ public ReactiveCollectionBatchLoaderInPredicate( ); } - this.jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersBuilder = JdbcParametersList.newBuilder(); this.sqlAst = LoaderSelectBuilder.createSelect( attributeMapping, null, @@ -73,9 +72,10 @@ public ReactiveCollectionBatchLoaderInPredicate( sqlBatchSize, influencers, LockOptions.NONE, - jdbcParameters::add, + jdbcParametersBuilder::add, sessionFactory ); + this.jdbcParameters = jdbcParametersBuilder.build(); assert this.jdbcParameters.size() == this.sqlBatchSize * this.keyColumnCount; this.jdbcSelect = sessionFactory.getJdbcServices() diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionLoaderSingleKey.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionLoaderSingleKey.java index d6495cc24..8606f6b65 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionLoaderSingleKey.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveCollectionLoaderSingleKey.java @@ -5,8 +5,6 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CompletionStage; import org.hibernate.LockOptions; @@ -27,12 +25,12 @@ import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor; import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer; import org.hibernate.sql.ast.SqlAstTranslatorFactory; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.internal.BaseExecutionContext; import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.graph.entity.LoadingEntityEntry; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; @@ -46,14 +44,14 @@ public class ReactiveCollectionLoaderSingleKey implements ReactiveCollectionLoad private final int keyJdbcCount; private final SelectStatement sqlAst; - private final List jdbcParameters; + private final JdbcParametersList jdbcParameters; public ReactiveCollectionLoaderSingleKey(PluralAttributeMapping attributeMapping, LoadQueryInfluencers influencers, SessionFactoryImplementor sessionFactory) { // PluralAttributeMappingImpl is the only implementation available at the moment in ORM final PluralAttributeMapping reactivePluralAttributeMapping = new ReactivePluralAttributeMapping( (PluralAttributeMappingImpl) attributeMapping ); this.attributeMapping = reactivePluralAttributeMapping; this.keyJdbcCount = reactivePluralAttributeMapping.getKeyDescriptor().getJdbcTypeCount(); - this.jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersBuilder = JdbcParametersList.newBuilder(); this.sqlAst = LoaderSelectBuilder.createSelect( reactivePluralAttributeMapping, null, @@ -62,9 +60,10 @@ public ReactiveCollectionLoaderSingleKey(PluralAttributeMapping attributeMapping 1, influencers, LockOptions.NONE, - jdbcParameters::add, + jdbcParametersBuilder::add, sessionFactory ); + this.jdbcParameters = jdbcParametersBuilder.build(); } @Override @@ -80,7 +79,7 @@ public SelectStatement getSqlAst() { return sqlAst; } - public List getJdbcParameters() { + public JdbcParametersList getJdbcParameters() { return jdbcParameters; } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveEntityBatchLoaderInPredicate.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveEntityBatchLoaderInPredicate.java index 1570faf90..0a403a174 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveEntityBatchLoaderInPredicate.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveEntityBatchLoaderInPredicate.java @@ -24,10 +24,10 @@ import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.query.spi.QueryOptions; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; import static org.hibernate.loader.ast.internal.MultiKeyLoadLogging.MULTI_KEY_LOAD_DEBUG_ENABLED; @@ -42,7 +42,7 @@ public class ReactiveEntityBatchLoaderInPredicate extends ReactiveSingleIdEnt private final int domainBatchSize; private final int sqlBatchSize; - private List jdbcParameters; + private JdbcParametersList jdbcParameters; private SelectStatement sqlAst; private JdbcOperationQuerySelect jdbcSelectOperation; @@ -185,7 +185,7 @@ public void prepare() { final int expectedNumberOfParameters = identifierMapping.getJdbcTypeCount() * sqlBatchSize; - jdbcParameters = arrayList( expectedNumberOfParameters ); + final JdbcParametersList.Builder parametersListBuilder = JdbcParametersList.newBuilder( expectedNumberOfParameters ); sqlAst = LoaderSelectBuilder.createSelect( getLoadable(), // null here means to select everything @@ -195,9 +195,10 @@ public void prepare() { sqlBatchSize, LoadQueryInfluencers.NONE, LockOptions.NONE, - jdbcParameters::add, + parametersListBuilder::add, sessionFactory ); + final JdbcParametersList jdbcParameters = parametersListBuilder.build(); assert jdbcParameters.size() == expectedNumberOfParameters; jdbcSelectOperation = sessionFactory.getJdbcServices() diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveLoaderHelper.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveLoaderHelper.java index 7142ad83f..44c90bfdf 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveLoaderHelper.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveLoaderHelper.java @@ -6,7 +6,6 @@ package org.hibernate.reactive.loader.ast.internal; import java.lang.reflect.Array; -import java.util.Collections; import java.util.List; import java.util.concurrent.CompletionStage; @@ -22,6 +21,7 @@ import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; import static java.util.Objects.requireNonNull; @@ -73,7 +73,7 @@ public static CompletionStage> loadByArrayParameter( final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler = SubselectFetch.createRegistrationHandler( session.getPersistenceContext().getBatchFetchQueue(), sqlAst, - Collections.singletonList( jdbcParameter ), + JdbcParametersList.singleton( jdbcParameter ), jdbcParameterBindings ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java index 5b06f5508..b37a780fd 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java @@ -8,7 +8,6 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.CompletionStage; @@ -44,6 +43,7 @@ import org.hibernate.sql.exec.internal.JdbcParameterImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; import org.hibernate.type.BasicType; import org.hibernate.type.BasicTypeRegistry; @@ -189,7 +189,7 @@ protected CompletionStage> performOrderedMultiLoad( final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler = SubselectFetch.createRegistrationHandler( batchFetchQueue, sqlAst, - Collections.singletonList( jdbcParameter ), + JdbcParametersList.singleton( jdbcParameter ), jdbcParameterBindings ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java index 06bef4c56..9a87f2359 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java @@ -43,11 +43,11 @@ import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer; import org.hibernate.reactive.util.impl.CompletionStages; import org.hibernate.sql.ast.SqlAstTranslatorFactory; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture; @@ -221,8 +221,7 @@ private CompletionStage> loadEntitiesById( LOG.tracef( "#loadEntitiesById(`%s`, `%s`, ..)", getEntityDescriptor().getEntityName(), numberOfIdsInBatch ); } - final List jdbcParameters = new ArrayList<>( numberOfIdsInBatch * idJdbcTypeCount ); - + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder( numberOfIdsInBatch * idJdbcTypeCount ); final SelectStatement sqlAst = LoaderSelectBuilder.createSelect( getLoadable(), // null here means to select everything @@ -232,9 +231,10 @@ private CompletionStage> loadEntitiesById( numberOfIdsInBatch, session.getLoadQueryInfluencers(), lockOptions, - jdbcParameters::add, + jdbcParametersListBuilder::add, getSessionFactory() ); + final JdbcParametersList jdbcParameters = jdbcParametersListBuilder.build(); final JdbcServices jdbcServices = getSessionFactory().getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiKeyLoadChunker.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiKeyLoadChunker.java index 90b6b410f..e5ec58e5d 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiKeyLoadChunker.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiKeyLoadChunker.java @@ -5,19 +5,18 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.List; import java.util.concurrent.CompletionStage; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.Bindable; import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor; import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerStandardImpl; import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture; @@ -53,7 +52,7 @@ interface ChunkBoundaryListener { private final int keyColumnCount; private final Bindable bindable; - private final List jdbcParameters; + private final JdbcParametersList jdbcParameters; private final SelectStatement sqlAst; private final JdbcOperationQuerySelect jdbcSelect; @@ -61,7 +60,7 @@ public ReactiveMultiKeyLoadChunker( int chunkSize, int keyColumnCount, Bindable bindable, - List jdbcParameters, + JdbcParametersList jdbcParameters, SelectStatement sqlAst, JdbcOperationQuerySelect jdbcSelect) { this.chunkSize = chunkSize; diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveNaturalIdLoaderDelegate.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveNaturalIdLoaderDelegate.java index 0619efa9a..8c11c087c 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveNaturalIdLoaderDelegate.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveNaturalIdLoaderDelegate.java @@ -5,8 +5,6 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CompletionStage; import java.util.function.BiConsumer; import java.util.function.BiFunction; @@ -36,7 +34,6 @@ import org.hibernate.sql.ast.SqlAstTranslatorFactory; import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl; import org.hibernate.sql.ast.spi.SqlAliasBaseManager; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectStatement; @@ -46,6 +43,7 @@ import org.hibernate.sql.exec.spi.Callback; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.FetchParent; @@ -148,7 +146,7 @@ public CompletionStage resolveNaturalIdToId( public CompletionStage resolveIdToNaturalId(Object id, SharedSessionContractImplementor session) { final SessionFactoryImplementor sessionFactory = session.getFactory(); - final List jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder(); final SelectStatement sqlSelect = LoaderSelectBuilder.createSelect( entityDescriptor(), singletonList( naturalIdMapping() ), @@ -157,9 +155,10 @@ public CompletionStage resolveIdToNaturalId(Object id, SharedSessionCont 1, session.getLoadQueryInfluencers(), LockOptions.NONE, - jdbcParameters::add, + jdbcParametersListBuilder::add, sessionFactory ); + final JdbcParametersList jdbcParameters = jdbcParametersListBuilder.build(); final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdArrayLoadPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdArrayLoadPlan.java index 8d991518b..b8335cd94 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdArrayLoadPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdArrayLoadPlan.java @@ -5,14 +5,13 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.List; import java.util.concurrent.CompletionStage; import org.hibernate.LockOptions; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.ModelPart; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.RowTransformerDatabaseSnapshotImpl; import org.hibernate.sql.results.spi.RowTransformer; @@ -24,7 +23,7 @@ public class ReactiveSingleIdArrayLoadPlan extends ReactiveSingleIdLoadPlan jdbcParameters, + JdbcParametersList jdbcParameters, LockOptions lockOptions, SessionFactoryImplementor sessionFactory) { super( null, restrictivePart, sqlAst, jdbcParameters, lockOptions, sessionFactory ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderStandardImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderStandardImpl.java index 9dc5a302e..9f2f1d3b2 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderStandardImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderStandardImpl.java @@ -5,9 +5,7 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.ArrayList; import java.util.EnumMap; -import java.util.List; import java.util.concurrent.CompletionStage; import java.util.concurrent.atomic.AtomicInteger; @@ -23,8 +21,8 @@ import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.persister.entity.Loadable; import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; +import org.hibernate.sql.exec.spi.JdbcParametersList; /** * Standard implementation of {@link ReactiveSingleIdEntityLoader}. @@ -195,8 +193,8 @@ private ReactiveSingleIdLoadPlan createLoadPlan( LoadQueryInfluencers queryInfluencers, SessionFactoryImplementor sessionFactory) { - final List jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder(); final SelectStatement sqlAst = LoaderSelectBuilder.createSelect( getLoadable(), // null here means to select everything @@ -206,9 +204,10 @@ private ReactiveSingleIdLoadPlan createLoadPlan( 1, queryInfluencers, lockOptions, - jdbcParameters::add, + jdbcParametersListBuilder::add, sessionFactory ); + final JdbcParametersList jdbcParameters = jdbcParametersListBuilder.build(); return new ReactiveSingleIdLoadPlan<>( (Loadable) getLoadable(), diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdLoadPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdLoadPlan.java index fab75b526..bfe274e13 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdLoadPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdLoadPlan.java @@ -23,13 +23,13 @@ import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor; import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer; import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.internal.CallbackImpl; import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl; import org.hibernate.sql.exec.spi.Callback; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.graph.entity.LoadingEntityEntry; public class ReactiveSingleIdLoadPlan extends SingleIdLoadPlan> { @@ -38,7 +38,7 @@ public ReactiveSingleIdLoadPlan( Loadable persister, ModelPart restrictivePart, SelectStatement sqlAst, - List jdbcParameters, + JdbcParametersList jdbcParameters, LockOptions lockOptions, SessionFactoryImplementor sessionFactory) { super( persister, restrictivePart, sqlAst, jdbcParameters, lockOptions, sessionFactory ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleUniqueKeyEntityLoaderStandard.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleUniqueKeyEntityLoaderStandard.java index 6ee7e65e8..f8ba89540 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleUniqueKeyEntityLoaderStandard.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleUniqueKeyEntityLoaderStandard.java @@ -5,7 +5,6 @@ */ package org.hibernate.reactive.loader.ast.internal; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletionStage; @@ -29,7 +28,6 @@ import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor; import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer; import org.hibernate.sql.ast.SqlAstTranslatorFactory; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.internal.BaseExecutionContext; import org.hibernate.sql.exec.internal.CallbackImpl; @@ -37,6 +35,7 @@ import org.hibernate.sql.exec.spi.Callback; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; /** * @@ -70,7 +69,7 @@ public CompletionStage load(Object ukValue, LockOptions lockOptions, Boolean final SessionFactoryImplementor sessionFactory = session.getFactory(); // todo (6.0) : cache the SQL AST and JdbcParameters - final List jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder(); final SelectStatement sqlAst = LoaderSelectBuilder.createSelectByUniqueKey( entityDescriptor, Collections.emptyList(), @@ -78,9 +77,10 @@ public CompletionStage load(Object ukValue, LockOptions lockOptions, Boolean null, LoadQueryInfluencers.NONE, LockOptions.NONE, - jdbcParameters::add, + jdbcParametersListBuilder::add, sessionFactory ); + final JdbcParametersList jdbcParameters = jdbcParametersListBuilder.build(); final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); @@ -125,7 +125,7 @@ public Object resolveId(Object ukValue, SharedSessionContractImplementor session final SessionFactoryImplementor sessionFactory = session.getFactory(); // todo (6.0) : cache the SQL AST and JdbcParameters - final List jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder(); final SelectStatement sqlAst = LoaderSelectBuilder.createSelectByUniqueKey( entityDescriptor, Collections.singletonList( entityDescriptor.getIdentifierMapping() ), @@ -133,9 +133,10 @@ public Object resolveId(Object ukValue, SharedSessionContractImplementor session null, LoadQueryInfluencers.NONE, LockOptions.NONE, - jdbcParameters::add, + jdbcParametersListBuilder::add, sessionFactory ); + final JdbcParametersList jdbcParameters = jdbcParametersListBuilder.build(); final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java index 4deaa284a..b9e692d15 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java @@ -51,8 +51,8 @@ import org.hibernate.reactive.session.impl.ReactiveQueryExecutorLookup; import org.hibernate.sql.SimpleSelect; import org.hibernate.sql.Update; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.type.BasicType; import jakarta.persistence.metamodel.Attribute; @@ -613,7 +613,7 @@ default ReactiveSingleIdArrayLoadPlan createLazyLoadPlan(List jdbcParameters = new ArrayList<>(); + final JdbcParametersList.Builder jdbcParametersListBuilder = JdbcParametersList.newBuilder(); final SelectStatement select = LoaderSelectBuilder.createSelect( this, partsToSelect, @@ -622,9 +622,10 @@ default ReactiveSingleIdArrayLoadPlan createLazyLoadPlan(List generatedValuesToSelect; - private final List jdbcParameters; + private final JdbcParametersList jdbcParameters; private final EntityMappingType entityDescriptor; private final SessionFactoryImplementor sessionFactory; ReactiveGeneratedValuesProcessor(SelectStatement selectStatement, List generatedValuesToSelect, - List jdbcParameters, + JdbcParametersList jdbcParameters, EntityMappingType entityDescriptor, SessionFactoryImplementor sessionFactory) { this.selectStatement = selectStatement; diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ConcreteSqmSelectReactiveQueryPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ConcreteSqmSelectReactiveQueryPlan.java index bcb15efae..8a5130088 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ConcreteSqmSelectReactiveQueryPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ConcreteSqmSelectReactiveQueryPlan.java @@ -39,10 +39,10 @@ import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.SqlAstTranslatorFactory; import org.hibernate.sql.ast.spi.FromClauseAccess; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.TupleMetadata; import org.hibernate.sql.results.spi.RowTransformer; @@ -93,7 +93,7 @@ private static CompletionStage> listInterpreter( final JdbcOperationQuerySelect jdbcSelect = sqmInterpretation.getJdbcSelect(); // I'm using a supplier so that the whenComplete at the end will catch any errors, like a finally-block Supplier fetchHandlerSupplier = () -> SubselectFetch - .createRegistrationHandler( session.getPersistenceContext().getBatchFetchQueue(), sqmInterpretation.selectStatement, emptyList(), jdbcParameterBindings ); + .createRegistrationHandler( session.getPersistenceContext().getBatchFetchQueue(), sqmInterpretation.selectStatement, JdbcParametersList.empty(), jdbcParameterBindings ); return completedFuture( fetchHandlerSupplier ) .thenApply( Supplier::get ) .thenCompose( subSelectFetchKeyHandler -> session @@ -212,7 +212,7 @@ private static CacheableSqmInterpretation buildCacheableSqmInterpretation( final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory(); final SqlAstTranslator selectTranslator = sqlAstTranslatorFactory .buildSelectTranslator( sessionFactory, sqmInterpretation.getSqlAst() ); - final Map, Map, List>>> jdbcParamsXref = SqmUtil + final Map, Map, List>> jdbcParamsXref = SqmUtil .generateJdbcParamsXref( domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam ); final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings( executionContext.getQueryParameterBindings(), @@ -258,7 +258,7 @@ private static class CacheableSqmInterpretation { private final SelectStatement selectStatement; private final JdbcOperationQuerySelect jdbcSelect; private final FromClauseAccess tableGroupAccess; - private final Map, Map, List>>> jdbcParamsXref; + private final Map, Map, List>> jdbcParamsXref; private final Map, MappingModelExpressible> sqmParameterMappingModelTypes; private transient JdbcParameterBindings firstParameterBindings; @@ -266,7 +266,7 @@ private static class CacheableSqmInterpretation { SelectStatement selectStatement, JdbcOperationQuerySelect jdbcSelect, FromClauseAccess tableGroupAccess, - Map, Map, List>>> jdbcParamsXref, + Map, Map, List>> jdbcParamsXref, Map, MappingModelExpressible> sqmParameterMappingModelTypes, JdbcParameterBindings firstParameterBindings) { this.selectStatement = selectStatement; @@ -289,7 +289,7 @@ FromClauseAccess getTableGroupAccess() { return tableGroupAccess; } - Map, Map, List>>> getJdbcParamsXref() { + Map, Map, List>> getJdbcParamsXref() { return jdbcParamsXref; } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleDeleteQueryPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleDeleteQueryPlan.java index 746950975..581d62c81 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleDeleteQueryPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleDeleteQueryPlan.java @@ -37,13 +37,13 @@ import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.tree.delete.DeleteStatement; import org.hibernate.sql.ast.tree.expression.Expression; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper; import org.hibernate.sql.ast.tree.from.NamedTableReference; import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.exec.spi.JdbcOperationQueryDelete; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; import org.hibernate.sql.results.internal.SqlSelectionImpl; import static org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter.usingLockingAndPaging; @@ -57,7 +57,7 @@ public class ReactiveSimpleDeleteQueryPlan extends SimpleDeleteQueryPlan impleme private SqmTranslation sqmInterpretation; - private Map, Map, List>>> jdbcParamsXref; + private Map, Map, List>> jdbcParamsXref; public ReactiveSimpleDeleteQueryPlan( EntityMappingType entityDescriptor, diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleInsertQueryPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleInsertQueryPlan.java index 33baca7d8..cba5287a9 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleInsertQueryPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleInsertQueryPlan.java @@ -31,10 +31,10 @@ import org.hibernate.reactive.sql.exec.internal.StandardReactiveJdbcMutationExecutor; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.FromClauseAccess; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.insert.InsertStatement; import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; /** * @see org.hibernate.query.sqm.internal.SimpleInsertQueryPlan @@ -49,7 +49,7 @@ public class ReactiveSimpleInsertQueryPlan implements ReactiveNonSelectQueryPlan private JdbcOperationQueryInsert jdbcInsert; private FromClauseAccess tableGroupAccess; - private Map, Map, List>>> jdbcParamsXref; + private Map, Map, List>> jdbcParamsXref; public ReactiveSimpleInsertQueryPlan( SqmInsertStatement sqmInsert, diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleUpdateQueryPlan.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleUpdateQueryPlan.java index 7f25ea865..068cb7f18 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleUpdateQueryPlan.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSimpleUpdateQueryPlan.java @@ -29,10 +29,10 @@ import org.hibernate.reactive.sql.exec.internal.StandardReactiveJdbcMutationExecutor; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.FromClauseAccess; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.update.UpdateStatement; import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate; import org.hibernate.sql.exec.spi.JdbcParameterBindings; +import org.hibernate.sql.exec.spi.JdbcParametersList; /** @@ -45,7 +45,7 @@ public class ReactiveSimpleUpdateQueryPlan implements ReactiveNonSelectQueryPlan private JdbcOperationQueryUpdate jdbcUpdate; private FromClauseAccess tableGroupAccess; - private Map, Map, List>>> jdbcParamsXref; + private Map, Map, List>> jdbcParamsXref; private Map, MappingModelExpressible> sqmParamMappingTypeResolutions; public ReactiveSimpleUpdateQueryPlan(SqmUpdateStatement sqmUpdate, DomainParameterXref domainParameterXref) { From 05890e13f5651205def1edaa6d2fd1b4e1ffbfc3 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Fri, 26 May 2023 10:25:13 +0200 Subject: [PATCH 3/6] Update ReactiveActionQueue to the new pattern in Hibernate ORM [HHH-16704] --- .../reactive/engine/ReactiveActionQueue.java | 387 +++++++++--------- .../ReactiveEntityIdentityInsertAction.java | 6 + .../impl/ReactiveEntityInsertAction.java | 4 + .../ReactiveEntityRegularInsertAction.java | 6 + 4 files changed, 201 insertions(+), 202 deletions(-) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java index a8d55c2b3..db3d12bd5 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java @@ -6,11 +6,9 @@ package org.hibernate.reactive.engine; import java.io.Serializable; -import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -23,7 +21,6 @@ import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.PropertyValueException; -import org.hibernate.action.internal.AbstractEntityInsertAction; import org.hibernate.action.internal.BulkOperationCleanupAction; import org.hibernate.action.internal.EntityDeleteAction; import org.hibernate.action.internal.UnresolvedEntityInsertActions; @@ -36,7 +33,6 @@ import org.hibernate.engine.spi.ExecutableList; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; import org.hibernate.proxy.HibernateProxy; @@ -47,13 +43,11 @@ import org.hibernate.reactive.engine.impl.ReactiveCollectionUpdateAction; import org.hibernate.reactive.engine.impl.ReactiveEntityActionVetoException; import org.hibernate.reactive.engine.impl.ReactiveEntityDeleteAction; -import org.hibernate.reactive.engine.impl.ReactiveEntityIdentityInsertAction; import org.hibernate.reactive.engine.impl.ReactiveEntityInsertAction; import org.hibernate.reactive.engine.impl.ReactiveEntityRegularInsertAction; import org.hibernate.reactive.engine.impl.ReactiveEntityUpdateAction; import org.hibernate.reactive.engine.impl.ReactiveOrphanRemovalAction; import org.hibernate.reactive.logging.impl.Log; -import org.hibernate.reactive.logging.impl.LoggerFactory; import org.hibernate.reactive.session.ReactiveSession; import org.hibernate.type.CollectionType; import org.hibernate.type.CompositeType; @@ -61,6 +55,8 @@ import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.Type; +import static java.lang.invoke.MethodHandles.lookup; +import static org.hibernate.reactive.logging.impl.LoggerFactory.make; import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture; import static org.hibernate.reactive.util.impl.CompletionStages.loop; import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture; @@ -71,121 +67,8 @@ */ public class ReactiveActionQueue { - private static final Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() ); + private static final Log LOG = make( Log.class, lookup() ); - /** - * A LinkedHashMap containing providers for all the ExecutableLists, inserted in execution order - */ - private static final LinkedHashMap, ListProvider> EXECUTABLE_LISTS_MAP; - - static { - EXECUTABLE_LISTS_MAP = CollectionHelper.linkedMapOfSize( 8 ); - - EXECUTABLE_LISTS_MAP.put( - ReactiveOrphanRemovalAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.orphanRemovals; - } - ExecutableList init(ReactiveActionQueue instance) { - // OrphanRemovalAction executables never require sorting. - return instance.orphanRemovals = new ExecutableList<>( false ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveEntityInsertAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.insertions; - } - - ExecutableList init(ReactiveActionQueue instance) { - instance.insertions = instance.isOrderInsertsEnabled() - ? new ExecutableList<>( new InsertActionSorter() ) - : new ExecutableList<>( false ); - return instance.insertions; - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveEntityUpdateAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.updates; - } - - ExecutableList init(ReactiveActionQueue instance) { - return instance.updates = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - QueuedOperationCollectionAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.collectionQueuedOps; - } - ExecutableList init(ReactiveActionQueue instance) { - return instance.collectionQueuedOps = new ExecutableList<>( - instance.isOrderUpdatesEnabled() - ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveCollectionRemoveAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.collectionRemovals; - } - ExecutableList init(ReactiveActionQueue instance) { - return instance.collectionRemovals = new ExecutableList<>( - instance.isOrderUpdatesEnabled() - ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveCollectionUpdateAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.collectionUpdates; - } - ExecutableList init(ReactiveActionQueue instance) { - return instance.collectionUpdates = new ExecutableList<>( - instance.isOrderUpdatesEnabled() - ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveCollectionRecreateAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.collectionCreations; - } - ExecutableList init(ReactiveActionQueue instance) { - return instance.collectionCreations = new ExecutableList<>( - instance.isOrderUpdatesEnabled() - ); - } - } - ); - EXECUTABLE_LISTS_MAP.put( - ReactiveEntityDeleteAction.class, - new ListProvider() { - ExecutableList get(ReactiveActionQueue instance) { - return instance.deletions; - } - - ExecutableList init(ReactiveActionQueue instance) { - // EntityDeleteAction executables never require sorting. - return instance.deletions = new ExecutableList<>( false ); - } - } - ); - } // NOTE: ExecutableList fields must be instantiated via ListProvider#init or #getOrInit // to ensure that they are instantiated consistently. @@ -213,6 +96,116 @@ ExecutableList init(ReactiveActionQueue instance) { private AfterTransactionCompletionProcessQueue afterTransactionProcesses; private BeforeTransactionCompletionProcessQueue beforeTransactionProcesses; + //Extract this as a constant to perform efficient iterations: + //method values() otherwise allocates a new array on each invocation. + private static final ReactiveActionQueue.OrderedActions[] ORDERED_OPERATIONS = ReactiveActionQueue.OrderedActions.values(); + + //The order of these operations is very important + private enum OrderedActions { + CollectionRemoveAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.collectionRemovals; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.collectionRemovals == null ) { + instance.collectionRemovals = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); + } + } + }, + OrphanRemovalAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.orphanRemovals; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.orphanRemovals == null ) { + instance.orphanRemovals = new ExecutableList<>( false ); + } + } + }, + EntityInsertAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.insertions; + } + @Override + public void ensureInitialized(final ReactiveActionQueue instance) { + if ( instance.insertions == null ) { + //Special case of initialization + instance.insertions = instance.isOrderInsertsEnabled() + ? new ExecutableList<>( ReactiveActionQueue.InsertActionSorter.INSTANCE ) + : new ExecutableList<>( false ); + } + } + }, + EntityUpdateAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.updates; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.updates == null ) { + instance.updates = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); + } + } + }, + QueuedOperationCollectionAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.collectionQueuedOps; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.collectionQueuedOps == null ) { + instance.collectionQueuedOps = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); + } + } + }, + CollectionUpdateAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.collectionUpdates; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.collectionUpdates == null ) { + instance.collectionUpdates = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); + } + } + }, + CollectionRecreateAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.collectionCreations; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.collectionCreations == null ) { + instance.collectionCreations = new ExecutableList<>( instance.isOrderUpdatesEnabled() ); + } + } + }, + EntityDeleteAction { + @Override + public ExecutableList getActions(ReactiveActionQueue instance) { + return instance.deletions; + } + @Override + public void ensureInitialized(ReactiveActionQueue instance) { + if ( instance.deletions == null ) { + instance.deletions = new ExecutableList<>( false ); + } + } + }; + + public abstract > ExecutableList getActions(ReactiveActionQueue instance); + public abstract void ensureInitialized(ReactiveActionQueue instance); + } + /** * Constructs an action queue bound to the given session. * @@ -223,54 +216,11 @@ public ReactiveActionQueue(ReactiveSession session) { isTransactionCoordinatorShared = false; } - private static String[] convertTimestampSpaces(Serializable[] spaces) { - return (String[]) spaces; - } - - private static boolean areTablesToBeUpdated( - ExecutableList actions, - @SuppressWarnings("rawtypes") Set tableSpaces) { - if ( actions == null || actions.isEmpty() ) { - return false; - } - - for ( Serializable actionSpace : actions.getQuerySpaces() ) { - if ( tableSpaces.contains( actionSpace ) ) { - LOG.debugf( "Changes must be flushed to space: %s", actionSpace ); - return true; - } - } - - return false; - } - - private static boolean areTablesToBeUpdated( - UnresolvedEntityInsertActions actions, - @SuppressWarnings("rawtypes") Set tableSpaces) { - for ( Executable action : actions.getDependentEntityInsertActions() ) { - for ( Serializable space : action.getPropertySpaces() ) { - if ( tableSpaces.contains( space ) ) { - LOG.debugf( "Changes must be flushed to space: %s", space ); - return true; - } - } - } - return false; - } - - private static String[] convertTimestampSpaces(Set spaces) { - return spaces.toArray( new String[0] ); - } - - private static String toString(ExecutableList q) { - return q == null ? "ExecutableList{size=0}" : q.toString(); - } - public void clear() { - for ( ListProvider listProvider : EXECUTABLE_LISTS_MAP.values() ) { - ExecutableList l = listProvider.get( this ); - if ( l != null ) { - l.clear(); + for ( OrderedActions value : ORDERED_OPERATIONS ) { + final ExecutableList list = value.getActions( this ); + if ( list != null ) { + list.clear(); } } if ( unresolvedInsertions != null ) { @@ -278,27 +228,18 @@ public void clear() { } } + /** * Adds an entity (REGULAR) insert action * * @param action The action representing the entity insertion */ - public CompletionStage addAction(ReactiveEntityRegularInsertAction action) { + public CompletionStage addAction(ReactiveEntityInsertAction action) { LOG.tracev( "Adding a ReactiveEntityRegularInsertAction for [{0}] object", action.getEntityName() ); return addInsertAction( action ); } - /** - * Adds an entity (IDENTITY) insert action - * - * @param action The action representing the entity insertion - */ - public CompletionStage addAction(ReactiveEntityIdentityInsertAction action) { - LOG.tracev( "Adding a ReactiveEntityIdentityInsertAction for [{0}] object", action.getEntityName() ); - return addInsertAction( action ); - } - - private CompletionStage addInsertAction(D insert) { + private CompletionStage addInsertAction( ReactiveEntityInsertAction insert) { CompletionStage ret = voidFuture(); if ( insert.isEarlyInsert() ) { // For early inserts, must execute inserts before finding non-nullable transient entities. @@ -321,7 +262,7 @@ private Comp if ( unresolvedInsertions == null ) { unresolvedInsertions = new UnresolvedEntityInsertActions(); } - unresolvedInsertions.addUnresolvedEntityInsertAction( insert, nonNullables ); + unresolvedInsertions.addUnresolvedEntityInsertAction( insert.asAbstractEntityInsertAction(), nonNullables ); return voidFuture(); } } ); @@ -339,7 +280,8 @@ private CompletionStage addResolvedEntityInsertAction(ReactiveEntityInsert } else { LOG.trace( "Adding resolved non-early insert action." ); - addAction( ReactiveEntityInsertAction.class, insert ); + OrderedActions.EntityInsertAction.ensureInitialized( this ); + this.insertions.add( insert ); ret = voidFuture(); } @@ -357,19 +299,52 @@ private CompletionStage addResolvedEntityInsertAction(ReactiveEntityInsert } } else { - // FIXME: Add it to the Log interface throw new ReactiveEntityActionVetoException( "The ReactiveEntityInsertAction was vetoed.", insert ); } } ); } - private > void addAction(Class executableClass, T action) { - getExecutableList(executableClass).getOrInit( this ).add( action ); + private static String[] convertTimestampSpaces(Serializable[] spaces) { + return (String[]) spaces; + } + + private static boolean areTablesToBeUpdated( + ExecutableList actions, + @SuppressWarnings("rawtypes") Set tableSpaces) { + if ( actions == null || actions.isEmpty() ) { + return false; + } + + for ( Serializable actionSpace : actions.getQuerySpaces() ) { + if ( tableSpaces.contains( actionSpace ) ) { + LOG.debugf( "Changes must be flushed to space: %s", actionSpace ); + return true; + } + } + + return false; + } + + private static boolean areTablesToBeUpdated( + UnresolvedEntityInsertActions actions, + @SuppressWarnings("rawtypes") Set tableSpaces) { + for ( Executable action : actions.getDependentEntityInsertActions() ) { + for ( Serializable space : action.getPropertySpaces() ) { + if ( tableSpaces.contains( space ) ) { + LOG.debugf( "Changes must be flushed to space: %s", space ); + return true; + } + } + } + return false; + } + + private static String[] convertTimestampSpaces(Set spaces) { + return spaces.toArray( new String[0] ); } - @SuppressWarnings("unchecked") - private > ListProvider getExecutableList(Class executableClass) { - return (ListProvider) EXECUTABLE_LISTS_MAP.get( executableClass ); + private static String toString(ExecutableList q) { + return q == null ? "ExecutableList{size=0}" : q.toString(); } /** @@ -378,7 +353,8 @@ private > ListProvider g * @param action The action representing the entity deletion */ public void addAction(ReactiveEntityDeleteAction action) { - addAction( ReactiveEntityDeleteAction.class, action ); + OrderedActions.EntityDeleteAction.ensureInitialized( this ); + this.deletions.add( action ); } /** @@ -387,7 +363,8 @@ public void addAction(ReactiveEntityDeleteAction action) { * @param action The action representing the orphan removal */ public void addAction(ReactiveOrphanRemovalAction action) { - addAction( ReactiveOrphanRemovalAction.class, action ); + OrderedActions.OrphanRemovalAction.ensureInitialized( this ); + this.orphanRemovals.add( action ); } /** @@ -396,7 +373,8 @@ public void addAction(ReactiveOrphanRemovalAction action) { * @param action The action representing the entity update */ public void addAction(ReactiveEntityUpdateAction action) { - addAction( ReactiveEntityUpdateAction.class, action ); + OrderedActions.EntityUpdateAction.ensureInitialized( this ); + this.updates.add( action ); } /** @@ -405,7 +383,8 @@ public void addAction(ReactiveEntityUpdateAction action) { * @param action The action representing the (re)creation of a collection */ public void addAction(ReactiveCollectionRecreateAction action) { - addAction( ReactiveCollectionRecreateAction.class, action ); + OrderedActions.CollectionRecreateAction.ensureInitialized( this ); + this.collectionCreations.add( action ); } /** @@ -414,7 +393,8 @@ public void addAction(ReactiveCollectionRecreateAction action) { * @param action The action representing the removal of a collection */ public void addAction(ReactiveCollectionRemoveAction action) { - addAction( ReactiveCollectionRemoveAction.class, action ); + OrderedActions.CollectionRemoveAction.ensureInitialized( this ); + this.collectionRemovals.add( action ); } /** @@ -423,7 +403,8 @@ public void addAction(ReactiveCollectionRemoveAction action) { * @param action The action representing the update of a collection */ public void addAction(ReactiveCollectionUpdateAction action) { - addAction( ReactiveCollectionUpdateAction.class, action ); + OrderedActions.CollectionUpdateAction.ensureInitialized( this ); + this.collectionUpdates.add( action ); } /** @@ -432,7 +413,8 @@ public void addAction(ReactiveCollectionUpdateAction action) { * @param action The action representing the queued operation */ public void addAction(QueuedOperationCollectionAction action) { - addAction( QueuedOperationCollectionAction.class, action ); + OrderedActions.QueuedOperationCollectionAction.ensureInitialized( this ); + this.collectionQueuedOps.add( action ); } /** @@ -537,11 +519,9 @@ public CompletionStage executeActions() { } CompletionStage ret = voidFuture(); - for ( ListProvider listProvider : EXECUTABLE_LISTS_MAP.values() ) { - ExecutableList l = listProvider.get( this ); - if ( l != null && !l.isEmpty() ) { - ret = ret.thenCompose( v -> executeActions( l ) ); - } + + for ( OrderedActions action : ORDERED_OPERATIONS ) { + ret = ret.thenCompose( v -> executeActions( action.getActions( this ) ) ); } return ret; } @@ -618,9 +598,9 @@ public boolean areTablesToBeUpdated(@SuppressWarnings("rawtypes") Set tables) { if ( tables.isEmpty() ) { return false; } - for ( ListProvider listProvider : EXECUTABLE_LISTS_MAP.values() ) { - ExecutableList l = listProvider.get( this ); - if ( areTablesToBeUpdated( l, tables ) ) { + for ( OrderedActions action : ORDERED_OPERATIONS ) { + final ExecutableList list = action.getActions( this ); + if ( areTablesToBeUpdated( list, tables ) ) { return true; } } @@ -637,6 +617,9 @@ public boolean areTablesToBeUpdated(@SuppressWarnings("rawtypes") Set tables) { */ private CompletionStage executeActions( ExecutableList list) throws HibernateException { + if ( list == null || list.isEmpty() ) { + return voidFuture(); + } // todo : consider ways to improve the double iteration of Executables here: // 1) we explicitly iterate list here to perform Executable#execute() // 2) ExecutableList#getQuerySpaces also iterates the Executables to collect query spaces. diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityIdentityInsertAction.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityIdentityInsertAction.java index 357128db8..7ad13ddce 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityIdentityInsertAction.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityIdentityInsertAction.java @@ -8,6 +8,7 @@ import java.util.concurrent.CompletionStage; import org.hibernate.HibernateException; +import org.hibernate.action.internal.AbstractEntityInsertAction; import org.hibernate.action.internal.EntityIdentityInsertAction; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.PersistenceContext; @@ -109,6 +110,11 @@ public EntityKey getEntityKey() { return super.getEntityKey(); } + @Override + public AbstractEntityInsertAction asAbstractEntityInsertAction() { + return this; + } + @Override protected void markExecuted() { super.markExecuted(); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java index 318b77715..a2c382d40 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java @@ -8,6 +8,7 @@ import java.util.concurrent.CompletionStage; import org.hibernate.LockMode; +import org.hibernate.action.internal.AbstractEntityInsertAction; import org.hibernate.action.internal.ComparableEntityAction; import org.hibernate.engine.internal.NonNullableTransientDependencies; import org.hibernate.engine.internal.Nullability; @@ -94,4 +95,7 @@ default CompletionStage reactiveMakeEntityManaged() { default CompletionStage reactiveFindNonNullableTransientEntities() { return ForeignKeys.findNonNullableTransientEntities( getPersister().getEntityName(), getInstance(), getState(), isEarlyInsert(), getSession() ); } + + AbstractEntityInsertAction asAbstractEntityInsertAction(); + } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityRegularInsertAction.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityRegularInsertAction.java index f113fef89..0e2045521 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityRegularInsertAction.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityRegularInsertAction.java @@ -9,6 +9,7 @@ import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; +import org.hibernate.action.internal.AbstractEntityInsertAction; import org.hibernate.action.internal.EntityInsertAction; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.entry.CacheEntry; @@ -150,6 +151,11 @@ public EntityKey getEntityKey() { return super.getEntityKey(); } + @Override + public AbstractEntityInsertAction asAbstractEntityInsertAction() { + return this; + } + @Override protected void markExecuted() { super.markExecuted(); From a845f861c7b703f5642574df761f76d2a6527953 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 26 May 2023 12:31:34 +0100 Subject: [PATCH 4/6] Rework type hierarchy of ReactiveEntityInsertAction --- .../reactive/engine/ReactiveActionQueue.java | 28 ++++---- .../impl/ReactiveEntityInsertAction.java | 7 +- .../ReactiveEntityInsertActionHolder.java | 72 +++++++++++++++++++ 3 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java index db3d12bd5..250901abf 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java @@ -44,6 +44,7 @@ import org.hibernate.reactive.engine.impl.ReactiveEntityActionVetoException; import org.hibernate.reactive.engine.impl.ReactiveEntityDeleteAction; import org.hibernate.reactive.engine.impl.ReactiveEntityInsertAction; +import org.hibernate.reactive.engine.impl.ReactiveEntityInsertActionHolder; import org.hibernate.reactive.engine.impl.ReactiveEntityRegularInsertAction; import org.hibernate.reactive.engine.impl.ReactiveEntityUpdateAction; import org.hibernate.reactive.engine.impl.ReactiveOrphanRemovalAction; @@ -78,7 +79,7 @@ public class ReactiveActionQueue { // Object insertions, updates, and deletions have list semantics because // they must happen in the right order to respect referential // integrity - private ExecutableList insertions; + private ExecutableList insertions; private ExecutableList deletions; private ExecutableList updates; // Actually the semantics of the next three are really "Bag" @@ -281,7 +282,7 @@ private CompletionStage addResolvedEntityInsertAction(ReactiveEntityInsert else { LOG.trace( "Adding resolved non-early insert action." ); OrderedActions.EntityInsertAction.ensureInitialized( this ); - this.insertions.add( insert ); + this.insertions.add( new ReactiveEntityInsertActionHolder( insert ) ); ret = voidFuture(); } @@ -1016,13 +1017,13 @@ public CompletionStage afterTransactionCompletion(boolean success) { * * @author Jay Erb */ - private static class InsertActionSorter implements ExecutableList.Sorter { + private static class InsertActionSorter implements ExecutableList.Sorter { /** * Singleton access */ public static final InsertActionSorter INSTANCE = new InsertActionSorter(); // the map of batch numbers to EntityInsertAction lists - private Map> actionBatches; + private Map> actionBatches; public InsertActionSorter() { } @@ -1030,20 +1031,21 @@ public InsertActionSorter() { /** * Sort the insert actions. */ - public void sort(List insertions) { + public void sort(List insertions) { // optimize the hash size to eliminate a rehash. this.actionBatches = new HashMap<>(); // the mapping of entity names to their latest batch numbers. final List latestBatches = new ArrayList<>(); - for ( ReactiveEntityInsertAction action : insertions ) { + for ( ReactiveEntityInsertActionHolder action : insertions ) { + final ReactiveEntityInsertAction actionDelegate = action.getDelegate(); BatchIdentifier batchIdentifier = new BatchIdentifier( - action.getEntityName(), - action.getSession() + actionDelegate.getEntityName(), + actionDelegate.getSession() .getFactory() .getMetamodel() - .entityPersister( action.getEntityName() ) + .entityPersister( actionDelegate.getEntityName() ) .getRootEntityName() ); @@ -1055,8 +1057,8 @@ public void sort(List insertions) { else { latestBatches.add( batchIdentifier ); } - addParentChildEntityNames( action, batchIdentifier ); - addToBatch( batchIdentifier, action ); + addParentChildEntityNames( actionDelegate, batchIdentifier ); + addToBatch( batchIdentifier, actionDelegate ); } insertions.clear(); @@ -1233,10 +1235,10 @@ else if ( type.isComponentType() && value != null ) { } private void addToBatch(BatchIdentifier batchIdentifier, ReactiveEntityInsertAction action) { - List actions = actionBatches + List actions = actionBatches .computeIfAbsent( batchIdentifier, k -> new LinkedList<>() ); - actions.add( action ); + actions.add( new ReactiveEntityInsertActionHolder( action ) ); } private static class BatchIdentifier { diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java index a2c382d40..2b196804d 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java @@ -9,7 +9,6 @@ import org.hibernate.LockMode; import org.hibernate.action.internal.AbstractEntityInsertAction; -import org.hibernate.action.internal.ComparableEntityAction; import org.hibernate.engine.internal.NonNullableTransientDependencies; import org.hibernate.engine.internal.Nullability; import org.hibernate.engine.internal.Versioning; @@ -29,7 +28,7 @@ * * @see org.hibernate.action.internal.AbstractEntityInsertAction */ -public interface ReactiveEntityInsertAction extends ReactiveExecutable, ComparableEntityAction { +public interface ReactiveEntityInsertAction extends ReactiveExecutable { boolean isEarlyInsert(); NonNullableTransientDependencies findNonNullableTransientEntities(); SharedSessionContractImplementor getSession(); @@ -98,4 +97,8 @@ default CompletionStage reactiveFindNonNullabl AbstractEntityInsertAction asAbstractEntityInsertAction(); + default int compareActionTo(ReactiveEntityInsertAction delegate) { + return asAbstractEntityInsertAction().compareTo( delegate.asAbstractEntityInsertAction() ); + } + } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java new file mode 100644 index 000000000..352981ea7 --- /dev/null +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java @@ -0,0 +1,72 @@ +/* Hibernate, Relational Persistence for Idiomatic Java + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright: Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.reactive.engine.impl; + +import java.io.Serializable; +import java.util.Objects; +import java.util.concurrent.CompletionStage; + +import org.hibernate.HibernateException; +import org.hibernate.action.spi.AfterTransactionCompletionProcess; +import org.hibernate.action.spi.BeforeTransactionCompletionProcess; +import org.hibernate.action.spi.Executable; +import org.hibernate.event.spi.EventSource; +import org.hibernate.reactive.engine.ReactiveExecutable; + +public final class ReactiveEntityInsertActionHolder implements Executable, ReactiveExecutable, Comparable, + Serializable { + + private final ReactiveEntityInsertAction delegate; + + public ReactiveEntityInsertActionHolder(ReactiveEntityInsertAction delegate) { + Objects.requireNonNull( delegate ); + this.delegate = delegate; + } + + @Override + public int compareTo(ReactiveEntityInsertActionHolder o) { + return delegate.compareActionTo( o.delegate ); + } + + @Override + public Serializable[] getPropertySpaces() { + return delegate.getPropertySpaces(); + } + + @Override + public void beforeExecutions() throws HibernateException { + delegate.beforeExecutions(); + } + + @Override + public void execute() throws HibernateException { + delegate.execute(); + } + + @Override + public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() { + return delegate.getAfterTransactionCompletionProcess(); + } + + @Override + public BeforeTransactionCompletionProcess getBeforeTransactionCompletionProcess() { + return delegate.getBeforeTransactionCompletionProcess(); + } + + @Override + public void afterDeserialize(EventSource session) { + delegate.afterDeserialize( session ); + } + + @Override + public CompletionStage reactiveExecute() { + return delegate.reactiveExecute(); + } + + public ReactiveEntityInsertAction getDelegate() { + return delegate; + } +} From cf8a9cae669d2a15c9caec02a47ce10bd27ffe07 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 26 May 2023 15:37:02 +0100 Subject: [PATCH 5/6] Adapt to changes in ORM core AttributeMappingsList [HHH-16705] --- .../entity/impl/ReactiveAbstractEntityPersister.java | 4 +++- .../persister/entity/impl/ReactiveCoordinatorFactory.java | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java index b9e692d15..671dbd0b4 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveAbstractEntityPersister.java @@ -556,7 +556,9 @@ default NaturalIdMapping generateNaturalIdMapping( // in the collected names. iterate here because it is already alphabetical final List collectedAttrMappings = new ArrayList<>(); - for ( AttributeMapping attributeMapping : getAttributeMappings() ) { + final AttributeMappingsList attributeMappings = getAttributeMappings(); + for ( int i = 0; i < attributeMappings.size(); i++ ) { + AttributeMapping attributeMapping = attributeMappings.get( i ); if ( attributeNames.contains( attributeMapping.getAttributeName() ) ) { collectedAttrMappings.add( (SingularAttributeMapping) attributeMapping ); } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveCoordinatorFactory.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveCoordinatorFactory.java index 558ff1da8..df60561f2 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveCoordinatorFactory.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/impl/ReactiveCoordinatorFactory.java @@ -7,6 +7,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.AttributeMapping; +import org.hibernate.metamodel.mapping.AttributeMappingsList; import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.reactive.persister.entity.mutation.ReactiveDeleteCoordinator; @@ -27,7 +28,9 @@ public static ReactiveUpdateCoordinator buildUpdateCoordinator( AbstractEntityPersister entityPersister, SessionFactoryImplementor factory) { // we only have updates to issue for entities with one or more singular attributes - for ( AttributeMapping attributeMapping : entityPersister.getAttributeMappings() ) { + final AttributeMappingsList attributeMappings = entityPersister.getAttributeMappings(); + for ( int i = 0; i < attributeMappings.size(); i++ ) { + AttributeMapping attributeMapping = attributeMappings.get( i ); if ( attributeMapping instanceof SingularAttributeMapping ) { return new ReactiveUpdateCoordinatorStandard( entityPersister, factory ); } From 958e2131397dafd650954cacd1c34cc1faf59fc4 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Wed, 31 May 2023 11:47:45 +0100 Subject: [PATCH 6/6] Adapt to ReactiveExecutable interface changes --- .../reactive/engine/ReactiveActionQueue.java | 16 ++----------- .../impl/ReactiveEntityInsertAction.java | 3 ++- .../ReactiveEntityInsertActionHolder.java | 23 ++++++++++++++----- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java index 250901abf..66f1730f1 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/ReactiveActionQueue.java @@ -29,6 +29,7 @@ import org.hibernate.action.spi.Executable; import org.hibernate.cache.CacheException; import org.hibernate.engine.spi.ActionQueue; +import org.hibernate.engine.spi.ComparableExecutable; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.ExecutableList; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -203,7 +204,7 @@ public void ensureInitialized(ReactiveActionQueue instance) { } }; - public abstract > ExecutableList getActions(ReactiveActionQueue instance); + public abstract ExecutableList getActions(ReactiveActionQueue instance); public abstract void ensureInitialized(ReactiveActionQueue instance); } @@ -1332,17 +1333,4 @@ private boolean hasParent(BatchIdentifier batchIdentifier, List } - private abstract static class ListProvider & Serializable> { - abstract ExecutableList get(ReactiveActionQueue instance); - - abstract ExecutableList init(ReactiveActionQueue instance); - - ExecutableList getOrInit(ReactiveActionQueue instance) { - ExecutableList list = get( instance ); - if ( list == null ) { - list = init( instance ); - } - return list; - } - } } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java index 2b196804d..ef48ba006 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertAction.java @@ -12,6 +12,7 @@ import org.hibernate.engine.internal.NonNullableTransientDependencies; import org.hibernate.engine.internal.Nullability; import org.hibernate.engine.internal.Versioning; +import org.hibernate.engine.spi.ComparableExecutable; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -28,7 +29,7 @@ * * @see org.hibernate.action.internal.AbstractEntityInsertAction */ -public interface ReactiveEntityInsertAction extends ReactiveExecutable { +public interface ReactiveEntityInsertAction extends ReactiveExecutable, ComparableExecutable { boolean isEarlyInsert(); NonNullableTransientDependencies findNonNullableTransientEntities(); SharedSessionContractImplementor getSession(); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java index 352981ea7..9cfff7f3b 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityInsertActionHolder.java @@ -13,10 +13,11 @@ import org.hibernate.action.spi.AfterTransactionCompletionProcess; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; import org.hibernate.action.spi.Executable; +import org.hibernate.engine.spi.ComparableExecutable; import org.hibernate.event.spi.EventSource; import org.hibernate.reactive.engine.ReactiveExecutable; -public final class ReactiveEntityInsertActionHolder implements Executable, ReactiveExecutable, Comparable, +public final class ReactiveEntityInsertActionHolder implements Executable, ReactiveExecutable, ComparableExecutable, Serializable { private final ReactiveEntityInsertAction delegate; @@ -26,11 +27,6 @@ public ReactiveEntityInsertActionHolder(ReactiveEntityInsertAction delegate) { this.delegate = delegate; } - @Override - public int compareTo(ReactiveEntityInsertActionHolder o) { - return delegate.compareActionTo( o.delegate ); - } - @Override public Serializable[] getPropertySpaces() { return delegate.getPropertySpaces(); @@ -69,4 +65,19 @@ public CompletionStage reactiveExecute() { public ReactiveEntityInsertAction getDelegate() { return delegate; } + + @Override + public String getPrimarySortClassifier() { + return delegate.getPrimarySortClassifier(); + } + + @Override + public Object getSecondarySortIndex() { + return delegate.getSecondarySortIndex(); + } + + @Override + public int compareTo(final ComparableExecutable o) { + return delegate.compareTo( o ); + } }