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 org.openrdf.query.Dataset;
09: import org.openrdf.query.impl.AbstractQuery;
10: import org.openrdf.query.parser.ParsedQuery;
11:
12: /**
13: * @author Arjohn Kampman
14: */
15: public abstract class SailQuery extends AbstractQuery {
16:
17: private final ParsedQuery parsedQuery;
18:
19: private final SailRepositoryConnection con;
20:
21: protected SailQuery(ParsedQuery parsedQuery,
22: SailRepositoryConnection con) {
23: this .parsedQuery = parsedQuery;
24: this .con = con;
25: }
26:
27: public ParsedQuery getParsedQuery() {
28: return parsedQuery;
29: }
30:
31: protected SailRepositoryConnection getConnection() {
32: return con;
33: }
34:
35: /**
36: * Gets the "active" dataset for this query. The active dataset is either the
37: * dataset that has been specified using {@link #setDataset(Dataset)} or the
38: * dataset that has been specified in the query, where the former takes
39: * precedence over the latter.
40: *
41: * @return The active dataset, or <tt>null</tt> if there is no dataset.
42: */
43: public Dataset getActiveDataset() {
44: if (dataset != null) {
45: return dataset;
46: }
47:
48: // No external dataset specified, use query's own dataset (if any)
49: return parsedQuery.getDataset();
50: }
51:
52: @Override
53: public String toString() {
54: return parsedQuery.toString();
55: }
56: }
|