HHH-16346 Relax scopes for TableBased*Handler

So that Hibernate Reactive can create a custom LocalTemporaryTableStrategy
This commit is contained in:
Davide D'Alto 2023-03-21 16:08:41 +01:00
parent 3598ee25a9
commit eeccc9c99d
No known key found for this signature in database
GPG Key ID: 163581B9C6E9FC17
4 changed files with 137 additions and 18 deletions

View File

@ -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<SharedSessionContractImplementor, String> getSessionUidAccess() {
return sessionUidAccess;
}
protected DomainParameterXref getDomainParameterXref() {
return domainParameterXref;
}
@Override
public SqmDeleteStatement<?> getSqmDeleteOrUpdateStatement() {
return (SqmDeleteStatement<?>) super.getSqmDeleteOrUpdateStatement();

View File

@ -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<SharedSessionContractImplementor, String> sessionUidAccess,
DomainParameterXref domainParameterXref,
TableGroup insertingTableGroup,
Map<String, TableReference> tableReferenceByAlias,
List<Assignment> assignments,
InsertSelectStatement insertStatement,
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
JdbcParameter sessionUidParameter,
Map<SqmParameter<?>, 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,

View File

@ -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<SharedSessionContractImplementor, String> sessionUidAccess,
DomainParameterXref domainParameterXref,
TableGroup updatingTableGroup,
Map<String, TableReference> tableReferenceByAlias,
List<Assignment> assignments,
Predicate suppliedPredicate,
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter<?>, 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<String, TableReference> consumer) {
consumer.accept( tableReference.getIdentificationVariable(), tableReference );
}
private void collectTableReference(
protected void collectTableReference(
TableReferenceJoin tableReferenceJoin,
BiConsumer<String, TableReference> consumer) {
collectTableReference( tableReferenceJoin.getJoinedTableReference(), consumer );
}
}

View File

@ -205,7 +205,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
}
}
private TableReference resolveTableReference(
protected TableReference resolveTableReference(
ColumnReference columnReference,
Map<String, TableReference> 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<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier, QuerySpec idTableSubQuery) {
protected QuerySpec createExistsSubQuerySpec(String targetTableExpression, Supplier<Consumer<SelectableConsumer>> 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<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier) {
protected Expression resolveMutatingTableKeyExpression(String tableExpression, Supplier<Consumer<SelectableConsumer>> 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<SqlSelection> 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<SharedSessionContractImplementor, String> 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<TableReference, List<Assignment>> getAssignmentsByTable() {
return assignmentsByTable;
}
protected SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}
}