01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.repository.sail;
07:
08: import info.aduna.iteration.CloseableIteration;
09:
10: import org.openrdf.query.BindingSet;
11: import org.openrdf.query.BooleanQuery;
12: import org.openrdf.query.Dataset;
13: import org.openrdf.query.QueryEvaluationException;
14: import org.openrdf.query.algebra.TupleExpr;
15: import org.openrdf.query.parser.ParsedBooleanQuery;
16: import org.openrdf.sail.SailConnection;
17: import org.openrdf.sail.SailException;
18:
19: /**
20: * @author Arjohn Kampman
21: */
22: public class SailBooleanQuery extends SailQuery implements BooleanQuery {
23:
24: protected SailBooleanQuery(ParsedBooleanQuery tupleQuery,
25: SailRepositoryConnection sailConnection) {
26: super (tupleQuery, sailConnection);
27: }
28:
29: @Override
30: public ParsedBooleanQuery getParsedQuery() {
31: return (ParsedBooleanQuery) super .getParsedQuery();
32: }
33:
34: public boolean evaluate() throws QueryEvaluationException {
35: ParsedBooleanQuery parsedBooleanQuery = getParsedQuery();
36: TupleExpr tupleExpr = parsedBooleanQuery.getTupleExpr();
37: Dataset dataset = getDataset();
38: if (dataset == null) {
39: // No external dataset specified, use query's own dataset (if any)
40: dataset = parsedBooleanQuery.getDataset();
41: }
42:
43: try {
44: SailConnection sailCon = getConnection()
45: .getSailConnection();
46:
47: CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter = sailCon
48: .evaluate(tupleExpr, dataset, getBindings(),
49: getIncludeInferred());
50:
51: try {
52: return bindingsIter.hasNext();
53: } finally {
54: bindingsIter.close();
55: }
56: } catch (SailException e) {
57: throw new QueryEvaluationException(e.getMessage(), e);
58: }
59: }
60: }
|