Search in sources :

Example 1 with RDFConnectionFuseki

use of org.apache.jena.rdfconnection.RDFConnectionFuseki in project jena by apache.

the class TestRDFConnectionFusekiBinary method rdfconnection_fuseki_1.

@Test
public void rdfconnection_fuseki_1() {
    // Tests all run, in order, on one connection.
    Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
    // Goes in as URI! (pre this PR)
    Model model = ModelFactory.createDefaultModel();
    model.getGraph().add(triple);
    int PORT = WebLib.choosePort();
    FusekiServer server = createFusekiServer(PORT).build().start();
    try {
        String dsURL = "http://localhost:" + PORT + "/ds";
        assertTrue(HttpLib.isFuseki(dsURL));
        RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create().destination(dsURL);
        try (RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build()) {
            assertTrue(HttpLib.isFuseki(dsURL));
            // GSP
            conn.put(model);
            checkModel(conn, "b3456");
            // Query forms.
            conn.querySelect("SELECT * {?s ?p ?o}", x -> {
                Node obj = x.get("o").asNode();
                assertTrue(obj.isBlank());
                assertEquals("b3456", obj.getBlankNodeLabel());
            });
            try (QueryExecution qExec = conn.query("ASK {?s ?p <_:b3456>}")) {
                boolean bool = qExec.execAsk();
                assertTrue(bool);
            }
            try (QueryExecution qExec = conn.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            try (QueryExecution qExec = conn.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            // Update
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
            checkModel(conn, "b789");
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
            checkModel(conn, "6789");
        }
    } finally {
        server.stop();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) RDFConnectionFuseki(org.apache.jena.rdfconnection.RDFConnectionFuseki) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 2 with RDFConnectionFuseki

use of org.apache.jena.rdfconnection.RDFConnectionFuseki in project jena by apache.

the class RDFConnectionExample6 method main.

public static void main(String... args) {
    RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create().destination("http://sparql.org/sparql");
    Query query = QueryFactory.create("SELECT * { BIND('Hello'as ?text) }");
    // In this variation, a connection is built each time.
    try (RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build()) {
        conn.queryResultSet(query, ResultSetFormatter::out);
    }
}
Also used : ResultSetFormatter(org.apache.jena.query.ResultSetFormatter) Query(org.apache.jena.query.Query) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) RDFConnectionFuseki(org.apache.jena.rdfconnection.RDFConnectionFuseki)

Aggregations

RDFConnectionFuseki (org.apache.jena.rdfconnection.RDFConnectionFuseki)2 RDFConnectionRemoteBuilder (org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder)2 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 Query (org.apache.jena.query.Query)1 QueryExecution (org.apache.jena.query.QueryExecution)1 ResultSetFormatter (org.apache.jena.query.ResultSetFormatter)1 Model (org.apache.jena.rdf.model.Model)1 Test (org.junit.Test)1