11
11
12
12
import org .hibernate .engine .jdbc .mutation .JdbcValueBindings ;
13
13
import org .hibernate .engine .jdbc .mutation .MutationExecutor ;
14
- import org .hibernate .engine .jdbc .mutation .ParameterUsage ;
15
14
import org .hibernate .engine .jdbc .mutation .group .PreparedStatementDetails ;
16
15
import org .hibernate .engine .jdbc .mutation .spi .MutationExecutorService ;
17
16
import org .hibernate .engine .spi .SessionFactoryImplementor ;
18
17
import org .hibernate .engine .spi .SharedSessionContractImplementor ;
19
- import org .hibernate .metamodel .mapping .EntityRowIdMapping ;
20
18
import org .hibernate .persister .entity .AbstractEntityPersister ;
21
19
import org .hibernate .persister .entity .mutation .DeleteCoordinator ;
22
20
import org .hibernate .persister .entity .mutation .EntityTableMapping ;
25
23
import org .hibernate .reactive .engine .jdbc .env .internal .ReactiveMutationExecutor ;
26
24
import org .hibernate .reactive .logging .impl .Log ;
27
25
import org .hibernate .reactive .logging .impl .LoggerFactory ;
26
+ import org .hibernate .sql .model .MutationOperation ;
28
27
import org .hibernate .sql .model .MutationOperationGroup ;
29
28
30
29
import static org .hibernate .engine .jdbc .mutation .internal .ModelMutationHelper .identifiedResultsCheck ;
@@ -51,7 +50,7 @@ public CompletionStage<Void> coordinateReactiveDelete(Object entity, Object id,
51
50
super .coordinateDelete ( entity , id , version , session );
52
51
return stage != null ? stage : voidFuture ();
53
52
}
54
- catch (Throwable t ) {
53
+ catch (RuntimeException t ) {
55
54
if ( stage == null ) {
56
55
return failedFuture ( t );
57
56
}
@@ -61,17 +60,18 @@ public CompletionStage<Void> coordinateReactiveDelete(Object entity, Object id,
61
60
}
62
61
63
62
@ Override
64
- protected void doDynamicDelete (Object entity , Object id , Object rowId , Object [] loadedState , SharedSessionContractImplementor session ) {
63
+ protected void doDynamicDelete (Object entity , Object id , Object [] loadedState , SharedSessionContractImplementor session ) {
65
64
stage = new CompletableFuture <>();
66
- final MutationOperationGroup operationGroup = generateOperationGroup ( loadedState , true , session );
65
+ final MutationOperationGroup operationGroup = generateOperationGroup ( null , loadedState , true , session );
67
66
final ReactiveMutationExecutor mutationExecutor = mutationExecutor ( session , operationGroup );
68
67
69
- operationGroup .forEachOperation ( (position , mutation ) -> {
68
+ for ( int i = 0 ; i < operationGroup .getNumberOfOperations (); i ++ ) {
69
+ final MutationOperation mutation = operationGroup .getOperation ( i );
70
70
if ( mutation != null ) {
71
71
final String tableName = mutation .getTableDetails ().getTableName ();
72
72
mutationExecutor .getPreparedStatementDetails ( tableName );
73
73
}
74
- } );
74
+ }
75
75
76
76
applyLocking ( null , loadedState , mutationExecutor , session );
77
77
applyId ( id , null , mutationExecutor , getStaticDeleteGroup (), session );
@@ -102,44 +102,49 @@ protected void applyId(
102
102
MutationOperationGroup operationGroup ,
103
103
SharedSessionContractImplementor session ) {
104
104
final JdbcValueBindings jdbcValueBindings = mutationExecutor .getJdbcValueBindings ();
105
- final EntityRowIdMapping rowIdMapping = entityPersister ().getRowIdMapping ();
106
105
107
- operationGroup .forEachOperation ( (position , jdbcMutation ) -> {
106
+ for ( int position = 0 ; position < operationGroup .getNumberOfOperations (); position ++ ) {
107
+ final MutationOperation jdbcMutation = operationGroup .getOperation ( position );
108
108
final EntityTableMapping tableDetails = (EntityTableMapping ) jdbcMutation .getTableDetails ();
109
- breakDownIdJdbcValues ( id , rowId , session , jdbcValueBindings , rowIdMapping , tableDetails );
109
+ breakDownKeyJdbcValues ( id , rowId , session , jdbcValueBindings , tableDetails );
110
110
final PreparedStatementDetails statementDetails = mutationExecutor .getPreparedStatementDetails ( tableDetails .getTableName () );
111
111
if ( statementDetails != null ) {
112
112
PreparedStatementAdaptor .bind ( statement -> {
113
- PrepareStatementDetailsAdaptor detailsAdaptor = new PrepareStatementDetailsAdaptor ( statementDetails , statement , session .getJdbcServices () );
113
+ PrepareStatementDetailsAdaptor detailsAdaptor = new PrepareStatementDetailsAdaptor (
114
+ statementDetails ,
115
+ statement ,
116
+ session .getJdbcServices ()
117
+ );
114
118
// force creation of the PreparedStatement
115
119
//noinspection resource
116
120
detailsAdaptor .resolveStatement ();
117
121
} );
118
122
}
119
- } );
123
+ }
120
124
}
121
125
122
126
@ Override
123
- protected void doStaticDelete (Object entity , Object id , Object [] loadedState , Object version , SharedSessionContractImplementor session ) {
127
+ protected void doStaticDelete (Object entity , Object id , Object rowId , Object [] loadedState , Object version , SharedSessionContractImplementor session ) {
124
128
stage = new CompletableFuture <>();
125
129
final boolean applyVersion = entity != null ;
126
130
final MutationOperationGroup operationGroupToUse = entity == null
127
131
? resolveNoVersionDeleteGroup ( session )
128
132
: getStaticDeleteGroup ();
129
133
130
134
final ReactiveMutationExecutor mutationExecutor = mutationExecutor ( session , operationGroupToUse );
131
- getStaticDeleteGroup ().forEachOperation ( (position , mutation ) -> {
135
+ for ( int position = 0 ; position < getStaticDeleteGroup ().getNumberOfOperations (); position ++ ) {
136
+ final MutationOperation mutation = getStaticDeleteGroup ().getOperation ( position );
132
137
if ( mutation != null ) {
133
138
mutationExecutor .getPreparedStatementDetails ( mutation .getTableDetails ().getTableName () );
134
139
}
135
- } );
140
+ }
136
141
137
142
if ( applyVersion ) {
138
143
applyLocking ( version , null , mutationExecutor , session );
139
144
}
140
145
final JdbcValueBindings jdbcValueBindings = mutationExecutor .getJdbcValueBindings ();
141
146
bindPartitionColumnValueBindings ( loadedState , session , jdbcValueBindings );
142
- applyId ( id , null , mutationExecutor , getStaticDeleteGroup (), session );
147
+ applyId ( id , rowId , mutationExecutor , getStaticDeleteGroup (), session );
143
148
mutationExecutor .executeReactive (
144
149
entity ,
145
150
null ,
@@ -158,38 +163,6 @@ protected void doStaticDelete(Object entity, Object id, Object[] loadedState, Ob
158
163
.whenComplete ( this ::complete );
159
164
}
160
165
161
- /**
162
- * Copy and paste of the on in ORM
163
- */
164
- private static void breakDownIdJdbcValues (
165
- Object id ,
166
- Object rowId ,
167
- SharedSessionContractImplementor session ,
168
- JdbcValueBindings jdbcValueBindings ,
169
- EntityRowIdMapping rowIdMapping ,
170
- EntityTableMapping tableDetails ) {
171
- if ( rowId != null && rowIdMapping != null && tableDetails .isIdentifierTable () ) {
172
- jdbcValueBindings .bindValue (
173
- rowId ,
174
- tableDetails .getTableName (),
175
- rowIdMapping .getRowIdName (),
176
- ParameterUsage .RESTRICT
177
- );
178
- }
179
- else {
180
- tableDetails .getKeyMapping ().breakDownKeyJdbcValues (
181
- id ,
182
- (jdbcValue , columnMapping ) -> jdbcValueBindings .bindValue (
183
- jdbcValue ,
184
- tableDetails .getTableName (),
185
- columnMapping .getColumnName (),
186
- ParameterUsage .RESTRICT
187
- ),
188
- session
189
- );
190
- }
191
- }
192
-
193
166
private void complete (Object o , Throwable throwable ) {
194
167
if ( throwable != null ) {
195
168
stage .toCompletableFuture ().completeExceptionally ( throwable );
0 commit comments