Search in sources :

Example 36 with ResultSet

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 37 with ResultSet

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));
}
Also used : BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 38 with ResultSet

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 39 with ResultSet

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();
}
Also used : Query(org.apache.jena.query.Query) Dataset(org.apache.jena.query.Dataset) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 40 with ResultSet

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();
    }
}
Also used : Query(org.apache.jena.query.Query) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Aggregations

ResultSet (org.apache.jena.query.ResultSet)75 Test (org.junit.Test)43 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)33 BaseTest (org.apache.jena.atlas.junit.BaseTest)27 QueryExecution (org.apache.jena.query.QueryExecution)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 QuerySolution (org.apache.jena.query.QuerySolution)11 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)8 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)8 ArrayList (java.util.ArrayList)7 Node (org.apache.jena.graph.Node)7 Query (org.apache.jena.query.Query)7 Model (org.apache.jena.rdf.model.Model)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Var (org.apache.jena.sparql.core.Var)5 Binding (org.apache.jena.sparql.engine.binding.Binding)4 AbstractRegexpBasedTest (org.apache.jena.arq.AbstractRegexpBasedTest)3