org.entityfs.util
Class IteratorDeleter

java.lang.Object
  extended by org.entityfs.util.AbstractIteratorUtil
      extended by org.entityfs.util.IteratorDeleter

public class IteratorDeleter
extends AbstractIteratorUtil

Delete the entities returned from an Iterator. If a non-empty directory is returned from the iterator, it is not deleted. If deleting entire entity hierarchies, make sure to use a DepthFirstIterator so that the directories returned from the iterator are empty.

The deleter locks entities and parent entities as needed, but it never holds any locks between two copy operations. (In other words: when it calls next on the iterator, it does not hold any locks.)

An optional ErrorHandlingStrategy can be used to deal with errors. The default strategy when an exception is caught is to abort the delete operation and rethrow the exception.

EntityFS iterators are not thread safe. Don't use them concurrently from several threads without synchronizing access to them.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Entities.deleteRecursively(EntityView), Entities.deleteRecursively(EntityView, boolean)
In_jar:
entityfs-util

Constructor Summary
IteratorDeleter(EntityListable el)
          Create an IteratorDeleter that recursively deletes the contents of the directory view.
IteratorDeleter(EntityListable el, ErrorHandlingStrategy errorStrategy)
          Create an IteratorDeleter that recursively deletes the contents of the directory view.
IteratorDeleter(Iterator<? extends EntityView> itr)
          Delete all entities returned from the iterator and use the default error strategy (see above).
IteratorDeleter(Iterator<? extends EntityView> itr, ErrorHandlingStrategy errorStrategy)
          Delete all entities returned from the iterator and use the supplied error strategy.
 
Method Summary
 void delete()
          Delete all entities returned from the Iterator supplied when creating this object.
 void deleteEntities()
          This method calls delete().
 
Methods inherited from class org.entityfs.util.AbstractIteratorUtil
letErrorStrategyHandle, letErrorStrategyHandle, letErrorStrategyHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorDeleter

public IteratorDeleter(Iterator<? extends EntityView> itr)
Delete all entities returned from the iterator and use the default error strategy (see above).

Parameters:
itr - The iterator that returns entities to delete. Use a DepthFirstIterator if deleting entity hierarchies.

IteratorDeleter

public IteratorDeleter(Iterator<? extends EntityView> itr,
                       ErrorHandlingStrategy errorStrategy)
Delete all entities returned from the iterator and use the supplied error strategy.

Parameters:
itr - The iterator that returns entities to delete. Use a DepthFirstIterator if deleting entity hierarchies.
errorStrategy - The error handling strategy.

IteratorDeleter

public IteratorDeleter(EntityListable el)
Create an IteratorDeleter that recursively deletes the contents of the directory view. The directory itself is not deleted. The default error strategy is used (see above).

Parameters:
el - The entity listable to delete the contents of. If this is a directory view, only the entities that are visible in the view are deleted.

IteratorDeleter

public IteratorDeleter(EntityListable el,
                       ErrorHandlingStrategy errorStrategy)
Create an IteratorDeleter that recursively deletes the contents of the directory view. The directory itself is not deleted. The supplied error strategy is used.

Parameters:
el - The entity listable to delete contents in. If this is a directory view, only the entities that are visible in the view are deleted.
errorStrategy - The error handling strategy.
Method Detail

delete

public void delete()
            throws UncheckedInterruptedException
Delete all entities returned from the Iterator supplied when creating this object.

Throws:
UncheckedInterruptedException - If the delete operation was interrupted.
See Also:
deleteEntities()

deleteEntities

public void deleteEntities()
                    throws UncheckedInterruptedException
This method calls delete(). It can be called by JavaScript scripts that cannot call delete directly (since that is a reserved word in JavaScript).

Throws:
UncheckedInterruptedException - If the delete operation was interrupted.
See Also:
delete()