Skip to content

Commit 9fe7240

Browse files
dreab8DavideD
authored andcommitted
[#2387] Check compatibility with Hibernate ORM 7.1
1 parent fbf8a65 commit 9fe7240

15 files changed

+146
-61
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/cte/ReactiveCteInsertHandler.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,7 @@ public CompletionStage<Integer> reactiveExecute(DomainQueryExecutionContext exec
144144
final BaseSqmToSqlAstConverter.AdditionalInsertValues additionalInsertValues = sqmConverter.visitInsertionTargetPaths(
145145
(assignable, columnReferences) -> {
146146
final SqmPathInterpretation<?> pathInterpretation = (SqmPathInterpretation<?>) assignable;
147-
final int offset = CteTable.determineModelPartStartIndex(
148-
entityDescriptor,
149-
pathInterpretation.getExpressionType()
150-
);
151-
if ( offset == -1 ) {
152-
throw new IllegalStateException( "Couldn't find matching cte column for: " + ( (Expression) assignable ).getExpressionType() );
153-
}
154-
final int end = offset + pathInterpretation.getExpressionType().getJdbcTypeCount();
155-
// Find a matching cte table column and set that at the current index
156-
final List<CteColumn> columns = getCteTable().getCteColumns().subList( offset, end );
147+
final List<CteColumn> columns = getCteTable().findCteColumns( pathInterpretation.getExpressionType() );
157148
insertStatement.addTargetColumnReferences( columnReferences );
158149
targetPathCteColumns.addAll( columns );
159150
targetPathColumns.add(
@@ -250,6 +241,17 @@ public CompletionStage<Integer> reactiveExecute(DomainQueryExecutionContext exec
250241
);
251242
}
252243
}
244+
if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecution() ) {
245+
querySpec.getSelectClause().addSqlSelection(
246+
new SqlSelectionImpl(
247+
0,
248+
SqmInsertStrategyHelper.createRowNumberingExpression(
249+
querySpec,
250+
sessionFactory
251+
)
252+
)
253+
);
254+
}
253255
final ValuesTableGroup valuesTableGroup = new ValuesTableGroup(
254256
navigablePath,
255257
entityDescriptor.getEntityPersister(),

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/cte/ReactiveInsertExecutionDelegate.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import java.util.function.Function;
1212

1313
import org.hibernate.dialect.temptable.TemporaryTable;
14+
import org.hibernate.dialect.temptable.TemporaryTableStrategy;
1415
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1516
import org.hibernate.query.spi.DomainQueryExecutionContext;
1617
import org.hibernate.query.sqm.internal.DomainParameterXref;
1718
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
1819
import org.hibernate.query.sqm.mutation.internal.temptable.InsertExecutionDelegate;
19-
import org.hibernate.query.sqm.mutation.spi.AfterUseAction;
2020
import org.hibernate.reactive.query.sqm.mutation.internal.temptable.ReactiveTableBasedInsertHandler;
2121
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
2222
import org.hibernate.sql.ast.tree.from.TableGroup;
@@ -34,25 +34,29 @@ public class ReactiveInsertExecutionDelegate extends InsertExecutionDelegate imp
3434
public ReactiveInsertExecutionDelegate(
3535
MultiTableSqmMutationConverter sqmConverter,
3636
TemporaryTable entityTable,
37-
AfterUseAction afterUseAction,
37+
TemporaryTableStrategy temporaryTableStrategy,
38+
boolean forceDropAfterUse,
3839
Function<SharedSessionContractImplementor, String> sessionUidAccess,
3940
DomainParameterXref domainParameterXref,
4041
TableGroup insertingTableGroup,
4142
Map<String, TableReference> tableReferenceByAlias,
4243
List<Assignment> assignments,
44+
boolean assignedId,
4345
InsertSelectStatement insertStatement,
4446
ConflictClause conflictClause,
4547
JdbcParameter sessionUidParameter,
4648
DomainQueryExecutionContext executionContext) {
4749
super(
4850
sqmConverter,
4951
entityTable,
50-
afterUseAction,
52+
temporaryTableStrategy,
53+
forceDropAfterUse,
5154
sessionUidAccess,
5255
domainParameterXref,
5356
insertingTableGroup,
5457
tableReferenceByAlias,
5558
assignments,
59+
assignedId,
5660
insertStatement,
5761
conflictClause,
5862
sessionUidParameter,

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveExecuteWithTemporaryTableHelper.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hibernate.dialect.Dialect;
1818
import org.hibernate.dialect.temptable.TemporaryTable;
1919
import org.hibernate.dialect.temptable.TemporaryTableColumn;
20+
import org.hibernate.dialect.temptable.TemporaryTableStrategy;
2021
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
2122
import org.hibernate.engine.jdbc.spi.JdbcServices;
2223
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -52,6 +53,7 @@
5253
import org.hibernate.sql.results.internal.SqlSelectionImpl;
5354

5455
import static org.hibernate.reactive.query.sqm.mutation.internal.temptable.ReactiveTemporaryTableHelper.cleanTemporaryTableRows;
56+
import static org.hibernate.reactive.util.impl.CompletionStages.falseFuture;
5557
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
5658

5759
/**
@@ -112,7 +114,10 @@ public static CompletionStage<Integer> saveMatchingIdsIntoIdTable(
112114
new SqlSelectionImpl(
113115
selectionIndex + 1,
114116
sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
115-
tableReference,
117+
mutatingTableGroup.resolveTableReference(
118+
mutatingTableGroup.getNavigablePath(),
119+
selection.getContainingTableExpression()
120+
),
116121
selection
117122
)
118123
)
@@ -155,7 +160,8 @@ public static CompletionStage<Integer> saveIntoTemporaryTable(
155160
temporaryTableInsert.getSourceSelectStatement().visitQuerySpecs(
156161
querySpec -> querySpec.getFromClause().visitTableJoins(
157162
tableJoin -> {
158-
if ( tableJoin.getJoinType() != SqlAstJoinType.INNER ) {
163+
if ( tableJoin.isInitialized()
164+
&& tableJoin.getJoinType() != SqlAstJoinType.INNER ) {
159165
lockOptions.setLockMode( lockMode );
160166
}
161167
}
@@ -210,7 +216,7 @@ public static QuerySpec createIdTableSelectQuerySpec(
210216

211217
querySpec.getFromClause().addRoot( idTableGroup );
212218

213-
applyIdTableSelections( querySpec, idTableReference, idTable, fkModelPart );
219+
applyIdTableSelections( querySpec, idTableReference, idTable, fkModelPart, entityDescriptor );
214220
applyIdTableRestrictions( querySpec, idTableReference, idTable, sessionUidAccess, executionContext );
215221

216222
return querySpec;
@@ -221,9 +227,10 @@ private static void applyIdTableSelections(
221227
QuerySpec querySpec,
222228
TableReference tableReference,
223229
TemporaryTable idTable,
224-
ModelPart fkModelPart) {
230+
ModelPart fkModelPart,
231+
EntityMappingType entityDescriptor) {
225232
if ( fkModelPart == null ) {
226-
final int size = idTable.getEntityDescriptor().getIdentifierMapping().getJdbcTypeCount();
233+
final int size = entityDescriptor.getIdentifierMapping().getJdbcTypeCount();
227234
for ( int i = 0; i < size; i++ ) {
228235
final TemporaryTableColumn temporaryTableColumn = idTable.getColumns().get( i );
229236
if ( temporaryTableColumn != idTable.getSessionUidColumn() ) {
@@ -285,20 +292,45 @@ private static void applyIdTableRestrictions(
285292
}
286293
}
287294

295+
@Deprecated(forRemoval = true, since = "7.1")
288296
public static CompletionStage<Void> performBeforeTemporaryTableUseActions(
289297
TemporaryTable temporaryTable,
290298
ExecutionContext executionContext) {
299+
return performBeforeTemporaryTableUseActions(
300+
temporaryTable,
301+
executionContext.getSession().getDialect().getTemporaryTableBeforeUseAction(),
302+
executionContext
303+
).thenCompose( v -> voidFuture() );
304+
}
305+
306+
public static CompletionStage<Boolean> performBeforeTemporaryTableUseActions(
307+
TemporaryTable temporaryTable,
308+
TemporaryTableStrategy temporaryTableStrategy,
309+
ExecutionContext executionContext) {
310+
return performBeforeTemporaryTableUseActions(
311+
temporaryTable,
312+
temporaryTableStrategy.getTemporaryTableBeforeUseAction(),
313+
executionContext
314+
);
315+
}
316+
317+
public static CompletionStage<Boolean> performBeforeTemporaryTableUseActions(
318+
TemporaryTable temporaryTable,
319+
BeforeUseAction beforeUseAction,
320+
ExecutionContext executionContext) {
291321
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
292322
final Dialect dialect = factory.getJdbcServices().getDialect();
293-
if ( dialect.getTemporaryTableBeforeUseAction() == BeforeUseAction.CREATE ) {
323+
if ( beforeUseAction == BeforeUseAction.CREATE ) {
294324
final TemporaryTableCreationWork temporaryTableCreationWork = new TemporaryTableCreationWork( temporaryTable, factory );
295325
final TempTableDdlTransactionHandling ddlTransactionHandling = dialect.getTemporaryTableDdlTransactionHandling();
296326
if ( ddlTransactionHandling == TempTableDdlTransactionHandling.NONE ) {
297327
return temporaryTableCreationWork.reactiveExecute( ( (ReactiveConnectionSupplier) executionContext.getSession() ).getReactiveConnection() );
298328
}
299329
throw LOG.notYetImplemented();
300330
}
301-
return voidFuture();
331+
else{
332+
return falseFuture();
333+
}
302334
}
303335

304336
public static CompletionStage<Void> performAfterTemporaryTableUseActions(
@@ -312,13 +344,13 @@ public static CompletionStage<Void> performAfterTemporaryTableUseActions(
312344
case CLEAN:
313345
return cleanTemporaryTableRows( temporaryTable, dialect.getTemporaryTableExporter(), sessionUidAccess, executionContext.getSession() );
314346
case DROP:
315-
return dropAction( temporaryTable, executionContext, factory, dialect );
347+
return dropAction( temporaryTable, executionContext, factory, dialect ).thenCompose( v -> voidFuture() );
316348
default:
317349
return voidFuture();
318350
}
319351
}
320352

321-
private static CompletionStage<Void> dropAction(
353+
private static CompletionStage<Boolean> dropAction(
322354
TemporaryTable temporaryTable,
323355
ExecutionContext executionContext,
324356
SessionFactoryImplementor factory,

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveGlobalTemporaryTableInsertStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public CompletionStage<Integer> reactiveExecuteInsert(
5656
sqmInsertStatement,
5757
domainParameterXref,
5858
getTemporaryTable(),
59-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
59+
getTemporaryTableStrategy(),
60+
false,
6061
// generally a global temp table should already track a Connection-specific uid,
6162
// but just in case a particular env needs it...
6263
ReactiveGlobalTemporaryTableStrategy::sessionIdentifier,

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveGlobalTemporaryTableMutationStrategy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public CompletionStage<Integer> reactiveExecuteUpdate(
5959
sqmUpdateStatement,
6060
domainParameterXref,
6161
getTemporaryTable(),
62-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
62+
getTemporaryTableStrategy(),
63+
false,
6364
ReactivePersistentTableStrategy::sessionIdentifier,
6465
getSessionFactory()
6566
).reactiveExecute( context ) );
@@ -75,7 +76,8 @@ public CompletionStage<Integer> reactiveExecuteDelete(
7576
sqmDeleteStatement,
7677
domainParameterXref,
7778
getTemporaryTable(),
78-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
79+
getTemporaryTableStrategy(),
80+
false,
7981
ReactiveGlobalTemporaryTableStrategy::sessionIdentifier,
8082
getSessionFactory()
8183
).reactiveExecute( context ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveLocalTemporaryTableInsertStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public CompletionStage<Integer> reactiveExecuteInsert(
3131
sqmInsertStatement,
3232
domainParameterXref,
3333
getTemporaryTable(),
34-
afterUserAction(),
34+
getTemporaryTableStrategy(),
35+
isDropIdTables(),
3536
ReactiveLocalTemporaryTableInsertStrategy::throwUnexpectedCallToSessionUIDError,
3637
getSessionFactory()
3738
).reactiveExecute( context );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveLocalTemporaryTableMutationStrategy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public CompletionStage<Integer> reactiveExecuteUpdate(
3737
sqmUpdate,
3838
domainParameterXref,
3939
getTemporaryTable(),
40-
afterUseAction(),
40+
getTemporaryTableStrategy(),
41+
isDropIdTables(),
4142
ReactiveLocalTemporaryTableMutationStrategy::throwUnexpectedAccessToSessionUID,
4243
getSessionFactory()
4344
).reactiveExecute( context );
@@ -52,7 +53,8 @@ public CompletionStage<Integer> reactiveExecuteDelete(
5253
sqmDelete,
5354
domainParameterXref,
5455
getTemporaryTable(),
55-
afterUseAction(),
56+
getTemporaryTableStrategy(),
57+
isDropIdTables(),
5658
ReactiveLocalTemporaryTableMutationStrategy::throwUnexpectedAccessToSessionUID,
5759
getSessionFactory()
5860
).reactiveExecute( context );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactivePersistentTableInsertStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public CompletionStage<Integer> reactiveExecuteInsert(
5353
sqmInsertStatement,
5454
domainParameterXref,
5555
getTemporaryTable(),
56-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
56+
getTemporaryTableStrategy(),
57+
false,
5758
ReactivePersistentTableStrategy::sessionIdentifier,
5859
getSessionFactory()
5960
).reactiveExecute( context ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactivePersistentTableMutationStrategy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public CompletionStage<Integer> reactiveExecuteUpdate(
5656
sqmUpdateStatement,
5757
domainParameterXref,
5858
getTemporaryTable(),
59-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
59+
getTemporaryTableStrategy(),
60+
false,
6061
ReactivePersistentTableStrategy::sessionIdentifier,
6162
getSessionFactory()
6263
).reactiveExecute( context ) );
@@ -72,7 +73,8 @@ public CompletionStage<Integer> reactiveExecuteDelete(
7273
sqmDeleteStatement,
7374
domainParameterXref,
7475
getTemporaryTable(),
75-
getSessionFactory().getJdbcServices().getDialect().getTemporaryTableAfterUseAction(),
76+
getTemporaryTableStrategy(),
77+
false,
7678
ReactivePersistentTableStrategy::sessionIdentifier,
7779
getSessionFactory()
7880
).reactiveExecute( context ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/mutation/internal/temptable/ReactiveRestrictedDeleteExecutionDelegate.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.function.Supplier;
1717

1818
import org.hibernate.dialect.temptable.TemporaryTable;
19+
import org.hibernate.dialect.temptable.TemporaryTableStrategy;
1920
import org.hibernate.engine.jdbc.spi.JdbcServices;
2021
import org.hibernate.engine.spi.LoadQueryInfluencers;
2122
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -83,7 +84,8 @@ public class ReactiveRestrictedDeleteExecutionDelegate
8384

8485
private final EntityMappingType entityDescriptor;
8586
private final TemporaryTable idTable;
86-
private final AfterUseAction afterUseAction;
87+
private final TemporaryTableStrategy temporaryTableStrategy;
88+
private final boolean forceDropAfterUse;
8789
private final SqmDeleteStatement<?> sqmDelete;
8890
private final DomainParameterXref domainParameterXref;
8991
private final SessionFactoryImplementor sessionFactory;
@@ -94,7 +96,8 @@ public class ReactiveRestrictedDeleteExecutionDelegate
9496
public ReactiveRestrictedDeleteExecutionDelegate(
9597
EntityMappingType entityDescriptor,
9698
TemporaryTable idTable,
97-
AfterUseAction afterUseAction,
99+
TemporaryTableStrategy temporaryTableStrategy,
100+
boolean forceDropAfterUse,
98101
SqmDeleteStatement<?> sqmDelete,
99102
DomainParameterXref domainParameterXref,
100103
Function<SharedSessionContractImplementor, String> sessionUidAccess,
@@ -104,7 +107,8 @@ public ReactiveRestrictedDeleteExecutionDelegate(
104107
SessionFactoryImplementor sessionFactory) {
105108
this.entityDescriptor = entityDescriptor;
106109
this.idTable = idTable;
107-
this.afterUseAction = afterUseAction;
110+
this.temporaryTableStrategy = temporaryTableStrategy;
111+
this.forceDropAfterUse = forceDropAfterUse;
108112
this.sqmDelete = sqmDelete;
109113
this.domainParameterXref = domainParameterXref;
110114
this.sessionUidAccess = sessionUidAccess;
@@ -517,14 +521,14 @@ public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T
517521
);
518522

519523
return ReactiveExecuteWithTemporaryTableHelper
520-
.performBeforeTemporaryTableUseActions( idTable, executionContext )
524+
.performBeforeTemporaryTableUseActions( idTable, temporaryTableStrategy, executionContext )
521525
.thenCompose( v -> executeUsingIdTable( predicate, executionContext, jdbcParameterBindings )
522526
.handle( CompletionStages::handle )
523527
.thenCompose( resultHandler -> ReactiveExecuteWithTemporaryTableHelper
524528
.performAfterTemporaryTableUseActions(
525529
idTable,
526530
sessionUidAccess,
527-
afterUseAction,
531+
getAfterUseAction(),
528532
executionContext
529533
)
530534
.thenCompose( resultHandler::getResultAsCompletionStage )
@@ -637,4 +641,9 @@ private CompletionStage<Integer> deleteFromTableUsingIdTable(
637641
);
638642
}
639643

644+
protected AfterUseAction getAfterUseAction() {
645+
return forceDropAfterUse ? AfterUseAction.DROP : temporaryTableStrategy.getTemporaryTableAfterUseAction();
646+
}
647+
648+
640649
}

0 commit comments

Comments
 (0)