use of org.apache.jena.graph.impl.CollectionGraph in project jena by apache.
the class SecuredModelImpl method add.
@Override
public SecuredModel add(final StmtIterator iter) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException {
checkUpdate();
if (!canCreate(Triple.ANY)) {
final List<Triple> lst = new ArrayList<>();
try {
while (iter.hasNext()) {
final Statement s = iter.next();
checkCreate(s);
lst.add(s.asTriple());
}
final Model m = ModelFactory.createModelForGraph(new CollectionGraph(lst));
holder.getBaseItem().add(m.listStatements());
} finally {
iter.close();
}
} else {
holder.getBaseItem().add(iter);
}
return holder.getSecuredItem();
}
use of org.apache.jena.graph.impl.CollectionGraph in project jena by apache.
the class UpdateBuilderTest method example1.
// testsbased on the examples
/*
* Example 1: Adding some triples to a graph
This snippet describes two RDF triples to be inserted into the default graph of the Graph Store.
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
<http://example/book1> dc:title "A new book" ;
dc:creator "A.N.Other" .
}
Data before:
# Default graph
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ns: <http://example.org/ns#> .
<http://example/book1> ns:price 42 .
Data after:
# Default graph
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ns: <http://example.org/ns#> .
<http://example/book1> ns:price 42 .
<http://example/book1> dc:title "A new book" .
<http://example/book1> dc:creator "A.N.Other" .
*/
@Test
public void example1() {
Node n = NodeFactory.createURI("http://example/book1");
Node priceN = NodeFactory.createURI("http://example.org/ns#price");
Node priceV = NodeFactory.createLiteral("42");
UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addInsert(n, DC_11.title, "A new book").addInsert(n, DC_11.creator, "A.N.Other");
List<Triple> triples = new ArrayList<Triple>();
triples.add(new Triple(n, priceN, priceV));
Graph g = new CollectionGraph(triples);
Model m = ModelFactory.createModelForGraph(g);
m.setNsPrefix("dc", DC_11.NS);
m.setNsPrefix("ns", "http://example.org/ns#");
UpdateAction.execute(builder.build(), m);
Resource r = ResourceFactory.createResource(n.getURI());
Property rPriceP = ResourceFactory.createProperty(priceN.getURI());
Literal rPriceV = ResourceFactory.createPlainLiteral("42");
assertTrue(m.contains(r, rPriceP, rPriceV));
assertTrue(m.contains(r, DC_11.title, "A new book"));
assertTrue(m.contains(r, DC_11.creator, "A.N.Other"));
assertEquals(3, triples.size());
}
use of org.apache.jena.graph.impl.CollectionGraph in project jena by apache.
the class SecuredModelImpl method remove.
@Override
public SecuredModel remove(final StmtIterator iter) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
if (!canDelete(Triple.ANY)) {
final List<Triple> lst = new ArrayList<>();
try {
while (iter.hasNext()) {
final Statement s = iter.next();
checkDelete(s);
lst.add(s.asTriple());
}
final Model m = ModelFactory.createModelForGraph(new CollectionGraph(lst));
holder.getBaseItem().remove(m.listStatements());
} finally {
iter.close();
}
} else {
holder.getBaseItem().remove(iter);
}
return holder.getSecuredItem();
}
Aggregations