FileDocCategorySizeDatePackage
BulkOperationCleanupAction.javaAPI DocHibernate 3.2.54975Thu Mar 29 14:36:34 BST 2007org.hibernate.action

BulkOperationCleanupAction

public class BulkOperationCleanupAction extends Object implements Serializable, Executable
Implementation of BulkOperationCleanupAction.
author
Steve Ebersole

Fields Summary
private final org.hibernate.engine.SessionImplementor
session
private final Set
affectedEntityNames
private final Set
affectedCollectionRoles
private final Serializable[]
spaces
Constructors Summary
public BulkOperationCleanupAction(org.hibernate.engine.SessionImplementor session, org.hibernate.persister.entity.Queryable[] affectedQueryables)


	     
		this.session = session;
		// TODO : probably better to calculate these and pass them in, as it'll be more performant
		ArrayList tmpSpaces = new ArrayList();
		for ( int i = 0; i < affectedQueryables.length; i++ ) {
			if ( affectedQueryables[i].hasCache() ) {
				affectedEntityNames.add( affectedQueryables[i].getEntityName() );
			}
			Set roles = session.getFactory().getCollectionRolesByEntityParticipant( affectedQueryables[i].getEntityName() );
			if ( roles != null ) {
				affectedCollectionRoles.addAll( roles );
			}
			for ( int y = 0; y < affectedQueryables[i].getQuerySpaces().length; y++ ) {
				tmpSpaces.add( affectedQueryables[i].getQuerySpaces()[y] );
			}
		}
		this.spaces = new Serializable[ tmpSpaces.size() ];
		for ( int i = 0; i < tmpSpaces.size(); i++ ) {
			this.spaces[i] = ( Serializable ) tmpSpaces.get( i );
		}
	
public BulkOperationCleanupAction(org.hibernate.engine.SessionImplementor session, Set querySpaces)
Create an action that will evict collection and entity regions based on queryspaces (table names). TODO: cache the autodetected information and pass it in instead.

		this.session = session;

		Set tmpSpaces = new HashSet(querySpaces);
		SessionFactoryImplementor factory = session.getFactory();
		Iterator iterator = factory.getAllClassMetadata().entrySet().iterator();
		while ( iterator.hasNext() ) {
			Map.Entry entry = (Map.Entry) iterator.next();
			String entityName = (String) entry.getKey();
			EntityPersister persister = factory.getEntityPersister( entityName );
			Serializable[] entitySpaces = persister.getQuerySpaces();

			if (affectedEntity( querySpaces, entitySpaces )) {
				if ( persister.hasCache() ) {
					affectedEntityNames.add( persister.getEntityName() );
				}
				Set roles = session.getFactory().getCollectionRolesByEntityParticipant( persister.getEntityName() );
				if ( roles != null ) {
					affectedCollectionRoles.addAll( roles );
				}
				for ( int y = 0; y < entitySpaces.length; y++ ) {
					tmpSpaces.add( entitySpaces[y] );
				}
			}

		}
		this.spaces = (Serializable[]) tmpSpaces.toArray( new Serializable[tmpSpaces.size()] );		
	
Methods Summary
private booleanaffectedEntity(java.util.Set querySpaces, java.io.Serializable[] entitySpaces)
returns true if no queryspaces or if there are a match

		if(querySpaces==null || querySpaces.isEmpty()) {
			return true;
		}
		
		for ( int i = 0; i < entitySpaces.length; i++ ) {
			if ( querySpaces.contains( entitySpaces[i] ) ) {
				return true;
			}
		}
		return false;
	
public voidafterTransactionCompletion(boolean success)

		///////////////////////////////////////////////////////////////////////
		// HACK ALERT!!!!!
		if ( session.getFactory().getSettings().getCacheProvider() instanceof org.hibernate.cache.OptimisticTreeCacheProvider
				|| session.getFactory().getSettings().getCacheProvider() instanceof org.hibernate.cache.TreeCacheProvider ) {
			return;
		}
		///////////////////////////////////////////////////////////////////////
		evictEntityRegions();
		evictCollectionRegions();
	
public voidbeforeExecutions()

		// nothing to do
	
private voidevictCollectionRegions()

		if ( affectedCollectionRoles != null ) {
			Iterator itr = affectedCollectionRoles.iterator();
			while ( itr.hasNext() ) {
				final String roleName = ( String ) itr.next();
				session.getFactory().evictCollection( roleName );
			}
		}
	
private voidevictEntityRegions()

		if ( affectedEntityNames != null ) {
			Iterator itr = affectedEntityNames.iterator();
			while ( itr.hasNext() ) {
				final String entityName = ( String ) itr.next();
				session.getFactory().evictEntity( entityName );
			}
		}
	
public voidexecute()

		// nothing to do		
	
public java.io.Serializable[]getPropertySpaces()

		return spaces;
	
public booleanhasAfterTransactionCompletion()

		return true;
	
public voidinit()

		evictEntityRegions();
		evictCollectionRegions();