From eeccc9c99df57306c96f64a8ac84c64c62aac6c8 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Tue, 21 Mar 2023 16:08:41 +0100 Subject: [PATCH] HHH-16346 Relax scopes for TableBased*Handler So that Hibernate Reactive can create a custom LocalTemporaryTableStrategy --- .../temptable/TableBasedDeleteHandler.java | 19 ++++++- .../temptable/TableBasedInsertHandler.java | 40 ++++++++++++- .../temptable/TableBasedUpdateHandler.java | 40 ++++++++++--- .../temptable/UpdateExecutionDelegate.java | 56 ++++++++++++++++--- 4 files changed, 137 insertions(+), 18 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedDeleteHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedDeleteHandler.java index 7aac972c3a..c4c5dc372f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedDeleteHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedDeleteHandler.java @@ -64,7 +64,7 @@ public class TableBasedDeleteHandler return resolveDelegate( executionContext ).execute( executionContext ); } - private ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { + protected ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { return new RestrictedDeleteExecutionDelegate( getEntityDescriptor(), idTable, @@ -79,6 +79,23 @@ public class TableBasedDeleteHandler ); } + // Getters for Hibernat Reactive + protected TemporaryTable getIdTable() { + return idTable; + } + + protected AfterUseAction getAfterUseAction() { + return afterUseAction; + } + + protected Function getSessionUidAccess() { + return sessionUidAccess; + } + + protected DomainParameterXref getDomainParameterXref() { + return domainParameterXref; + } + @Override public SqmDeleteStatement getSqmDeleteOrUpdateStatement() { return (SqmDeleteStatement) super.getSqmDeleteOrUpdateStatement(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java index 970ddba12e..8b0f1bb3aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java @@ -76,7 +76,7 @@ public class TableBasedInsertHandler implements InsertHandler { private final DomainParameterXref domainParameterXref; private final JdbcParameter sessionUidParameter; - TableBasedInsertHandler( + public TableBasedInsertHandler( SqmInsertStatement sqmInsert, DomainParameterXref domainParameterXref, TemporaryTable entityTable, @@ -116,7 +116,7 @@ public class TableBasedInsertHandler implements InsertHandler { return resolveDelegate( executionContext ).execute( executionContextAdapter ); } - private ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { + protected ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor( getSqmInsertStatement().getTarget().getEntityName() ); @@ -319,7 +319,7 @@ public class TableBasedInsertHandler implements InsertHandler { collectTableReference( insertingTableGroup.getTableReferenceJoins().get( i ), tableReferenceByAlias::put ); } - return new InsertExecutionDelegate( + return buildExecutionDelegate( sqmInsertStatement, converterDelegate, entityTable, @@ -337,6 +337,40 @@ public class TableBasedInsertHandler implements InsertHandler { ); } + // For Hibernate Reactive + protected ExecutionDelegate buildExecutionDelegate( + SqmInsertStatement sqmInsert, + MultiTableSqmMutationConverter sqmConverter, + TemporaryTable entityTable, + AfterUseAction afterUseAction, + Function sessionUidAccess, + DomainParameterXref domainParameterXref, + TableGroup insertingTableGroup, + Map tableReferenceByAlias, + List assignments, + InsertSelectStatement insertStatement, + Map, List>> parameterResolutions, + JdbcParameter sessionUidParameter, + Map, MappingModelExpressible> paramTypeResolutions, + DomainQueryExecutionContext executionContext) { + return new InsertExecutionDelegate( + sqmInsertStatement, + sqmConverter, + entityTable, + afterUseAction, + sessionUidAccess, + domainParameterXref, + insertingTableGroup, + tableReferenceByAlias, + assignments, + insertStatement, + parameterResolutions, + sessionUidParameter, + paramTypeResolutions, + executionContext + ); + } + private void collectTableReference( TableReference tableReference, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedUpdateHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedUpdateHandler.java index 3b45fb0b22..965d4d0888 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedUpdateHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedUpdateHandler.java @@ -62,7 +62,7 @@ public class TableBasedUpdateHandler private final EntityPersister entityDescriptor; - TableBasedUpdateHandler( + public TableBasedUpdateHandler( SqmUpdateStatement sqmUpdate, DomainParameterXref domainParameterXref, TemporaryTable idTable, @@ -102,7 +102,7 @@ public class TableBasedUpdateHandler return resolveDelegate( executionContext ).execute( executionContextAdapter ); } - private ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { + protected ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) { final SessionFactoryImplementor sessionFactory = getSessionFactory(); final MappingMetamodel domainModel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel(); final EntityPersister entityDescriptor = domainModel.getEntityDescriptor( getSqmDeleteOrUpdateStatement().getTarget().getEntityName() ); @@ -207,7 +207,7 @@ public class TableBasedUpdateHandler collectTableReference( updatingTableGroup.getTableReferenceJoins().get( i ), tableReferenceByAlias::put ); } - return new UpdateExecutionDelegate( + return buildExecutionDelegate( converterDelegate, idTable, afterUseAction, @@ -223,18 +223,44 @@ public class TableBasedUpdateHandler ); } + protected UpdateExecutionDelegate buildExecutionDelegate( + MultiTableSqmMutationConverter sqmConverter, + TemporaryTable idTable, + AfterUseAction afterUseAction, + Function sessionUidAccess, + DomainParameterXref domainParameterXref, + TableGroup updatingTableGroup, + Map tableReferenceByAlias, + List assignments, + Predicate suppliedPredicate, + Map, List>> parameterResolutions, + Map, MappingModelExpressible> paramTypeResolutions, + DomainQueryExecutionContext executionContext) { + return new UpdateExecutionDelegate( + sqmConverter, + idTable, + afterUseAction, + sessionUidAccess, + domainParameterXref, + updatingTableGroup, + tableReferenceByAlias, + assignments, + suppliedPredicate, + parameterResolutions, + paramTypeResolutions, + executionContext + ); + } - private void collectTableReference( + protected void collectTableReference( TableReference tableReference, BiConsumer consumer) { consumer.accept( tableReference.getIdentificationVariable(), tableReference ); } - private void collectTableReference( + protected void collectTableReference( TableReferenceJoin tableReferenceJoin, BiConsumer consumer) { collectTableReference( tableReferenceJoin.getJoinedTableReference(), consumer ); } - - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java index 72e5a94f4c..0bf58c8b38 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java @@ -205,7 +205,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio } } - private TableReference resolveTableReference( + protected TableReference resolveTableReference( ColumnReference columnReference, Map tableReferenceByAlias) { final TableReference tableReferenceByQualifier = tableReferenceByAlias.get( columnReference.getQualifier() ); @@ -216,7 +216,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio throw new SemanticException( "Assignment referred to column of a joined association: " + columnReference ); } - private NamedTableReference resolveUnionTableReference( + protected NamedTableReference resolveUnionTableReference( TableReference tableReference, String tableExpression) { if ( tableReference instanceof UnionTableReference ) { @@ -284,7 +284,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio } } - private boolean isTableOptional(String tableExpression) { + protected boolean isTableOptional(String tableExpression) { final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister(); for ( int i = 0; i < entityPersister.getTableSpan(); i++ ) { if ( tableExpression.equals( entityPersister.getTableName( i ) ) @@ -371,7 +371,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio ); } - private QuerySpec createExistsSubQuerySpec(String targetTableExpression, Supplier> tableKeyColumnVisitationSupplier, QuerySpec idTableSubQuery) { + protected QuerySpec createExistsSubQuerySpec(String targetTableExpression, Supplier> tableKeyColumnVisitationSupplier, QuerySpec idTableSubQuery) { final NamedTableReference existsTableReference = new NamedTableReference( targetTableExpression, "dml_" @@ -411,7 +411,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio return existsSubQuerySpec; } - private static QuerySpec makeInsertSourceSelectQuerySpec(QuerySpec idTableSubQuery) { + protected static QuerySpec makeInsertSourceSelectQuerySpec(QuerySpec idTableSubQuery) { final QuerySpec idTableQuerySpec = new QuerySpec( true ); for ( TableGroup root : idTableSubQuery.getFromClause().getRoots() ) { idTableQuerySpec.getFromClause().addRoot( root ); @@ -448,7 +448,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio return updateCount; } - private Expression resolveMutatingTableKeyExpression(String tableExpression, Supplier> tableKeyColumnVisitationSupplier) { + protected Expression resolveMutatingTableKeyExpression(String tableExpression, Supplier> tableKeyColumnVisitationSupplier) { final TableKeyExpressionCollector keyColumnCollector = new TableKeyExpressionCollector( entityDescriptor ); tableKeyColumnVisitationSupplier.get().accept( @@ -461,7 +461,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio return keyColumnCollector.buildKeyExpression(); } - private Expression asExpression(SelectClause selectClause) { + protected Expression asExpression(SelectClause selectClause) { final List sqlSelections = selectClause.getSqlSelections(); if ( sqlSelections.size() == 1 ) { return sqlSelections.get( 0 ).getExpression(); @@ -472,4 +472,46 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio } return new SqlTuple( expressions, null ); } + + // FOr Hibernate Reactive + + protected TemporaryTable getIdTable() { + return idTable; + } + + protected Predicate getSuppliedPredicate() { + return suppliedPredicate; + } + + protected MultiTableSqmMutationConverter getSqmConverter() { + return sqmConverter; + } + + protected Function getSessionUidAccess() { + return sessionUidAccess; + } + + protected JdbcParameterBindings getJdbcParameterBindings() { + return jdbcParameterBindings; + } + + protected EntityMappingType getEntityDescriptor() { + return entityDescriptor; + } + + protected AfterUseAction getAfterUseAction() { + return afterUseAction; + } + + protected TableGroup getUpdatingTableGroup() { + return updatingTableGroup; + } + + protected Map> getAssignmentsByTable() { + return assignmentsByTable; + } + + protected SessionFactoryImplementor getSessionFactory() { + return sessionFactory; + } }