From 25790c26dfd3e1209da8189410fb95a5f54b9777 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Wed, 20 Nov 2024 11:44:37 +0100 Subject: [PATCH] HHH-18854 OptionalTableUpdateOperation: change scopes and minor refactoring Allow me to remove some duplicated code in Hibernate Reactive --- .../jdbc/OptionalTableUpdateOperation.java | 82 +++++++++++-------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/model/jdbc/OptionalTableUpdateOperation.java b/hibernate-core/src/main/java/org/hibernate/sql/model/jdbc/OptionalTableUpdateOperation.java index 52b10472b1..e213f3cc59 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/model/jdbc/OptionalTableUpdateOperation.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/model/jdbc/OptionalTableUpdateOperation.java @@ -263,7 +263,10 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio } } - private JdbcDeleteMutation createJdbcDelete(SharedSessionContractImplementor session) { + /* + * Used by Hibernate Reactive + */ + protected JdbcDeleteMutation createJdbcDelete(SharedSessionContractImplementor session) { final TableDelete tableDelete; if ( tableMapping.getDeleteDetails() != null && tableMapping.getDeleteDetails().getCustomSql() != null ) { @@ -305,39 +308,7 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio JdbcValueBindings jdbcValueBindings, SharedSessionContractImplementor session) { MODEL_MUTATION_LOGGER.tracef( "#performUpdate(%s)", tableMapping.getTableName() ); - - final TableUpdate tableUpdate; - if ( tableMapping.getUpdateDetails() != null - && tableMapping.getUpdateDetails().getCustomSql() != null ) { - tableUpdate = new TableUpdateCustomSql( - new MutatingTableReference( tableMapping ), - mutationTarget, - "upsert update for " + mutationTarget.getRolePath(), - valueBindings, - keyBindings, - optimisticLockBindings, - parameters - ); - } - else { - tableUpdate = new TableUpdateStandard( - new MutatingTableReference( tableMapping ), - mutationTarget, - "upsert update for " + mutationTarget.getRolePath(), - valueBindings, - keyBindings, - optimisticLockBindings, - parameters - ); - } - - final SqlAstTranslator translator = session - .getJdbcServices() - .getJdbcEnvironment() - .getSqlAstTranslatorFactory() - .buildModelMutationTranslator( tableUpdate, session.getFactory() ); - - final JdbcMutationOperation jdbcUpdate = translator.translate( null, MutationQueryOptions.INSTANCE ); + final JdbcMutationOperation jdbcUpdate = createJdbcUpdate( session ); final PreparedStatementGroupSingleTable statementGroup = new PreparedStatementGroupSingleTable( jdbcUpdate, session ); final PreparedStatementDetails statementDetails = statementGroup.resolvePreparedStatementDetails( tableMapping.getTableName() ); @@ -374,6 +345,44 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio } } + /* + * Used by Hibernate Reactive + */ + protected JdbcMutationOperation createJdbcUpdate(SharedSessionContractImplementor session) { + final TableUpdate tableUpdate; + if ( tableMapping.getUpdateDetails() != null + && tableMapping.getUpdateDetails().getCustomSql() != null ) { + tableUpdate = new TableUpdateCustomSql( + new MutatingTableReference( tableMapping ), + mutationTarget, + "upsert update for " + mutationTarget.getRolePath(), + valueBindings, + keyBindings, + optimisticLockBindings, + parameters + ); + } + else { + tableUpdate = new TableUpdateStandard( + new MutatingTableReference( tableMapping ), + mutationTarget, + "upsert update for " + mutationTarget.getRolePath(), + valueBindings, + keyBindings, + optimisticLockBindings, + parameters + ); + } + + final SqlAstTranslator translator = session + .getJdbcServices() + .getJdbcEnvironment() + .getSqlAstTranslatorFactory() + .buildModelMutationTranslator( tableUpdate, session.getFactory() ); + + return translator.translate( null, MutationQueryOptions.INSTANCE ); + } + private void performInsert(JdbcValueBindings jdbcValueBindings, SharedSessionContractImplementor session) { final JdbcInsertMutation jdbcInsert = createJdbcInsert( session ); @@ -414,7 +423,10 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio } } - private JdbcInsertMutation createJdbcInsert(SharedSessionContractImplementor session) { + /* + * Used by Hibernate Reactive + */ + protected JdbcInsertMutation createJdbcInsert(SharedSessionContractImplementor session) { final TableInsert tableInsert; if ( tableMapping.getInsertDetails() != null && tableMapping.getInsertDetails().getCustomSql() != null ) {