private static void doJsonQuery(Prologue prologue, QueryExecution queryExecution, ResultsFormat outputFormat) { JsonArray results = queryExecution.execJson(); JSON.write(System.out, results); }
@Override public JsonArray execJson() { beforeExec(); try { return decoratee.execJson(); } catch(Exception e) { onException(e); // throw new RuntimeException(e); throw e; } finally { afterExec(); } }
private void test(String queryString, String jsonExpected) { Query query = QueryFactory.create(queryString, Syntax.syntaxARQ); DatasetGraph dsg = new DatasetGraphZero(); Dataset ds = DatasetFactory.wrap(dsg); try ( QueryExecution qExec = QueryExecutionFactory.create(query, ds) ) { JsonValue jvGot = qExec.execJson() ; JsonValue jvExpected = JSON.parseAny(jsonExpected) ; assertEquals(jvExpected, jvGot); } } }
System.err.println(str); } else if(q.isJsonType()) { String json = qe.execJson().toString(); System.out.println(json); } else {
/** * Test that a JSON query returns an array with the correct size, given a pre-populated model. */ @Test public void testExecJson() { // JENA-632 Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } " + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ); try ( QueryExecution qexec = QueryExecutionFactory.create(query, m) ) { JsonArray jsonArray = qexec.execJson(); assertNotNull( jsonArray ); assertEquals(3, jsonArray.size()); } }