Search in sources :

Example 11 with ARQException

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);
}
Also used : ARQException(org.apache.jena.sparql.ARQException) ResultSetLang(org.apache.jena.riot.resultset.ResultSetLang) Lang(org.apache.jena.riot.Lang)

Example 12 with ARQException

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);
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Resource(org.apache.jena.rdf.model.Resource)

Example 13 with ARQException

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);
}
Also used : HttpRequest(java.net.http.HttpRequest) ARQException(org.apache.jena.sparql.ARQException) HttpParams(org.apache.jena.sparql.engine.http.HttpParams)

Example 14 with ARQException

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);
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Lang(org.apache.jena.riot.Lang)

Example 15 with ARQException

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;
}
Also used : ARQException(org.apache.jena.sparql.ARQException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

ARQException (org.apache.jena.sparql.ARQException)48 IOException (java.io.IOException)11 Var (org.apache.jena.sparql.core.Var)7 ArrayList (java.util.ArrayList)5 Lang (org.apache.jena.riot.Lang)5 BufferedReader (java.io.BufferedReader)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 Node (org.apache.jena.graph.Node)4 Syntax (org.apache.jena.query.Syntax)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Triple (org.apache.jena.graph.Triple)2 Query (org.apache.jena.query.Query)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 RiotException (org.apache.jena.riot.RiotException)2 HttpParams (org.apache.jena.sparql.engine.http.HttpParams)2 Item (org.apache.jena.sparql.sse.Item)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 BufferedWriter (java.io.BufferedWriter)1