Search in sources :

Example 26 with UpdateRequest

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

the class TestService method update_service_context_application_01.

@Test
public void update_service_context_application_01() {
    // This test requires no service context to be set
    @SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap != null) {
        serviceContextMap.remove(SERVICE);
    }
    UpdateRequest updates = UpdateFactory.create("CREATE GRAPH <http://example>");
    UpdateProcessRemoteBase engine = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, SERVICE);
    Assert.assertNotNull(engine);
    // Check that no settings were changed
    Assert.assertNull(engine.getClient());
}
Also used : Context(org.apache.jena.sparql.util.Context) UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 27 with UpdateRequest

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

the class update method execOne.

private void execOne(String requestString, DatasetGraph store) {
    UpdateRequest req = UpdateFactory.create(requestString, updateSyntax);
    UpdateExecutionFactory.create(req, store).execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 28 with UpdateRequest

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

the class update method execOneFile.

private void execOneFile(String filename, DatasetGraph store) {
    UpdateRequest req = UpdateFactory.read(filename, updateSyntax);
    UpdateExecutionFactory.create(req, store).execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 29 with UpdateRequest

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

the class rupdate method exec.

@Override
protected void exec() {
    if (modRemote.getServiceURL() == null) {
        throw new CmdException("No endpoint given");
    }
    String endpoint = modRemote.getServiceURL();
    for (String filename : requestFiles) {
        UpdateRequest req = UpdateFactory.read(filename);
        exec(endpoint, req);
    }
    for (String requestString : super.getPositional()) {
        requestString = indirect(requestString);
        UpdateRequest req = UpdateFactory.create(requestString);
        exec(endpoint, req);
    }
}
Also used : CmdException(jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 30 with UpdateRequest

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

the class UpdateBuilderExampleTests method example4.

/**
	 * Example 4:
	 * 
	 * @see https://www.w3.org/TR/sparql11-update/#example_4
	 */
@Test
public void example4() {
    Resource r = ResourceFactory.createResource("http://example/book1");
    Node graphName = NodeFactory.createURI("http://example/bookStore");
    Dataset ds = DatasetFactory.create();
    ds.addNamedModel(graphName.getURI(), m);
    m.setNsPrefix("dc", DC_11.NS);
    m.add(r, DC_11.title, "Fundamentals of Compiler Desing");
    SelectBuilder sb = new SelectBuilder().addWhere(r, DC_11.title, "Fundamentals of Compiler Desing");
    sb = new SelectBuilder().addPrefix("dc", DC_11.NS).addGraph(graphName, sb);
    UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addDelete(sb);
    UpdateRequest req = builder.buildRequest();
    sb = new SelectBuilder().addWhere(r, DC_11.title, "Fundamentals of Compiler Design");
    sb = new SelectBuilder().addPrefix("dc", DC_11.NS).addGraph(graphName, sb);
    builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addInsert(sb);
    builder.appendTo(req);
    UpdateAction.execute(req, ds);
    Model m2 = ds.getNamedModel(graphName.getURI());
    assertTrue(m2.contains(r, DC_11.title, "Fundamentals of Compiler Design"));
    assertEquals(1, m2.listStatements().toSet().size());
// assertEquals( 1, m2.getNsPrefixMap().size());
// assertEquals( DC.NS, m2.getNsPrefixMap().get("dc"));
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Dataset(org.apache.jena.query.Dataset) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) 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