Search in sources :

Example 46 with UpdateRequest

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

the class sdbupdate method execOneFile.

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

Example 47 with UpdateRequest

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

the class TestParameterizedSparqlString method test_param_string_injection_02.

@Test(expected = ARQException.class)
public void test_param_string_injection_02() {
    // This injection is prevented by forbidding the > character in URIs
    String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> ?var2 . }";
    ParameterizedSparqlString pss = new ParameterizedSparqlString(str);
    pss.setIri("var2", "hello> } ; DROP ALL ; INSERT DATA { <s> <p> <goodbye");
    UpdateRequest updates = pss.asUpdate();
    Assert.fail("Attempt to do SPARQL injection should result in an exception");
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Test(org.junit.Test)

Example 48 with UpdateRequest

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

the class TestParameterizedSparqlString method test_param_string_positional_injection_09.

@Test
public void test_param_string_positional_injection_09() {
    // This injection attempt using comments results in a valid SPARQL
    // update but a failed injection because the attempt to use comments
    // ends up being a valid string literal within quotes
    String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> ? }";
    ParameterizedSparqlString pss = new ParameterizedSparqlString(str);
    pss.setLiteral(0, "\" . } ; DROP ALL ; INSERT DATA { <s> <p> <o> }#");
    UpdateRequest updates = pss.asUpdate();
    Assert.assertEquals(1, updates.getOperations().size());
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Test(org.junit.Test)

Example 49 with UpdateRequest

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

the class UpdateBuilderExampleTests method example6.

/**
	 * Example 6:
	 * 
	 * @see https://www.w3.org/TR/sparql11-update/#example_6
	 */
@Test
public void example6() {
    Resource book1 = ResourceFactory.createResource("http://example/book1");
    Resource book2 = ResourceFactory.createResource("http://example/book2");
    Resource book3 = ResourceFactory.createResource("http://example/book3");
    Literal d1977 = ResourceFactory.createTypedLiteral("1977-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
    Literal d1970 = ResourceFactory.createTypedLiteral("1970-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
    Literal d1948 = ResourceFactory.createTypedLiteral("1948-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
    Property price = ResourceFactory.createProperty(NS_prefix + "price");
    Literal priceV = ResourceFactory.createPlainLiteral("42");
    m.setNsPrefix("dc", DC_11.NS);
    m.setNsPrefix("ns", NS_prefix);
    m.add(book1, DC_11.title, "Principles of Compiler Design");
    m.add(book1, DC_11.date, d1977);
    m.add(book2, price, priceV);
    m.add(book2, DC_11.title, "David Copperfield");
    m.add(book2, DC_11.creator, "Edmund Wells");
    m.add(book2, DC_11.date, d1948);
    m.add(book3, DC_11.title, "SPARQL 1.1 Tutorial");
    UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addPrefix("xsd", "http://www.w3.org/2001/XMLSchema#").addDelete("?book", "?p", "?v").addWhere("?book", "dc:date", "?date");
    ExprFactory exprFact = builder.getExprFactory();
    builder.addFilter(exprFact.gt(exprFact.asExpr("?date"), d1970)).addWhere("?book", "?p", "?v");
    UpdateRequest req = builder.buildRequest();
    UpdateAction.execute(req, m);
    assertTrue(m.contains(book2, price, priceV));
    assertTrue(m.contains(book2, DC_11.title, "David Copperfield"));
    assertTrue(m.contains(book2, DC_11.creator, "Edmund Wells"));
    assertTrue(m.contains(book2, DC_11.date, d1948));
    assertTrue(m.contains(book3, DC_11.title, "SPARQL 1.1 Tutorial"));
    assertEquals(5, triples.size());
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 50 with UpdateRequest

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

the class UpdateBuilderExampleTests method example5.

/**
	 * Example 5:
	 * 
	 * @see https://www.w3.org/TR/sparql11-update/#example_5
	 */
@Test
public void example5() {
    Resource p25 = ResourceFactory.createResource("http://example/president25");
    Resource p27 = ResourceFactory.createResource("http://example/president27");
    Resource p42 = ResourceFactory.createResource("http://example/president42");
    m.setNsPrefix("foaf", FOAF.NS);
    m.add(p25, FOAF.givenname, "Bill");
    m.add(p25, FOAF.family_name, "McKinley");
    m.add(p27, FOAF.givenname, "Bill");
    m.add(p27, FOAF.family_name, "Taft");
    m.add(p42, FOAF.givenname, "Bill");
    m.add(p42, FOAF.family_name, "Clinton");
    Node graphName = NodeFactory.createURI("http://example/addresses");
    Dataset ds = DatasetFactory.create();
    ds.addNamedModel(graphName.getURI(), m);
    UpdateBuilder builder = new UpdateBuilder().addPrefix("foaf", FOAF.NS).with(graphName).addDelete("?person", FOAF.givenname, "Bill").addInsert("?person", FOAF.givenname, "William").addWhere("?person", FOAF.givenname, "Bill");
    UpdateRequest req = builder.buildRequest();
    UpdateAction.execute(req, ds);
    Model m2 = ds.getNamedModel(graphName.getURI());
    List<RDFNode> nodes = m2.listObjectsOfProperty(FOAF.givenname).toList();
    assertEquals(1, nodes.size());
    assertEquals("William", nodes.get(0).asLiteral().toString());
    List<Resource> subjects = m2.listSubjectsWithProperty(FOAF.givenname).toList();
    assertEquals(3, subjects.size());
}
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) RDFNode(org.apache.jena.rdf.model.RDFNode) 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