Package org.hibernate.engine.spi
Class ActionQueue
- java.lang.Object
-
- org.hibernate.engine.spi.ActionQueue
-
public class ActionQueue extends Object
Responsible for maintaining the queue of actions related to events. The ActionQueue holds the DML operations queued as part of a session's transactional-write-behind semantics. The DML operations are queued here until a flush forces them to be executed against the database.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classActionQueue.TransactionCompletionProcessesWrapper class allowing to bind the same transaction completion process queues in different sessions.
-
Constructor Summary
Constructors Constructor Description ActionQueue(SessionImplementor session)Constructs an action queue bound to the given session.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAction(org.hibernate.action.internal.BulkOperationCleanupAction action)Adds an action defining a cleanup relating to a bulk operation (HQL/JPQL or Criteria based update/delete)voidaddAction(org.hibernate.action.internal.CollectionRecreateAction action)Adds a collection (re)create actionvoidaddAction(org.hibernate.action.internal.CollectionRemoveAction action)Adds a collection remove actionvoidaddAction(org.hibernate.action.internal.CollectionUpdateAction action)Adds a collection update actionvoidaddAction(org.hibernate.action.internal.EntityDeleteAction action)Adds an entity delete actionvoidaddAction(org.hibernate.action.internal.EntityIdentityInsertAction action)Adds an entity (IDENTITY) insert actionvoidaddAction(org.hibernate.action.internal.EntityInsertAction action)Adds an entity insert actionvoidaddAction(org.hibernate.action.internal.EntityUpdateAction action)Adds an entity update actionvoidaddAction(org.hibernate.action.internal.OrphanRemovalAction action)Adds an orphan removal actionvoidaddAction(org.hibernate.action.internal.QueuedOperationCollectionAction action)Adds an action relating to a collection queued operation (extra lazy).voidafterTransactionCompletion(boolean success)Performs cleanup of any held cache soft locks.booleanareInsertionsOrDeletionsQueued()Check whether any insertion or deletion actions are currently queued.booleanareTablesToBeUpdated(Set tables)Check whether the given tables/query-spaces are to be executed against given the currently queued actions.voidbeforeTransactionCompletion()Execute any registeredBeforeTransactionCompletionProcessvoidcheckNoUnresolvedActionsAfterOperation()ThrowsPropertyValueExceptionif there are any unresolved entity insert actions that depend on non-nullable associations with a transient entity.voidclear()voidclearFromFlushNeededCheck(int previousCollectionRemovalSize)static ActionQueuedeserialize(ObjectInputStream ois, SessionImplementor session)Used by the owning session to explicitly control deserialization of the action queue.<E extends Executable & Comparable<?>>
voidexecute(E executable)voidexecuteActions()Perform all currently queued actions.voidexecuteInserts()Perform all currently queued entity-insertion actions.ActionQueue.TransactionCompletionProcessesgetTransactionCompletionProcesses()booleanhasAfterTransactionActions()booleanhasAnyQueuedActions()booleanhasBeforeTransactionActions()booleanhasUnresolvedEntityInsertActions()Are there unresolved entity insert actions that depend on non-nullable associations with a transient entity?intnumberOfCollectionCreations()intnumberOfCollectionRemovals()intnumberOfCollectionUpdates()intnumberOfDeletions()intnumberOfInsertions()intnumberOfUpdates()voidprepareActions()Prepares the internal action queues for execution.voidregisterProcess(AfterTransactionCompletionProcess process)voidregisterProcess(BeforeTransactionCompletionProcess process)voidserialize(ObjectOutputStream oos)Used by the owning session to explicitly control serialization of the action queuevoidsetTransactionCompletionProcesses(ActionQueue.TransactionCompletionProcesses processes, boolean isTransactionCoordinatorShared)Bind transaction completion processes to make them shared between primary and secondary session.voidsortActions()voidsortCollectionActions()StringtoString()Returns a string representation of the object.voidunScheduleDeletion(EntityEntry entry, Object rescuedEntity)
-
-
-
Constructor Detail
-
ActionQueue
public ActionQueue(SessionImplementor session)
Constructs an action queue bound to the given session.- Parameters:
session- The session "owning" this queue.
-
-
Method Detail
-
clear
public void clear()
-
addAction
public void addAction(org.hibernate.action.internal.EntityInsertAction action)
Adds an entity insert action- Parameters:
action- The action representing the entity insertion
-
addAction
public void addAction(org.hibernate.action.internal.EntityIdentityInsertAction action)
Adds an entity (IDENTITY) insert action- Parameters:
action- The action representing the entity insertion
-
addAction
public void addAction(org.hibernate.action.internal.EntityDeleteAction action)
Adds an entity delete action- Parameters:
action- The action representing the entity deletion
-
addAction
public void addAction(org.hibernate.action.internal.OrphanRemovalAction action)
Adds an orphan removal action- Parameters:
action- The action representing the orphan removal
-
addAction
public void addAction(org.hibernate.action.internal.EntityUpdateAction action)
Adds an entity update action- Parameters:
action- The action representing the entity update
-
addAction
public void addAction(org.hibernate.action.internal.CollectionRecreateAction action)
Adds a collection (re)create action- Parameters:
action- The action representing the (re)creation of a collection
-
addAction
public void addAction(org.hibernate.action.internal.CollectionRemoveAction action)
Adds a collection remove action- Parameters:
action- The action representing the removal of a collection
-
addAction
public void addAction(org.hibernate.action.internal.CollectionUpdateAction action)
Adds a collection update action- Parameters:
action- The action representing the update of a collection
-
addAction
public void addAction(org.hibernate.action.internal.QueuedOperationCollectionAction action)
Adds an action relating to a collection queued operation (extra lazy).- Parameters:
action- The action representing the queued operation
-
addAction
public void addAction(org.hibernate.action.internal.BulkOperationCleanupAction action)
Adds an action defining a cleanup relating to a bulk operation (HQL/JPQL or Criteria based update/delete)- Parameters:
action- The action representing the queued operation
-
hasUnresolvedEntityInsertActions
public boolean hasUnresolvedEntityInsertActions()
Are there unresolved entity insert actions that depend on non-nullable associations with a transient entity?- Returns:
- true, if there are unresolved entity insert actions that depend on non-nullable associations with a transient entity; false, otherwise
-
checkNoUnresolvedActionsAfterOperation
public void checkNoUnresolvedActionsAfterOperation() throws PropertyValueExceptionThrowsPropertyValueExceptionif there are any unresolved entity insert actions that depend on non-nullable associations with a transient entity. This method should be called on completion of an operation (after all cascades are completed) that saves an entity.- Throws:
PropertyValueException- if there are any unresolved entity insert actions;PropertyValueException.getEntityName()andPropertyValueException.getPropertyName()will return the entity name and property value for the first unresolved entity insert action.
-
registerProcess
public void registerProcess(AfterTransactionCompletionProcess process)
-
registerProcess
public void registerProcess(BeforeTransactionCompletionProcess process)
-
executeInserts
public void executeInserts() throws HibernateExceptionPerform all currently queued entity-insertion actions.- Throws:
HibernateException- error executing queued insertion actions.
-
executeActions
public void executeActions() throws HibernateExceptionPerform all currently queued actions.- Throws:
HibernateException- error executing queued actions.
-
prepareActions
public void prepareActions() throws HibernateExceptionPrepares the internal action queues for execution.- Throws:
HibernateException- error preparing actions.
-
afterTransactionCompletion
public void afterTransactionCompletion(boolean success)
Performs cleanup of any held cache soft locks.- Parameters:
success- Was the transaction successful.
-
beforeTransactionCompletion
public void beforeTransactionCompletion()
Execute any registeredBeforeTransactionCompletionProcess
-
areInsertionsOrDeletionsQueued
public boolean areInsertionsOrDeletionsQueued()
Check whether any insertion or deletion actions are currently queued.- Returns:
trueif insertions or deletions are currently queued;falseotherwise.
-
areTablesToBeUpdated
public boolean areTablesToBeUpdated(Set tables)
Check whether the given tables/query-spaces are to be executed against given the currently queued actions.- Parameters:
tables- The table/query-spaces to check.- Returns:
trueif we contain pending actions against any of the given tables;falseotherwise.
-
execute
public <E extends Executable & Comparable<?>> void execute(E executable)
- Parameters:
executable- The action to execute
-
toString
public String toString()
Returns a string representation of the object.
-
numberOfCollectionRemovals
public int numberOfCollectionRemovals()
-
numberOfCollectionUpdates
public int numberOfCollectionUpdates()
-
numberOfCollectionCreations
public int numberOfCollectionCreations()
-
numberOfDeletions
public int numberOfDeletions()
-
numberOfUpdates
public int numberOfUpdates()
-
numberOfInsertions
public int numberOfInsertions()
-
getTransactionCompletionProcesses
public ActionQueue.TransactionCompletionProcesses getTransactionCompletionProcesses()
-
setTransactionCompletionProcesses
public void setTransactionCompletionProcesses(ActionQueue.TransactionCompletionProcesses processes, boolean isTransactionCoordinatorShared)
Bind transaction completion processes to make them shared between primary and secondary session. Transaction completion processes are always executed by transaction owner (primary session), but can be registered using secondary session too.- Parameters:
processes- Transaction completion processes.isTransactionCoordinatorShared- Flag indicating shared transaction context.
-
sortCollectionActions
public void sortCollectionActions()
-
sortActions
public void sortActions()
-
clearFromFlushNeededCheck
public void clearFromFlushNeededCheck(int previousCollectionRemovalSize)
-
hasAfterTransactionActions
public boolean hasAfterTransactionActions()
-
hasBeforeTransactionActions
public boolean hasBeforeTransactionActions()
-
hasAnyQueuedActions
public boolean hasAnyQueuedActions()
-
unScheduleDeletion
public void unScheduleDeletion(EntityEntry entry, Object rescuedEntity)
-
serialize
public void serialize(ObjectOutputStream oos) throws IOException
Used by the owning session to explicitly control serialization of the action queue- Parameters:
oos- The stream to which the action queue should get written- Throws:
IOException- Indicates an error writing to the stream
-
deserialize
public static ActionQueue deserialize(ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException
Used by the owning session to explicitly control deserialization of the action queue.- Parameters:
ois- The stream from which to read the action queuesession- The session to which the action queue belongs- Returns:
- The deserialized action queue
- Throws:
IOException- indicates a problem reading from the streamClassNotFoundException- Generally means we were unable to locate user classes.
-
-