Search in sources :

Example 11 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class AbstractJenaConnectionTests method connection_pre_processors_08.

/**
     * Tests pre-processor management operations
     * 
     * @throws SQLException
     */
@Test
public void connection_pre_processors_08() throws SQLException {
    JenaConnection conn = this.getConnection();
    Assert.assertFalse(conn.getPreProcessors().hasNext());
    // Add a pre-processor
    Echo echo = new Echo();
    conn.addPreProcessor(echo);
    Assert.assertTrue(conn.getPreProcessors().hasNext());
    // Apply the pre-processor
    UpdateRequest input = UpdateFactory.create("DELETE WHERE { ?s ?p ?o }");
    UpdateRequest output = conn.applyPreProcessors(input);
    Assert.assertEquals(input, output);
    conn.close();
}
Also used : ResultsEcho(org.apache.jena.jdbc.postprocessing.ResultsEcho) Echo(org.apache.jena.jdbc.preprocessing.Echo) UpdateRequest(org.apache.jena.update.UpdateRequest) Test(org.junit.Test)

Example 12 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestSyntaxTransform method testUpdate.

private void testUpdate(String input, String output, String varStr, String valStr) {
    UpdateRequest req1 = UpdateFactory.create(PREFIX + input);
    UpdateRequest reqExpected = UpdateFactory.create(PREFIX + output);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(varStr), SSE.parseNode(valStr));
    UpdateRequest reqTrans = UpdateTransformOps.transform(req1, map);
    // Crude.
    String x1 = reqExpected.toString().replaceAll("[ \n\t]", "");
    String x2 = reqTrans.toString().replaceAll("[ \n\t]", "");
    //assertEquals(reqExpected, reqTrans) ;
    assertEquals(x1, x2);
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 13 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestEmbeddedFuseki method embedded_04.

@Test
public void embedded_04() {
    DatasetGraph dsg = dataset();
    Txn.executeWrite(dsg, () -> {
        Quad q = SSE.parseQuad("(_ :s :p _:b)");
        dsg.add(q);
    });
    // A service with just being able to do quads operations
    // That is, GET, POST, PUT on  "/data" in N-quads and TriG. 
    DataService dataService = new DataService(dsg);
    dataService.addEndpoint(OperationName.Quads_RW, "");
    dataService.addEndpoint(OperationName.Query, "");
    dataService.addEndpoint(OperationName.Update, "");
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
    server.start();
    try {
        // Put data in.
        String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
        Graph g = SSE.parseGraph(data);
        HttpEntity e = graphToHttpEntity(g);
        HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
        // Get data out.
        try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
            Graph g2 = GraphFactory.createDefaultGraph();
            RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
            assertTrue(g.isIsomorphicWith(g2));
        }
        // Query.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(3, x);
        });
        // Update
        UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
        UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
        // Query again.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(0, x);
        });
    } finally {
        server.stop();
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) HttpEntity(org.apache.http.HttpEntity) UpdateRequest(org.apache.jena.update.UpdateRequest) ResultSet(org.apache.jena.query.ResultSet) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Example 14 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestSPARQLProtocol method update_02.

@Test
public void update_02() {
    UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
    UpdateProcessor proc = UpdateExecutionFactory.createRemoteForm(update, serviceUpdate());
    proc.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessor(org.apache.jena.update.UpdateProcessor) Test(org.junit.Test)

Example 15 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestSPARQLProtocol method update_01.

@Test
public void update_01() {
    UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
    UpdateProcessor proc = UpdateExecutionFactory.createRemote(update, serviceUpdate());
    proc.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessor(org.apache.jena.update.UpdateProcessor) Test(org.junit.Test)

Aggregations

UpdateRequest (org.apache.jena.update.UpdateRequest)71 Test (org.junit.Test)46 UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 UpdateProcessor (org.apache.jena.update.UpdateProcessor)7 Node (org.apache.jena.graph.Node)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 HashMap (java.util.HashMap)4 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)4 Resource (org.apache.jena.rdf.model.Resource)4 AuthScope (org.apache.http.auth.AuthScope)3 Dataset (org.apache.jena.query.Dataset)3 QueryParseException (org.apache.jena.query.QueryParseException)3 Model (org.apache.jena.rdf.model.Model)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 Map (java.util.Map)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 CmdException (jena.cmd.CmdException)2 HttpClient (org.apache.http.client.HttpClient)2