Search in sources :

Example 1 with UnsupportedSPARQLStatementException

use of com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException in project gocd by gocd.

the class SesameGraph method renderSPARQLResultsAsXML.

public void renderSPARQLResultsAsXML(String sparql, OutputStream stream) {
    try {
        Query query = conn.prepareQuery(QueryLanguage.SPARQL, sparql);
        contextualize(query);
        if (query instanceof TupleQuery) {
            renderTupleQuery(query, new SPARQLResultsXMLWriter(stream));
        } else {
            renderBooleanQuery(query, new SPARQLBooleanXMLWriter(stream));
        }
        stream.flush();
    } catch (UnsupportedSPARQLStatementException e) {
        throw e;
    } catch (Exception e) {
        throw new ShineRuntimeException("Could not render sparql results as XML: <<" + sparql + ">>", e);
    }
}
Also used : SPARQLResultsXMLWriter(org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) SailQuery(org.openrdf.repository.sail.SailQuery) Query(org.openrdf.query.Query) TupleQuery(org.openrdf.query.TupleQuery) BooleanQuery(org.openrdf.query.BooleanQuery) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) SPARQLBooleanXMLWriter(org.openrdf.query.resultio.sparqlxml.SPARQLBooleanXMLWriter) TupleQuery(org.openrdf.query.TupleQuery) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 2 with UnsupportedSPARQLStatementException

use of com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException in project gocd by gocd.

the class SesameGraph method contextualize.

private void contextualize(Query query) throws Exception {
    if (contextVar == null) {
        return;
    }
    TupleExpr tupleExpr = ((SailQuery) query).getParsedQuery().getTupleExpr();
    tupleExpr.visit(new QueryModelVisitorBase() {

        public void meet(StatementPattern node) throws Exception {
            if (node.getContextVar() != null) {
                throw new UnsupportedSPARQLStatementException("Attempted to execute a SPARQL statement with a GRAPH clause against a context aware graph.");
            }
            node.setContextVar(contextVar);
        }
    });
}
Also used : QueryModelVisitorBase(org.openrdf.query.algebra.helpers.QueryModelVisitorBase) StatementPattern(org.openrdf.query.algebra.StatementPattern) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) TupleExpr(org.openrdf.query.algebra.TupleExpr) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 3 with UnsupportedSPARQLStatementException

use of com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException in project gocd by gocd.

the class SesameGraph method getTupleQueryResult.

private TupleQueryResult getTupleQueryResult(String sparqlSelect) {
    try {
        TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlSelect);
        contextualize(tupleQuery);
        return tupleQuery.evaluate();
    } catch (UnsupportedSPARQLStatementException e) {
        throw e;
    } catch (Exception e) {
        throw new ShineRuntimeException(e);
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) TupleQuery(org.openrdf.query.TupleQuery) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 4 with UnsupportedSPARQLStatementException

use of com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException in project gocd by gocd.

the class SesameGraph method getBooleanQueryResult.

private boolean getBooleanQueryResult(String sparqlSelect) {
    try {
        BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, sparqlSelect);
        contextualize(booleanQuery);
        return booleanQuery.evaluate();
    } catch (UnsupportedSPARQLStatementException e) {
        throw e;
    } catch (Exception e) {
        throw new ShineRuntimeException(e);
    }
}
Also used : BooleanQuery(org.openrdf.query.BooleanQuery) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 5 with UnsupportedSPARQLStatementException

use of com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException in project gocd by gocd.

the class SesameGraph method validate.

public void validate(String arq) {
    try {
        Query query = conn.prepareQuery(QueryLanguage.SPARQL, arq);
        contextualize(query);
    } catch (UnsupportedSPARQLStatementException e) {
        throw e;
    } catch (MalformedQueryException e) {
        throw new MalformedSPARQLException(e);
    } catch (Exception e) {
        throw new ShineRuntimeException(e);
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) SailQuery(org.openrdf.repository.sail.SailQuery) Query(org.openrdf.query.Query) TupleQuery(org.openrdf.query.TupleQuery) BooleanQuery(org.openrdf.query.BooleanQuery) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Aggregations

ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)5 MalformedSPARQLException (com.thoughtworks.studios.shine.semweb.MalformedSPARQLException)5 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)5 UnsupportedSPARQLStatementException (com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)5 IOException (java.io.IOException)5 NoSuchElementException (java.util.NoSuchElementException)5 OpenRDFException (org.openrdf.OpenRDFException)5 MalformedQueryException (org.openrdf.query.MalformedQueryException)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)5 RepositoryException (org.openrdf.repository.RepositoryException)5 RDFHandlerException (org.openrdf.rio.RDFHandlerException)5 BooleanQuery (org.openrdf.query.BooleanQuery)3 TupleQuery (org.openrdf.query.TupleQuery)3 Query (org.openrdf.query.Query)2 SailQuery (org.openrdf.repository.sail.SailQuery)2 StatementPattern (org.openrdf.query.algebra.StatementPattern)1 TupleExpr (org.openrdf.query.algebra.TupleExpr)1 QueryModelVisitorBase (org.openrdf.query.algebra.helpers.QueryModelVisitorBase)1 SPARQLBooleanXMLWriter (org.openrdf.query.resultio.sparqlxml.SPARQLBooleanXMLWriter)1