use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameGraph method select.
public List<BoundVariables> select(String sparqlSelect) {
List<BoundVariables> results = new LinkedList<>();
TupleQueryResult tupleQueryResult = getTupleQueryResult(sparqlSelect);
try {
while (tupleQueryResult.hasNext()) {
results.add(new SesameBoundVariables(tupleQueryResult.getBindingNames(), tupleQueryResult.next()));
}
} catch (QueryEvaluationException e) {
throw new ShineRuntimeException(e);
}
return results;
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class StagesQuery method selectForSingleStage.
private <T> List<T> selectForSingleStage(String sparql, StageIdentifier stageIdentifier, RdfResultMapper<T> mapper) {
StagesQueryCache.CacheKey key = new StagesQueryCache.CacheKey(sparql, stageIdentifier);
List<T> mappedResults = (List<T>) cache.get(key);
if (mappedResults != null) {
return mappedResults;
}
synchronized (key.getKey().intern()) {
mappedResults = (List<T>) cache.get(key);
if (mappedResults != null) {
return mappedResults;
}
Graph graph = stageGraphLoader.load(stageIdentifier);
List<BoundVariables> boundVariableses = graph.select(sparql);
mappedResults = new ArrayList<>();
for (BoundVariables bv : boundVariableses) {
mappedResults.add(mapper.map(bv));
}
cache.put(mappedResults, key);
return mappedResults;
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetBoolean.
@Test
public void checkGetBoolean() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "<http://example.com/1> ex:is \"true\"^^xsd:boolean . " + "<http://example.com/2> ex:is \"false\"^^xsd:boolean . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?one ?two ?three WHERE { " + "<http://example.com/1> ex:is ?one . " + "<http://example.com/2> ex:is ?two . " + "OPTIONAL { <http://example.com/3> ex:is ?three } " + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertTrue(bv.getBoolean("one"));
assertFalse(bv.getBoolean("two"));
assertNull(bv.getBoolean("three"));
try {
bv.getBoolean("baz");
fail("Illegal argument exception expected.");
} catch (IllegalArgumentException e) {
assertEquals("boundName 'baz' is not in the list of possible values ('one', 'two', 'three')", e.getMessage());
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetBoundVariableNames.
@Test
public void checkGetBoundVariableNames() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "<http://example.com/1> ex:is <http://hello> . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?one ?two WHERE { " + "<http://example.com/1> ex:is ?one . " + "OPTIONAL { [] ex:nope ?two } " + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertEquals("one", bv.getBoundVariableNames().get(0));
assertEquals("two", bv.getBoundVariableNames().get(1));
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class StagesQueryTest method testQueryResultWillBeGetFromCacheIfCacheIsHit.
@Test
public void testQueryResultWillBeGetFromCacheIfCacheIsHit() {
InMemoryCache cache = new InMemoryCache();
StagesQuery stagesQuery = new StagesQuery(graphLoader, cache);
String sparql = "PREFIX cruise:<" + GoOntology.URI + ">" + "SELECT ?job WHERE {" + " ?job a cruise:Job . " + "}";
StageIdentifier stageIdentifier = new StageIdentifier("p", 1, "s", "2");
cache.put(Arrays.<BoundVariables>asList(new BoundVariablesStub("job", "http://job/1")), new StagesQueryCache.CacheKey(sparql, stageIdentifier));
List<BoundVariables> bvs = stagesQuery.select(sparql, Arrays.asList(stageIdentifier), new RdfResultMapper<BoundVariables>() {
public BoundVariables map(BoundVariables aRow) {
return aRow;
}
});
assertEquals(1, bvs.size());
assertEquals("http://job/1", bvs.get(0).getAsString("job"));
}
Aggregations