12
12
import org .hibernate .engine .jdbc .mutation .MutationExecutor ;
13
13
import org .hibernate .engine .jdbc .mutation .ParameterUsage ;
14
14
import org .hibernate .engine .jdbc .mutation .group .PreparedStatementDetails ;
15
- import org .hibernate .engine .jdbc .mutation .spi .MutationExecutorService ;
16
15
import org .hibernate .engine .spi .EntityEntry ;
17
16
import org .hibernate .engine .spi .PersistenceContext ;
18
17
import org .hibernate .engine .spi .SessionFactoryImplementor ;
19
18
import org .hibernate .engine .spi .SharedSessionContractImplementor ;
20
19
import org .hibernate .metamodel .mapping .AttributeMapping ;
21
20
import org .hibernate .metamodel .mapping .AttributeMappingsList ;
22
- import org .hibernate .metamodel .mapping .EntityRowIdMapping ;
23
21
import org .hibernate .metamodel .mapping .EntityVersionMapping ;
24
22
import org .hibernate .metamodel .mapping .SelectableMapping ;
25
23
import org .hibernate .persister .entity .AbstractEntityPersister ;
26
24
import org .hibernate .sql .model .MutationOperation ;
27
25
import org .hibernate .sql .model .MutationOperationGroup ;
28
26
import org .hibernate .sql .model .MutationType ;
29
- import org .hibernate .sql .model .ast .ColumnValueBinding ;
30
27
import org .hibernate .sql .model .ast .ColumnValueBindingList ;
31
28
import org .hibernate .sql .model .ast .builder .MutationGroupBuilder ;
32
29
import org .hibernate .sql .model .ast .builder .RestrictedTableMutationBuilder ;
@@ -52,7 +49,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
52
49
public DeleteCoordinator (AbstractEntityPersister entityPersister , SessionFactoryImplementor factory ) {
53
50
super ( entityPersister , factory );
54
51
55
- this .staticOperationGroup = generateOperationGroup ( null , true , null );
52
+ this .staticOperationGroup = generateOperationGroup ( "" , null , true , null );
56
53
this .batchKey = new BasicBatchKey ( entityPersister .getEntityName () + "#DELETE" );
57
54
58
55
if ( !entityPersister .isVersioned () ) {
@@ -79,24 +76,23 @@ public void coordinateDelete(
79
76
80
77
final PersistenceContext persistenceContext = session .getPersistenceContextInternal ();
81
78
final EntityEntry entry = persistenceContext .getEntry ( entity );
82
- final Object [] loadedState = entry != null && isImpliedOptimisticLocking ? entry .getLoadedState () : null ;
83
- final Object rowId = entry != null && entityPersister (). hasRowId () ? entry .getRowId () : null ;
79
+ final Object [] loadedState = entry != null ? entry .getLoadedState () : null ;
80
+ final Object rowId = entry != null ? entry .getRowId () : null ;
84
81
85
- if ( ( isImpliedOptimisticLocking && loadedState != null ) || rowId != null ) {
86
- doDynamicDelete ( entity , id , rowId , loadedState , session );
82
+ if ( ( isImpliedOptimisticLocking && loadedState != null ) || ( rowId == null && entityPersister (). hasRowId () ) ) {
83
+ doDynamicDelete ( entity , id , loadedState , session );
87
84
}
88
85
else {
89
- doStaticDelete ( entity , id , entry == null ? null : entry . getLoadedState () , version , session );
86
+ doStaticDelete ( entity , id , rowId , loadedState , version , session );
90
87
}
91
88
}
92
89
93
90
protected void doDynamicDelete (
94
91
Object entity ,
95
92
Object id ,
96
- Object rowId ,
97
93
Object [] loadedState ,
98
94
SharedSessionContractImplementor session ) {
99
- final MutationOperationGroup operationGroup = generateOperationGroup ( loadedState , true , session );
95
+ final MutationOperationGroup operationGroup = generateOperationGroup ( null , loadedState , true , session );
100
96
101
97
final MutationExecutor mutationExecutor = executor ( session , operationGroup );
102
98
@@ -110,7 +106,7 @@ protected void doDynamicDelete(
110
106
111
107
applyLocking ( null , loadedState , mutationExecutor , session );
112
108
113
- applyId ( id , rowId , mutationExecutor , operationGroup , session );
109
+ applyId ( id , null , mutationExecutor , operationGroup , session );
114
110
115
111
try {
116
112
mutationExecutor .execute (
@@ -217,14 +213,11 @@ protected void applyId(
217
213
MutationExecutor mutationExecutor ,
218
214
MutationOperationGroup operationGroup ,
219
215
SharedSessionContractImplementor session ) {
220
-
221
216
final JdbcValueBindings jdbcValueBindings = mutationExecutor .getJdbcValueBindings ();
222
- final EntityRowIdMapping rowIdMapping = entityPersister ().getRowIdMapping ();
223
-
224
217
for ( int position = 0 ; position < operationGroup .getNumberOfOperations (); position ++ ) {
225
218
final MutationOperation jdbcMutation = operationGroup .getOperation ( position );
226
219
final EntityTableMapping tableDetails = (EntityTableMapping ) jdbcMutation .getTableDetails ();
227
- breakDownIdJdbcValues ( id , rowId , session , jdbcValueBindings , rowIdMapping , tableDetails );
220
+ breakDownKeyJdbcValues ( id , rowId , session , jdbcValueBindings , tableDetails );
228
221
final PreparedStatementDetails statementDetails = mutationExecutor .getPreparedStatementDetails ( tableDetails .getTableName () );
229
222
if ( statementDetails != null ) {
230
223
// force creation of the PreparedStatement
@@ -234,40 +227,10 @@ protected void applyId(
234
227
}
235
228
}
236
229
237
- private static void breakDownIdJdbcValues (
238
- Object id ,
239
- Object rowId ,
240
- SharedSessionContractImplementor session ,
241
- JdbcValueBindings jdbcValueBindings ,
242
- EntityRowIdMapping rowIdMapping ,
243
- EntityTableMapping tableDetails ) {
244
- if ( rowId != null && rowIdMapping != null && tableDetails .isIdentifierTable () ) {
245
- jdbcValueBindings .bindValue (
246
- rowId ,
247
- tableDetails .getTableName (),
248
- rowIdMapping .getRowIdName (),
249
- ParameterUsage .RESTRICT
250
- );
251
- }
252
- else {
253
- tableDetails .getKeyMapping ().breakDownKeyJdbcValues (
254
- id ,
255
- (jdbcValue , columnMapping ) -> {
256
- jdbcValueBindings .bindValue (
257
- jdbcValue ,
258
- tableDetails .getTableName (),
259
- columnMapping .getColumnName (),
260
- ParameterUsage .RESTRICT
261
- );
262
- },
263
- session
264
- );
265
- }
266
- }
267
-
268
230
protected void doStaticDelete (
269
231
Object entity ,
270
232
Object id ,
233
+ Object rowId ,
271
234
Object [] loadedState ,
272
235
Object version ,
273
236
SharedSessionContractImplementor session ) {
@@ -299,7 +262,7 @@ protected void doStaticDelete(
299
262
300
263
bindPartitionColumnValueBindings ( loadedState , session , jdbcValueBindings );
301
264
302
- applyId ( id , null , mutationExecutor , staticOperationGroup , session );
265
+ applyId ( id , rowId , mutationExecutor , staticOperationGroup , session );
303
266
304
267
mutationExecutor .execute (
305
268
entity ,
@@ -321,13 +284,14 @@ protected void doStaticDelete(
321
284
322
285
protected MutationOperationGroup resolveNoVersionDeleteGroup (SharedSessionContractImplementor session ) {
323
286
if ( noVersionDeleteGroup == null ) {
324
- noVersionDeleteGroup = generateOperationGroup ( null , false , session );
287
+ noVersionDeleteGroup = generateOperationGroup ( "" , null , false , session );
325
288
}
326
289
327
290
return noVersionDeleteGroup ;
328
291
}
329
292
330
293
protected MutationOperationGroup generateOperationGroup (
294
+ Object rowId ,
331
295
Object [] loadedState ,
332
296
boolean applyVersion ,
333
297
SharedSessionContractImplementor session ) {
@@ -340,21 +304,22 @@ protected MutationOperationGroup generateOperationGroup(
340
304
deleteGroupBuilder .addTableDetailsBuilder ( tableDeleteBuilder );
341
305
} );
342
306
343
- applyTableDeleteDetails ( deleteGroupBuilder , loadedState , applyVersion , session );
307
+ applyTableDeleteDetails ( deleteGroupBuilder , rowId , loadedState , applyVersion , session );
344
308
345
309
return createOperationGroup ( null , deleteGroupBuilder .buildMutationGroup () );
346
310
}
347
311
348
312
private void applyTableDeleteDetails (
349
313
MutationGroupBuilder deleteGroupBuilder ,
314
+ Object rowId ,
350
315
Object [] loadedState ,
351
316
boolean applyVersion ,
352
317
SharedSessionContractImplementor session ) {
353
318
// first, the table key column(s)
354
319
deleteGroupBuilder .forEachTableMutationBuilder ( (builder ) -> {
355
320
final EntityTableMapping tableMapping = (EntityTableMapping ) builder .getMutatingTable ().getTableMapping ();
356
321
final TableDeleteBuilder tableDeleteBuilder = (TableDeleteBuilder ) builder ;
357
- applyKeyDetails ( tableDeleteBuilder , tableMapping );
322
+ applyKeyRestriction ( rowId , entityPersister (), tableDeleteBuilder , tableMapping );
358
323
} );
359
324
360
325
if ( applyVersion ) {
@@ -382,10 +347,6 @@ private void applyTableDeleteDetails(
382
347
// todo (6.2) : apply where + where-fragments
383
348
}
384
349
385
- private static void applyKeyDetails (TableDeleteBuilder tableDeleteBuilder , EntityTableMapping tableMapping ) {
386
- tableDeleteBuilder .addKeyRestrictions ( tableMapping .getKeyMapping () );
387
- }
388
-
389
350
protected void applyOptimisticLocking (
390
351
MutationGroupBuilder mutationGroupBuilder ,
391
352
Object [] loadedState ,
0 commit comments