Class DefaultActionQueue

java.lang.Object
io.github.blyznytsiaorg.bibernate.actionqueue.impl.DefaultActionQueue
All Implemented Interfaces:
ActionQueue

public class DefaultActionQueue extends Object implements ActionQueue
Default implementation of the ActionQueue interface. Manages and executes entity actions categorized by their types, including insert, update, and delete operations. This class ensures proper handling of interdependencies between different types of actions during execution.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

    • entityActions

      private final Map<ActionType,Set<EntityAction>> entityActions
      A map that categorizes entity actions based on their types (INSERT, UPDATE, DELETE).
    • isExecuted

      private boolean isExecuted
      Flag indicating whether the action queue has been executed. When 'true', it signifies that the action queue should not perform any execution of entity actions, providing control over the processing flow.
  • Constructor Details

    • DefaultActionQueue

      public DefaultActionQueue()
  • Method Details

    • executeEntityAction

      public void executeEntityAction()
      Executes entity actions in the order of INSERT, UPDATE, and DELETE types. Clears the entity actions map after execution.
      Specified by:
      executeEntityAction in interface ActionQueue
    • addEntityAction

      public void addEntityAction(EntityAction entityAction)
      Adds an entity action to the corresponding type category in the entity actions map.
      Specified by:
      addEntityAction in interface ActionQueue
      Parameters:
      entityAction - The entity action to be added.
    • isNotExecuted

      public boolean isNotExecuted()
      Checks if the action queue is set to not execute actions. When this method returns true, it indicates that the action queue is in a state where it should not perform any execution of entity actions.
      Specified by:
      isNotExecuted in interface ActionQueue
      Returns:
      true if the action queue is set to not execute actions, false otherwise.
    • initEntityActions

      private void initEntityActions()
      Initializes the entity actions map to ensure each type category has an associated set.
    • addInsertAction

      private void addInsertAction(EntityAction insertEntityAction)
      Adds an INSERT type entity action to the entity actions map, taking into account interdependencies with UPDATE and DELETE type actions.
      Parameters:
      insertEntityAction - The INSERT type entity action to be added.
    • addUpdateAction

      private void addUpdateAction(EntityAction updateEntityAction)
      Adds an UPDATE type entity action to the entity actions map, taking into account interdependencies with INSERT and DELETE type actions.
      Parameters:
      updateEntityAction - The UPDATE type entity action to be added.
    • addDeleteAction

      private void addDeleteAction(EntityAction deleteEntityAction)
      Adds a DELETE type entity action to the entity actions map, taking into account interdependencies with INSERT and UPDATE type actions.
      Parameters:
      deleteEntityAction - The DELETE type entity action to be added.
    • executeInsertEntityAction

      private void executeInsertEntityAction(Set<EntityAction> insertEntityActions)
      Executes INSERT type entity actions.
      Parameters:
      insertEntityActions - The set of INSERT type entity actions to be executed.
    • executeUpdateEntityAction

      private void executeUpdateEntityAction(Set<EntityAction> updateEntityActions)
      Executes UPDATE type entity actions.
      Parameters:
      updateEntityActions - The set of UPDATE type entity actions to be executed.
    • executeDeleteEntityAction

      private void executeDeleteEntityAction(Set<EntityAction> deleteEntityActions)
      Executes DELETE type entity actions.
      Parameters:
      deleteEntityActions - The set of DELETE type entity actions to be executed.
    • executeIfNotEmpty

      private <T extends Collection<?>> void executeIfNotEmpty(Consumer<T> consumer, T collections)
      Executes a consumer on a collection if the collection is not empty.
      Type Parameters:
      T - The type of the collection.
      Parameters:
      consumer - The consumer to be executed.
      collections - The collection to be checked and passed to the consumer if not empty.