Class ActionQueue.InsertActionSorter

java.lang.Object
org.hibernate.engine.spi.ActionQueue.InsertActionSorter
All Implemented Interfaces:
ExecutableList.Sorter<org.hibernate.action.internal.AbstractEntityInsertAction>
Enclosing class:
ActionQueue

public static class ActionQueue.InsertActionSorter extends Object implements ExecutableList.Sorter<org.hibernate.action.internal.AbstractEntityInsertAction>
Order the ActionQueue.insertions queue such that we group inserts against the same entity together (without violating constraints). The original order is generated by cascade order, which in turn is based on the directionality of foreign-keys. So even though we will be changing the ordering here, we need to make absolutely certain that we do not circumvent this FK ordering to the extent of causing constraint violations.

The algorithm first discovers the transitive incoming dependencies for every insert action and groups all inserts by the entity name. Finally, it schedules these groups one by one, as long as all the dependencies of the groups are fulfilled.

The implementation will only produce an optimal insert order for the insert groups that can be perfectly scheduled serially. Scheduling serially means, that there is an order which doesn't violate the FK constraint dependencies. The inserts of insert groups which can't be scheduled, are going to be inserted in the original order.
  • Field Details

  • Constructor Details

    • InsertActionSorter

      public InsertActionSorter()
  • Method Details

    • sort

      public void sort(List<org.hibernate.action.internal.AbstractEntityInsertAction> insertions)
      Sort the insert actions.
      Specified by:
      sort in interface ExecutableList.Sorter<org.hibernate.action.internal.AbstractEntityInsertAction>