RepositoryIndexes indexDefns,
NodeTypes nodeTypes,
PlanHints hints,
Map<String, Object> variables ) {
final QueryEngine queryEngine = queryEngine();
final QueryContext queryContext = queryEngine.createQueryContext(context, repositoryCache, workspaceNames,
overriddenNodeCachesByWorkspaceName, schemata,
indexDefns, nodeTypes, new BufferManager(context),
hints, variables);
final org.modeshape.jcr.query.model.QueryCommand command = (org.modeshape.jcr.query.model.QueryCommand)query;
return new CancellableQuery() {
private final Lock lock = new ReentrantLock();
private QueryResults results;
@Override
public QueryResults execute() throws QueryCancelledException, RepositoryException {
try {
lock.lock();
if (results == null) {
// this will block and will hold the lock until it is done ...
results = queryEngine.execute(queryContext, command);
}
return results;
} finally {
lock.unlock();
}
}
@Override
public boolean cancel() {
return queryContext.cancel();
}
};
}