use of org.apache.jena.sparql.ARQException in project jena by apache.
the class ResultSetFormatter method output.
/**
* Output a ResultSet in some format.
* To get detailed control over each format, call the appropriate operation directly.
*
* @param outStream Output
* @param resultSet Result set
* @param rFmt A format to encode the result set in
*/
public static void output(OutputStream outStream, ResultSet resultSet, ResultsFormat rFmt) {
Lang lang = ResultsFormat.convert(rFmt);
if (lang != null) {
output(outStream, resultSet, lang);
return;
}
boolean b = ResultsFormat.oldWrite(outStream, rFmt, null, resultSet);
if (b)
return;
throw new ARQException("Unknown ResultSet format: " + rFmt);
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class DatasetFactory method assemble.
/**
* Assemble a dataset from the model
*
* @param model
* @return Dataset
*/
public static Dataset assemble(Model model) {
Objects.requireNonNull(model, "model can not be null");
Resource r = GraphUtils.findRootByType(model, DatasetAssembler.getType());
if (r == null)
throw new ARQException("No root found for type <" + DatasetAssembler.getType() + ">");
return assemble(r);
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class QueryExecHTTP method performQuery.
/**
* Make a query over HTTP.
* The response is returned after status code processing so the caller can assume the
* query execution was successful and return 200.
* Use {@link HttpLib#getInputStream} to access the body.
*/
private HttpResponse<InputStream> performQuery(String reqAcceptHeader) {
if (closed)
throw new ARQException("HTTP execution already closed");
// SERVICE specials.
Params thisParams = Params.create(params);
if (defaultGraphURIs != null) {
for (String dft : defaultGraphURIs) thisParams.add(HttpParams.pDefaultGraph, dft);
}
if (namedGraphURIs != null) {
for (String name : namedGraphURIs) thisParams.add(HttpParams.pNamedGraph, name);
}
HttpLib.modifyByService(service, context, thisParams, httpHeaders);
HttpRequest request = makeRequest(thisParams, reqAcceptHeader);
return executeQuery(request);
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class DSP method uploadQuads.
/**
* Send a file of quads to a URL. The Content-Type is inferred from the file
* extension.
*/
private static void uploadQuads(HttpClient httpClient, String endpoint, String file, String fileExtContentType, Map<String, String> headers, Push mode) {
Lang lang = RDFLanguages.contentTypeToLang(fileExtContentType);
if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang))
throw new ARQException("Not an RDF format: " + file + " (lang=" + lang + ")");
pushFile(httpClient, endpoint, file, fileExtContentType, headers, mode);
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class QueryExecUtils method getAtMostOne.
/**
* Execute, expecting the result to be one row, one column. Return that one
* RDFNode or null. Throw exception if more than one.
* Use with {@code try ( QueryExecution qExec = ....)}.
*/
public static RDFNode getAtMostOne(QueryExecution qExec, String varname) {
ResultSet rs = qExec.execSelect();
if (!rs.hasNext())
return null;
QuerySolution qs = rs.nextSolution();
RDFNode r = qs.get(varname);
if (rs.hasNext()) {
QuerySolution qs2 = rs.next();
RDFNode r2 = qs2.get(varname);
if (rs.hasNext())
throw new ARQException("More than one: var ?" + varname + " -> " + r + ", " + r2 + ", ...");
else
throw new ARQException("Found two matches: var ?" + varname + " -> " + r + ", " + r2);
}
return r;
}
Aggregations