Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spring for Stardog fragments
String sparql = "CONSTRUCT { ?a <urn:test:new> ?b } WHERE { ?a <urn:test:p> ?b }";
List<Map<String,String>> results = snarlTemplate.construct(sparql, new GraphMapper<Map<String,String>>() {
@Override
public Map<String, String> mapRow(Statement next) {
Map<String,String> map = new HashMap<String,String>();
map.put(next.getSubject().stringValue(), next.getObject().stringValue());
return map;
}
});
snarlTemplate.doWithAdder(new AdderCallback<Boolean>() {
@Override
public Boolean add(Adder adder) throws StardogException {
String uriA = "urn:test:j";
String uriB = "urn:test:k";
String litA = "hello world";
String litB = "goodbye";
adder.statement(new URIImpl(uriA), new URIImpl(uriB), new LiteralImpl(litA));
adder.statement(new URIImpl(uriA), new URIImpl(uriB), new LiteralImpl(litB));
return true;
}
});
List<String> results = snarlTemplate.doWithGetter(null, "urn:test:n", new GetterCallback<String>() {
@Override
public String processStatement(Statement statement) {
return statement.getObject().stringValue();
}
});
snarlTemplate.doWithRemover(new RemoverCallback<Boolean>() {
@Override
public Boolean remove(Remover remover) throws StardogException {
remover.statements(new URIImpl("urn:test:m"), new URIImpl("urn:test:n"), null);
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.