FileDocCategorySizeDatePackage
CollectionAction.javaAPI DocHibernate 3.2.54236Wed Mar 22 07:58:00 GMT 2006org.hibernate.action

CollectionAction

public abstract class CollectionAction extends Object implements Serializable, Comparable, Executable
Any action relating to insert/update/delete of a collection
author
Gavin King

Fields Summary
private transient org.hibernate.persister.collection.CollectionPersister
persister
private final Serializable
key
private Serializable
finalKey
private final org.hibernate.engine.SessionImplementor
session
private org.hibernate.cache.CacheConcurrencyStrategy.SoftLock
lock
private final String
collectionRole
private final org.hibernate.collection.PersistentCollection
collection
Constructors Summary
public CollectionAction(org.hibernate.persister.collection.CollectionPersister persister, org.hibernate.collection.PersistentCollection collection, Serializable key, org.hibernate.engine.SessionImplementor session)

		this.persister = persister;
		this.session = session;
		this.key = key;
		this.collectionRole = persister.getRole();
		this.collection = collection;
	
Methods Summary
public voidafterTransactionCompletion(boolean success)

		if ( persister.hasCache() ) {
			final CacheKey ck = new CacheKey( 
					key, 
					persister.getKeyType(), 
					persister.getRole(), 
					session.getEntityMode(), 
					session.getFactory() 
				);
			persister.getCache().release(ck, lock);
		}
	
public final voidbeforeExecutions()

		// we need to obtain the lock before any actions are
		// executed, since this may be an inverse="true"
		// bidirectional association and it is one of the
		// earlier entity actions which actually updates
		// the database (this action is resposible for
		// second-level cache invalidation only)
		if ( persister.hasCache() ) {
			final CacheKey ck = new CacheKey( 
					key, 
					persister.getKeyType(), 
					persister.getRole(), 
					session.getEntityMode(), 
					session.getFactory() 
				);
			lock = persister.getCache().lock(ck, null);
		}
	
public intcompareTo(java.lang.Object other)

		CollectionAction action = ( CollectionAction ) other;
		//sort first by role name
		int roleComparison = collectionRole.compareTo( action.collectionRole );
		if ( roleComparison != 0 ) {
			return roleComparison;
		}
		else {
			//then by fk
			return persister.getKeyType()
					.compare( key, action.key, session.getEntityMode() );
		}
	
protected final voidevict()

		if ( persister.hasCache() ) {
			CacheKey ck = new CacheKey( 
					key, 
					persister.getKeyType(), 
					persister.getRole(), 
					session.getEntityMode(), 
					session.getFactory() 
				);
			persister.getCache().evict(ck);
		}
	
protected org.hibernate.collection.PersistentCollectiongetCollection()

		return collection;
	
protected final java.io.SerializablegetKey()

		finalKey = key;
		if ( key instanceof DelayedPostInsertIdentifier ) {
			// need to look it up from the persistence-context
			finalKey = session.getPersistenceContext().getEntry( collection.getOwner() ).getId();
			if ( finalKey == key ) {
				// we may be screwed here since the collection action is about to execute
				// and we do not know the final owner key value
			}
		}
		return finalKey;
	
protected final org.hibernate.persister.collection.CollectionPersistergetPersister()

		return persister;
	
public java.io.Serializable[]getPropertySpaces()

		return persister.getCollectionSpaces();
	
protected final org.hibernate.engine.SessionImplementorgetSession()

		return session;
	
public booleanhasAfterTransactionCompletion()

		return persister.hasCache();
	
private voidreadObject(java.io.ObjectInputStream ois)

		ois.defaultReadObject();
		persister = session.getFactory().getCollectionPersister( collectionRole );
	
public java.lang.StringtoString()

		return StringHelper.unqualify( getClass().getName() ) + 
				MessageHelper.infoString( collectionRole, key );