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();
}
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");
}
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());
}
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());
}
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());
}
Aggregations