* @throws Exception If the Dn is not valid or if the deletion failed
*/
private void deleteRecursive( Dn rootDn, Map<Dn, EntryFilteringCursor> cursorMap ) throws Exception
{
LOG.debug( "searching for {}", rootDn.getName() );
EntryFilteringCursor cursor = null;
try
{
if ( cursorMap == null )
{
cursorMap = new HashMap<Dn, EntryFilteringCursor>();
}
cursor = cursorMap.get( rootDn );
if ( cursor == null )
{
cursor = session.search( rootDn, SearchScope.ONELEVEL, ENTRY_UUID_PRESENCE_FILTER,
AliasDerefMode.NEVER_DEREF_ALIASES, SchemaConstants.ENTRY_UUID_AT );
cursor.beforeFirst();
LOG.debug( "putting cursor for {}", rootDn.getName() );
cursorMap.put( rootDn, cursor );
}
if ( !cursor.next() ) // if this is a leaf entry's Dn
{
LOG.debug( "deleting {}", rootDn.getName() );
cursorMap.remove( rootDn );
cursor.close();
session.delete( rootDn );
}
else
{
do
{
Entry entry = cursor.get();
deleteRecursive( entry.getDn(), cursorMap );
}
while ( cursor.next() );
cursorMap.remove( rootDn );
cursor.close();
LOG.debug( "deleting {}", rootDn.getName() );
session.delete( rootDn );
}
}
catch ( Exception e )