* org.jboss.dna.graph.request.Request)
*/
public void execute( ExecutionContext context,
Request request ) throws RepositorySourceException {
Logger logger = context.getLogger(getClass());
Stopwatch sw = null;
if (logger.isTraceEnabled()) {
sw = new Stopwatch();
sw.start();
}
// Do any commands update/write?
RepositoryContext repositoryContext = this.source.getRepositoryContext();
Observer observer = repositoryContext != null ? repositoryContext.getObserver() : null;
RequestProcessor processor = new MapRequestProcessor(context, this.repository, observer, source.areUpdatesAllowed());
boolean commit = true;
MapRepositoryTransaction txn = repository.startTransaction(request.isReadOnly());
try {
// Obtain the lock and execute the commands ...
processor.process(request);
if (request.hasError() && !request.isReadOnly()) {
// The changes failed, so we need to rollback so we have 'all-or-nothing' behavior
commit = false;
}
} catch (Throwable error) {
commit = false;
} finally {
try {
processor.close();
} finally {
// Now commit or rollback ...
try {
if (commit) {
txn.commit();
} else {
// Need to rollback the changes made to the repository ...
txn.rollback();
}
} catch (Throwable commitOrRollbackError) {
if (commit && !request.hasError() && !request.isFrozen()) {
// Record the error on the request ...
request.setError(commitOrRollbackError);
}
commit = false; // couldn't do it
}
if (commit) {
// Now that we've closed our transaction, we can notify the observer of the committed changes ...
processor.notifyObserverOfChanges();
}
}
}
if (logger.isTraceEnabled()) {
assert sw != null;
sw.stop();
logger.trace("MapRepositoryConnection.execute(...) took " + sw.getTotalDuration());
}
}