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. DML operations are queued here
until a flush forces them to be executed against the database.
Method from org.hibernate.engine.ActionQueue Detail: |
public void addAction(EntityInsertAction action) {
insertions.add( action );
}
|
public void addAction(EntityDeleteAction action) {
deletions.add( action );
}
|
public void addAction(EntityUpdateAction action) {
updates.add( action );
}
|
public void addAction(CollectionRecreateAction action) {
collectionCreations.add( action );
}
|
public void addAction(CollectionRemoveAction action) {
collectionRemovals.add( action );
}
|
public void addAction(CollectionUpdateAction action) {
collectionUpdates.add( action );
}
|
public void addAction(EntityIdentityInsertAction insert) {
insertions.add( insert );
}
|
public void addAction(BulkOperationCleanupAction cleanupAction) {
// Add these directly to the executions queue
executions.add( cleanupAction );
}
|
public void afterTransactionCompletion(boolean success) {
int size = executions.size();
final boolean invalidateQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();
for ( int i = 0; i < size; i++ ) {
try {
Executable exec = ( Executable ) executions.get( i );
try {
exec.afterTransactionCompletion( success );
}
finally {
if ( invalidateQueryCache ) {
session.getFactory().getUpdateTimestampsCache().invalidate( exec.getPropertySpaces() );
}
}
}
catch ( CacheException ce ) {
log.error( "could not release a cache lock", ce );
// continue loop
}
catch ( Exception e ) {
throw new AssertionFailure( "Exception releasing cache locks", e );
}
}
executions.clear();
}
Performs cleanup of any held cache softlocks. |
public boolean areInsertionsOrDeletionsQueued() {
return ( insertions.size() > 0 || deletions.size() > 0 );
}
Check whether any insertion or deletion actions are currently queued. |
public boolean areTablesToBeUpdated(Set tables) {
return areTablesToUpdated( updates, tables ) ||
areTablesToUpdated( insertions, tables ) ||
areTablesToUpdated( deletions, tables ) ||
areTablesToUpdated( collectionUpdates, tables ) ||
areTablesToUpdated( collectionCreations, tables ) ||
areTablesToUpdated( collectionRemovals, tables );
}
Check whether the given tables/query-spaces are to be executed against
given the currently queued actions. |
public void clear() {
updates.clear();
insertions.clear();
deletions.clear();
collectionCreations.clear();
collectionRemovals.clear();
collectionUpdates.clear();
}
|
public void clearFromFlushNeededCheck(int previousCollectionRemovalSize) {
collectionCreations.clear();
collectionUpdates.clear();
updates.clear();
// collection deletions are a special case since update() can add
// deletions of collections not loaded by the session.
for ( int i = collectionRemovals.size() - 1; i >= previousCollectionRemovalSize; i-- ) {
collectionRemovals.remove( i );
}
}
|
public ArrayList cloneDeletions() {
return ( ArrayList ) deletions.clone();
}
|
public static ActionQueue deserialize(ObjectInputStream ois,
SessionImplementor session) throws IOException, ClassNotFoundException {
log.trace( "deserializing action-queue" );
ActionQueue rtn = new ActionQueue( session );
int queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] insertions entries" );
rtn.insertions = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.insertions.add( ois.readObject() );
}
queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] deletions entries" );
rtn.deletions = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.deletions.add( ois.readObject() );
}
queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] updates entries" );
rtn.updates = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.updates.add( ois.readObject() );
}
queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] collectionUpdates entries" );
rtn.collectionUpdates = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.collectionUpdates.add( ois.readObject() );
}
queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] collectionRemovals entries" );
rtn.collectionRemovals = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.collectionRemovals.add( ois.readObject() );
}
queueSize = ois.readInt();
log.trace( "starting deserialization of [" + queueSize + "] collectionCreations entries" );
rtn.collectionCreations = new ArrayList( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
rtn.collectionCreations.add( ois.readObject() );
}
return rtn;
}
Used by the owning session to explicitly control deserialization of the
action queue |
public void execute(Executable executable) {
final boolean lockQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();
if ( executable.hasAfterTransactionCompletion() || lockQueryCache ) {
executions.add( executable );
}
if ( lockQueryCache ) {
session.getFactory()
.getUpdateTimestampsCache()
.preinvalidate( executable.getPropertySpaces() );
}
executable.execute();
}
|
public void executeActions() throws HibernateException {
executeActions( insertions );
executeActions( updates );
executeActions( collectionRemovals );
executeActions( collectionUpdates );
executeActions( collectionCreations );
executeActions( deletions );
}
Perform all currently queued actions. |
public void executeInserts() throws HibernateException {
executeActions( insertions );
}
Perform all currently queued entity-insertion actions. |
public boolean hasAfterTransactionActions() {
return executions.size() > 0;
}
|
public boolean hasAnyQueuedActions() {
return updates.size() > 0 ||
insertions.size() > 0 ||
deletions.size() > 0 ||
collectionUpdates.size() > 0 ||
collectionRemovals.size() > 0 ||
collectionCreations.size() > 0;
}
|
public int numberOfCollectionCreations() {
return collectionCreations.size();
}
|
public int numberOfCollectionRemovals() {
return collectionRemovals.size();
}
|
public int numberOfCollectionUpdates() {
return collectionUpdates.size();
}
|
public int numberOfDeletions() {
return deletions.size();
}
|
public int numberOfInsertions() {
return insertions.size();
}
|
public int numberOfUpdates() {
return updates.size();
}
|
public void prepareActions() throws HibernateException {
prepareActions( collectionRemovals );
prepareActions( collectionUpdates );
prepareActions( collectionCreations );
}
Prepares the internal action queues for execution. |
public void serialize(ObjectOutputStream oos) throws IOException {
log.trace( "serializing action-queue" );
int queueSize = insertions.size();
log.trace( "starting serialization of [" + queueSize + "] insertions entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( insertions.get( i ) );
}
queueSize = deletions.size();
log.trace( "starting serialization of [" + queueSize + "] deletions entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( deletions.get( i ) );
}
queueSize = updates.size();
log.trace( "starting serialization of [" + queueSize + "] updates entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( updates.get( i ) );
}
queueSize = collectionUpdates.size();
log.trace( "starting serialization of [" + queueSize + "] collectionUpdates entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( collectionUpdates.get( i ) );
}
queueSize = collectionRemovals.size();
log.trace( "starting serialization of [" + queueSize + "] collectionRemovals entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( collectionRemovals.get( i ) );
}
queueSize = collectionCreations.size();
log.trace( "starting serialization of [" + queueSize + "] collectionCreations entries" );
oos.writeInt( queueSize );
for ( int i = 0; i < queueSize; i++ ) {
oos.writeObject( collectionCreations.get( i ) );
}
}
Used by the owning session to explicitly control serialization of the
action queue |
public void sortActions() {
if ( session.getFactory().getSettings().isOrderUpdatesEnabled() ) {
//sort the updates by pk
java.util.Collections.sort( updates );
}
if ( session.getFactory().getSettings().isOrderInsertsEnabled() ) {
sortInsertActions();
}
}
|
public void sortCollectionActions() {
if ( session.getFactory().getSettings().isOrderUpdatesEnabled() ) {
//sort the updates by fk
java.util.Collections.sort( collectionCreations );
java.util.Collections.sort( collectionUpdates );
java.util.Collections.sort( collectionRemovals );
}
}
|
public String toString() {
return new StringBuffer()
.append( "ActionQueue[insertions=" ).append( insertions )
.append( " updates=" ).append( updates )
.append( " deletions=" ).append( deletions )
.append( " collectionCreations=" ).append( collectionCreations )
.append( " collectionRemovals=" ).append( collectionRemovals )
.append( " collectionUpdates=" ).append( collectionUpdates )
.append( "]" )
.toString();
}
Returns a string representation of the object. |