use of uk.ac.ebi.fgpt.lode.exception.LodeException in project goci by EBISPOT.
the class SparqlTemplate method query.
public <T> T query(String sparql, ResultSetMapper<T> rsm, Object... args) {
sparql = getPrefixString().concat(sparql);
Graph g = getJenaQueryExecutionService().getDefaultGraph();
Map<String, Object> bindingMap = new HashMap<String, Object>();
int i = 0;
for (Object o : args) {
String argName = "?_arg" + i++;
sparql = sparql.replaceFirst("\\?\\?", argName);
bindingMap.put(argName, o);
}
Query q1 = QueryFactory.create(sparql, Syntax.syntaxARQ);
QuerySolutionMap initialBinding = new QuerySolutionMap();
for (String argName : bindingMap.keySet()) {
Object argValue = bindingMap.get(argName);
RDFNode arg;
if (argValue instanceof URI) {
arg = new ResourceImpl(argValue.toString());
} else {
arg = getLiteralNode(argValue);
}
initialBinding.add(argName, arg);
}
ParameterizedSparqlString queryString = new ParameterizedSparqlString(q1.toString(), initialBinding);
QueryExecution execute = null;
try {
execute = getJenaQueryExecutionService().getQueryExecution(g, queryString.asQuery(), false);
ResultSet results = execute.execSelect();
return rsm.mapResultSet(results);
} catch (LodeException e) {
throw new SparqlQueryException("Failed to execute query '" + sparql + "'", e);
} finally {
if (execute != null) {
execute.close();
if (g != null) {
g.close();
}
}
}
}
use of uk.ac.ebi.fgpt.lode.exception.LodeException in project goci by EBISPOT.
the class SparqlTemplate method query.
public <T> T query(String sparql, ResultSetMapper<T> rsm) {
sparql = getPrefixString().concat(sparql);
Graph g = getJenaQueryExecutionService().getDefaultGraph();
Query q1 = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution execute = null;
try {
execute = getJenaQueryExecutionService().getQueryExecution(g, q1, false);
ResultSet results = execute.execSelect();
return rsm.mapResultSet(results);
} catch (LodeException e) {
throw new SparqlQueryException("Failed to execute query '" + sparql + "'", e);
} finally {
if (execute != null) {
execute.close();
if (g != null) {
g.close();
}
}
}
}
use of uk.ac.ebi.fgpt.lode.exception.LodeException in project goci by EBISPOT.
the class SparqlTemplate method ask.
public boolean ask(String sparql) {
sparql = getPrefixString().concat(sparql);
if (askCache.containsKey(sparql)) {
return askCache.get(sparql);
}
Graph g = getJenaQueryExecutionService().getDefaultGraph();
Query q1 = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution execute = null;
try {
execute = getJenaQueryExecutionService().getQueryExecution(g, q1, false);
boolean result = execute.execAsk();
askCache.put(sparql, result);
return result;
} catch (LodeException e) {
throw new SparqlQueryException("Failed to execute ask '" + sparql + "'", e);
} finally {
if (execute != null) {
execute.close();
if (g != null) {
g.close();
}
}
}
}
Aggregations