}
private void applyUpdates(List<LuceneWork> workList, IndexingMonitor monitor, boolean streaming) throws InterruptedException, ExecutionException {
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
ErrorContextBuilder errorContextBuilder = new ErrorContextBuilder();
errorContextBuilder.allWorkToBeDone(workList);
IndexWriter indexWriter = workspace.getIndexWriter(errorContextBuilder);
if (indexWriter == null) {
LOG.log(Level.SEVERE, "Cannot open index writer");
return;
}
boolean someFailureHappened = false;
try {
List<LuceneWork> failedWorkds = new ArrayList<LuceneWork>();
int queueSize = workList.size();
LOG.info("Performing " + queueSize + " lucene works");
for (int i = 0; i < queueSize; i++) {
LuceneWork work = workList.get(i);
try {
long time = 0;
if (LOG.isLoggable(Level.INFO)) {
String entity = work.getEntityClass().toString();
LOG.info("Performing lucene work for " + entity);
time = System.currentTimeMillis();
}
Transaction transaction = datastoreService.beginTransaction();
try {
work.getWorkDelegate(getVisitor()).performWork(work, indexWriter, monitor);
transaction.commit();
} finally {
if (transaction.isActive())
transaction.rollback();
}
if (LOG.isLoggable(Level.INFO)) {
String entity = work.getEntityClass().toString();
LOG.info("Performed lucene work for " + entity + " in " + (System.currentTimeMillis() - time) + " ms");
}
} catch (Exception e) {
someFailureHappened = true;
errorContextBuilder.errorThatOccurred(e.getCause());
failedWorkds.add(work);
}
}
if (someFailureHappened) {
errorContextBuilder.addAllWorkThatFailed(failedWorkds);
getErrorHandler().handle(errorContextBuilder.createErrorContext());
} else {
if (!streaming) {
workspace.optimizerPhase();
}
}