01: package org.ontoware.rdf2go.impl.jena24;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import org.ontoware.aifbcommons.collection.ClosableIterator;
07: import org.ontoware.rdf2go.exception.ModelRuntimeException;
08: import org.ontoware.rdf2go.model.QueryResultTable;
09: import org.ontoware.rdf2go.model.QueryRow;
10:
11: import com.hp.hpl.jena.query.Query;
12: import com.hp.hpl.jena.query.QueryExecution;
13: import com.hp.hpl.jena.query.QueryExecutionFactory;
14: import com.hp.hpl.jena.query.ResultSet;
15: import com.hp.hpl.jena.rdf.model.Model;
16:
17: public class QueryResultTableImpl implements QueryResultTable {
18:
19: private List<String> varnames;
20:
21: private QueryExecution qexec;
22:
23: public QueryResultTableImpl(Query query, Model jenaModel)
24: throws ModelRuntimeException {
25:
26: if (!query.isSelectType()) {
27: throw new ModelRuntimeException(
28: "The given query is not a SELECT query");
29: }
30: // else
31: this .varnames = new ArrayList<String>();
32: for (Object o : query.getResultVars()) {
33: varnames.add((String) o);
34: }
35: qexec = QueryExecutionFactory.create(query, jenaModel);
36: }
37:
38: public List<String> getVariables() {
39: return this .varnames;
40: }
41:
42: public ClosableIterator<QueryRow> iterator() {
43: ResultSet results = qexec.execSelect();
44: return new QueryIterator(this, results);
45: }
46:
47: }
|