26
26
import org .hibernate .metamodel .mapping .ForeignKeyDescriptor ;
27
27
import org .hibernate .metamodel .mapping .PluralAttributeMapping ;
28
28
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
29
- import org .hibernate .persister .collection .mutation .CollectionTableMapping ;
30
29
import org .hibernate .persister .collection .mutation .DeleteRowsCoordinator ;
31
30
import org .hibernate .persister .collection .mutation .DeleteRowsCoordinatorNoOp ;
32
31
import org .hibernate .persister .collection .mutation .DeleteRowsCoordinatorStandard ;
44
43
import org .hibernate .persister .spi .PersisterCreationContext ;
45
44
import org .hibernate .sql .ast .SqlAstTranslator ;
46
45
import org .hibernate .sql .ast .tree .from .TableGroup ;
47
- import org .hibernate .sql .model .ast .ColumnValueParameterList ;
48
46
import org .hibernate .sql .model .ast .MutatingTableReference ;
49
47
import org .hibernate .sql .model .ast .RestrictedTableMutation ;
50
48
import org .hibernate .sql .model .ast .TableInsert ;
51
49
import org .hibernate .sql .model .ast .TableMutation ;
52
- import org .hibernate .sql .model .ast .builder .TableDeleteBuilderStandard ;
50
+ import org .hibernate .sql .model .ast .builder .CollectionRowDeleteBuilder ;
53
51
import org .hibernate .sql .model .ast .builder .TableInsertBuilderStandard ;
54
52
import org .hibernate .sql .model .ast .builder .TableUpdateBuilderStandard ;
55
- import org .hibernate .sql .model .jdbc .JdbcDeleteMutation ;
56
53
import org .hibernate .sql .model .jdbc .JdbcMutationOperation ;
57
- import org .hibernate .sql .model .jdbc .JdbcUpdateMutation ;
58
54
59
55
import static org .hibernate .sql .model .ModelMutationLogging .MODEL_MUTATION_LOGGER ;
60
56
@@ -410,40 +406,6 @@ else if ( attributeMapping.getIndexDescriptor() != null ) {
410
406
// Update handling
411
407
412
408
private JdbcMutationOperation generateUpdateRowOperation (MutatingTableReference tableReference ) {
413
- if ( getIdentifierTableMapping ().getUpdateDetails ().getCustomSql () != null ) {
414
- return buildCustomSqlUpdateRowOperation ( tableReference );
415
- }
416
-
417
- return buildGeneratedUpdateRowOperation ( tableReference );
418
-
419
- }
420
-
421
- private JdbcMutationOperation buildCustomSqlUpdateRowOperation (MutatingTableReference tableReference ) {
422
- final PluralAttributeMapping attribute = getAttributeMapping ();
423
- assert attribute != null ;
424
-
425
- final ForeignKeyDescriptor foreignKey = attribute .getKeyDescriptor ();
426
- assert foreignKey != null ;
427
-
428
- final int keyColumnCount = foreignKey .getJdbcTypeCount ();
429
- final ColumnValueParameterList parameterBinders = new ColumnValueParameterList (
430
- tableReference ,
431
- ParameterUsage .RESTRICT ,
432
- keyColumnCount
433
- );
434
- foreignKey .getKeyPart ().forEachSelectable ( parameterBinders );
435
-
436
- return new JdbcUpdateMutation (
437
- getCollectionTableMapping (),
438
- this ,
439
- getCollectionTableMapping ().getUpdateDetails ().getCustomSql (),
440
- getCollectionTableMapping ().getUpdateDetails ().isCallable (),
441
- getCollectionTableMapping ().getUpdateDetails ().getExpectation (),
442
- parameterBinders
443
- );
444
- }
445
-
446
- private JdbcMutationOperation buildGeneratedUpdateRowOperation (MutatingTableReference tableReference ) {
447
409
final RestrictedTableMutation <JdbcMutationOperation > sqlAst = generateUpdateRowAst ( tableReference );
448
410
449
411
final SqlAstTranslator <JdbcMutationOperation > translator = getFactory ().getJdbcServices ()
@@ -458,6 +420,7 @@ private RestrictedTableMutation<JdbcMutationOperation> generateUpdateRowAst(Muta
458
420
final PluralAttributeMapping attribute = getAttributeMapping ();
459
421
assert attribute != null ;
460
422
423
+ // note that custom sql update row details are handled by TableUpdateBuilderStandard
461
424
final TableUpdateBuilderStandard <?> updateBuilder = new TableUpdateBuilderStandard <>(
462
425
this ,
463
426
tableReference ,
@@ -620,41 +583,6 @@ private void applyUpdateRowRestrictions(
620
583
// Delete handling
621
584
622
585
private JdbcMutationOperation generateDeleteRowOperation (MutatingTableReference tableReference ) {
623
- if ( getIdentifierTableMapping ().getDeleteRowDetails ().getCustomSql () != null ) {
624
- return buildCustomSqlDeleteRowOperation ( tableReference );
625
- }
626
-
627
- return buildGeneratedDeleteRowOperation ( tableReference );
628
- }
629
-
630
- private JdbcMutationOperation buildCustomSqlDeleteRowOperation (MutatingTableReference tableReference ) {
631
- final PluralAttributeMapping attribute = getAttributeMapping ();
632
- assert attribute != null ;
633
-
634
- final ForeignKeyDescriptor foreignKey = attribute .getKeyDescriptor ();
635
- assert foreignKey != null ;
636
-
637
- final CollectionTableMapping tableMapping = (CollectionTableMapping ) tableReference .getTableMapping ();
638
-
639
- final int keyColumnCount = foreignKey .getJdbcTypeCount ();
640
- final ColumnValueParameterList parameterBinders = new ColumnValueParameterList (
641
- tableReference ,
642
- ParameterUsage .RESTRICT ,
643
- keyColumnCount
644
- );
645
- foreignKey .getKeyPart ().forEachSelectable ( parameterBinders );
646
-
647
- return new JdbcDeleteMutation (
648
- tableMapping ,
649
- this ,
650
- tableMapping .getDeleteDetails ().getCustomSql (),
651
- tableMapping .getDeleteDetails ().isCallable (),
652
- tableMapping .getDeleteDetails ().getExpectation (),
653
- parameterBinders
654
- );
655
- }
656
-
657
- private JdbcMutationOperation buildGeneratedDeleteRowOperation (MutatingTableReference tableReference ) {
658
586
final RestrictedTableMutation <JdbcMutationOperation > sqlAst = generateDeleteRowAst ( tableReference );
659
587
660
588
final SqlAstTranslator <JdbcMutationOperation > translator = getFactory ().getJdbcServices ()
@@ -672,7 +600,8 @@ private RestrictedTableMutation<JdbcMutationOperation> generateDeleteRowAst(Muta
672
600
final ForeignKeyDescriptor fkDescriptor = pluralAttribute .getKeyDescriptor ();
673
601
assert fkDescriptor != null ;
674
602
675
- final TableDeleteBuilderStandard deleteBuilder = new TableDeleteBuilderStandard (
603
+ // note that custom sql delete row details are handled by CollectionRowDeleteBuilder
604
+ final CollectionRowDeleteBuilder deleteBuilder = new CollectionRowDeleteBuilder (
676
605
this ,
677
606
tableReference ,
678
607
getFactory (),
0 commit comments