use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestResultSet method test_RS_5.
// JSON
@Test
public void test_RS_5() {
ResultSetRewindable rs1 = new ResultSetMem();
ByteArrayOutputStream arr = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(arr, rs1);
rs1.reset();
ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray());
ResultSet rs2 = ResultSetFactory.fromJSON(ins);
assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestResultSet method test_RS_cmp_2.
@Test
public void test_RS_cmp_2() {
ResultSet rs1 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local"));
ResultSet rs2 = new ResultSetMem();
assertFalse(ResultSetCompare.equalsByTerm(rs1, rs2));
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestResultSet method test_RS_6.
@Test
public void test_RS_6() {
ResultSetRewindable rs1 = make2Rewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local"));
ByteArrayOutputStream arr = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(arr, rs1);
rs1.reset();
ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray());
// Test using the DAWG examples
ResultSet rs2 = ResultSetFactory.fromJSON(ins);
assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class ExTDB4 method main.
public static void main(String... argv) {
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1";
Dataset dataset = TDBFactory.createDataset(directory);
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }";
// See http://incubator.apache.org/jena/documentation/query/app_api.html
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(results);
qexec.close();
dataset.close();
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class ExTDB_Txn1 method execQuery.
public static void execQuery(String sparqlQueryString, Dataset dataset) {
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext(); ) {
QuerySolution soln = results.nextSolution();
int count = soln.getLiteral("count").getInt();
System.out.println("count = " + count);
}
} finally {
qexec.close();
}
}
Aggregations