mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fixed ALF-4676: WorkProviderIterator over BatchProcessWorkProvider does not fetch all results
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22297 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -336,9 +336,8 @@ public class AuthorityMigrationPatch extends AbstractPatch
|
|||||||
return authNodeRef;
|
return authNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* (non-Javadoc)
|
* TODO: The walking of the group associations should be wrapped up in a BatchProcessWorkProvider, if possible
|
||||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String applyInternal() throws Exception
|
protected String applyInternal() throws Exception
|
||||||
|
@@ -24,6 +24,7 @@ import java.io.Writer;
|
|||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -141,14 +142,24 @@ public class BatchProcessor<T> implements BatchMonitor
|
|||||||
retryingTransactionHelper,
|
retryingTransactionHelper,
|
||||||
new BatchProcessWorkProvider<T>()
|
new BatchProcessWorkProvider<T>()
|
||||||
{
|
{
|
||||||
|
boolean hasMore = true;
|
||||||
public int getTotalEstimatedWorkSize()
|
public int getTotalEstimatedWorkSize()
|
||||||
{
|
{
|
||||||
return collection.size();
|
return collection.size();
|
||||||
}
|
}
|
||||||
public Collection<T> getNextWork()
|
public Collection<T> getNextWork()
|
||||||
{
|
{
|
||||||
|
// Only return the collection once
|
||||||
|
if (hasMore)
|
||||||
|
{
|
||||||
|
hasMore = false;
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
workerThreads, batchSize,
|
workerThreads, batchSize,
|
||||||
applicationEventPublisher, logger, loggingInterval);
|
applicationEventPublisher, logger, loggingInterval);
|
||||||
@@ -541,27 +552,44 @@ public class BatchProcessor<T> implements BatchMonitor
|
|||||||
|
|
||||||
public boolean hasNext()
|
public boolean hasNext()
|
||||||
{
|
{
|
||||||
if (currentIterator == null)
|
boolean hasNext = false;
|
||||||
|
if (workProvider == null)
|
||||||
{
|
{
|
||||||
if (workProvider != null)
|
// The workProvider was exhausted
|
||||||
|
hasNext = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentIterator != null)
|
||||||
|
{
|
||||||
|
// See if there there is any more on this specific iterator
|
||||||
|
hasNext = currentIterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't have a next (remember that the workProvider is still available)
|
||||||
|
// go and get more results
|
||||||
|
if (!hasNext)
|
||||||
{
|
{
|
||||||
Collection<T> nextWork = workProvider.getNextWork();
|
Collection<T> nextWork = workProvider.getNextWork();
|
||||||
if (nextWork == null)
|
if (nextWork == null)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("BatchProcessWorkProvider returned 'null' work: " + workProvider);
|
throw new RuntimeException("BatchProcessWorkProvider returned 'null' work: " + workProvider);
|
||||||
}
|
}
|
||||||
currentIterator = nextWork.iterator();
|
// Check that there are some results at all
|
||||||
|
if (nextWork.size() == 0)
|
||||||
|
{
|
||||||
|
// An empty collection indicates that there are no more results
|
||||||
|
workProvider = null;
|
||||||
|
currentIterator = null;
|
||||||
|
hasNext = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The null workProvider indicates that it was exhausted
|
// There were some results, so get a new iterator
|
||||||
|
currentIterator = nextWork.iterator();
|
||||||
|
hasNext = currentIterator.hasNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean hasNext = (currentIterator == null) ? false : currentIterator.hasNext();
|
|
||||||
if (!hasNext)
|
|
||||||
{
|
|
||||||
workProvider = null; // No more work to get
|
|
||||||
currentIterator = null;
|
|
||||||
}
|
}
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user