diff --git a/src/com/franz/agraph/jena/AGQueryExecution.java b/src/com/franz/agraph/jena/AGQueryExecution.java index 00d12721..e0590fc0 100644 --- a/src/com/franz/agraph/jena/AGQueryExecution.java +++ b/src/com/franz/agraph/jena/AGQueryExecution.java @@ -13,6 +13,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.util.Context; import com.hp.hpl.jena.util.FileManager; @@ -35,8 +36,6 @@ public void abort() { @Override public void close() { - // TODO Auto-generated method stub - } @Override @@ -44,6 +43,7 @@ public boolean execAsk() { AGBooleanQuery bq = model.getGraph().getConnection().prepareBooleanQuery(AGQueryLanguage.SPARQL, query.getQueryString()); boolean result; try { + bq.setDataset(model.getGraph().getDataset()); result = bq.evaluate(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); @@ -52,35 +52,42 @@ public boolean execAsk() { } @Override - public AGModel execConstruct() { + public Model execConstruct() { + return execConstruct(null); + } + + @Override + public Model execConstruct(Model m) { AGGraphQuery gq = model.getGraph().getConnection().prepareGraphQuery(AGQueryLanguage.SPARQL, query.getQueryString()); GraphQueryResult result; try { + gq.setDataset(model.getGraph().getDataset()); result = gq.evaluate(); - // TODO: - result.close(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } - return null; // TODO: new AGModel(result, model); - } - - @Override - public Model execConstruct(Model model) { - // TODO Auto-generated method stub - return null; + if (m==null) { + m = ModelFactory.createDefaultModel(); + } + try { + m.setNsPrefixes(result.getNamespaces()); + while (result.hasNext()) { + m.add(model.asStatement(AGNodeFactory.asTriple(result.next()))); + } + } catch (QueryEvaluationException e) { + throw new RuntimeException(e); + } + return m; } @Override public Model execDescribe() { - // TODO Auto-generated method stub - return null; + return execDescribe(null); } @Override - public Model execDescribe(Model model) { - // TODO Auto-generated method stub - return null; + public Model execDescribe(Model m) { + return execConstruct(m); } @Override diff --git a/src/tutorial/JenaTutorialExamples.java b/src/tutorial/JenaTutorialExamples.java index 21d798e1..6ab684ab 100644 --- a/src/tutorial/JenaTutorialExamples.java +++ b/src/tutorial/JenaTutorialExamples.java @@ -409,7 +409,7 @@ public static void example7() throws Exception { public static void example8() throws Exception { AGGraphMaker maker = example6(); AGModel model = new AGModel(maker.getGraph()); - AGModel model_vcards = new AGModel(maker.openGraph("http://example.org#vcards")); + // TODO AGModel model_vcards = new AGModel(maker.openGraph("http://example.org#vcards")); String outputFile = TEMPORARY_DIRECTORY + "temp.nt"; // outputFile = null; if (outputFile == null) { @@ -429,7 +429,7 @@ public static void example8() throws Exception { } output = (outputFile2 != null) ? new FileOutputStream(outputFile2) : System.out; - model_vcards.write(output); + // TODO model_vcards.write(output); } /** @@ -495,7 +495,6 @@ public static void example13() throws Exception { } finally { qe.close(); } - /*TODO: queryString = "construct {?s ?p ?o} where { ?s ?p ?o . filter (?o = \"Alice\") } "; query = AGQueryFactory.create(queryString); qe = AGQueryExecutionFactory.create(query, model); @@ -515,7 +514,7 @@ public static void example13() throws Exception { m.write(System.out); } finally { qe.close(); - }*/ + } } /**