Created
July 30, 2011 19:46
-
-
Save kendall/1115915 to your computer and use it in GitHub Desktop.
Spring for Stardog fragments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> results = snarlTemplate.doWithGetter(null, "urn:test:n", new GetterCallback<String>() { | |
@Override | |
public String processStatement(Statement statement) { | |
return statement.getObject().stringValue(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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