Search in sources :

Example 1 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class CSVInputIterator method parseNextBinding.

private boolean parseNextBinding() {
    String line;
    try {
        line = this.reader.readLine();
        //Once EOF has been reached we'll see null for this call so we can return false because there are no further bindings
        if (line == null)
            return false;
        this.lineNum++;
    } catch (IOException e) {
        throw new QueryException("Error parsing CSV results - " + e.getMessage());
    }
    if (line.isEmpty()) {
        // which means a non-empty string which we handle normally
        if (expectedItems > 1)
            throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems));
        binding = BindingFactory.create();
        if (expectedItems == 1)
            binding.add(vars.get(0), NodeConst.emptyString);
        return true;
    }
    binding = parseLine(vars, line);
    return true;
}
Also used : QueryException(org.apache.jena.query.QueryException) IOException(java.io.IOException)

Example 2 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class ParserSPARQL10 method perform.

// All throwable handling.
private static void perform(Query query, String string, Action action) {
    Reader in = new StringReader(string);
    SPARQLParser10 parser = new SPARQLParser10(in);
    try {
        query.setStrict(true);
        parser.setQuery(query);
        action.exec(parser);
    } catch (org.apache.jena.sparql.lang.sparql_10.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_10.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (QueryException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.warn(ParserSPARQL10.class, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) StringReader(java.io.StringReader)

Example 3 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class QueryUtils method checkParse.

public static void checkParse(Query query) {
    if (!SPARQLParserRegistry.get().containsFactory(query.getSyntax()))
        return;
    IndentedLineBuffer buff = new IndentedLineBuffer();
    query.serialize(buff, query.getSyntax());
    String tmp = buff.toString();
    Query query2 = null;
    try {
        String baseURI = null;
        if (!query.explicitlySetBaseURI())
            // Not in query - use the same one (e.g. file read from) .  
            baseURI = query.getBaseURI();
        query2 = QueryFactory.create(tmp, baseURI, query.getSyntax());
        if (query2 == null)
            return;
    } catch (UnsupportedOperationException ex) {
        // No parser after all.
        return;
    } catch (QueryException ex) {
        System.err.println(tmp);
        throw new QueryCheckException("could not parse output query", ex);
    }
    if (query.hashCode() != query2.hashCode())
        throw new QueryCheckException("reparsed query hashCode does not equal parsed input query \nQuery (hashCode: " + query.hashCode() + ")=\n" + query + "\n\nQuery2 (hashCode: " + query2.hashCode() + ")=\n" + query2);
    if (!query.equals(query2))
        throw new QueryCheckException("reparsed output does not equal parsed input");
}
Also used : QueryException(org.apache.jena.query.QueryException) Query(org.apache.jena.query.Query) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 4 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class PathParser method parse.

public static Path parse(String str, Prologue prologue) {
    Query query = new Query(prologue);
    Reader in = new StringReader(str);
    ARQParser parser = new ARQParser(in);
    try {
        query.setStrict(true);
        parser.setQuery(query);
        return parser.PathUnit();
    } catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (QueryException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.warn(PathParser.class, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : Query(org.apache.jena.query.Query) StringReader(java.io.StringReader) Reader(java.io.Reader) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) StringReader(java.io.StringReader)

Example 5 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class ParserARQUpdate method _parse.

private void _parse(UpdateSink sink, Reader r) {
    ARQParser parser = null;
    try {
        parser = new ARQParser(r);
        parser.setUpdateSink(sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (QueryException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.error(this, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

QueryException (org.apache.jena.query.QueryException)9 QueryParseException (org.apache.jena.query.QueryParseException)6 JenaException (org.apache.jena.shared.JenaException)6 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)3 Query (org.apache.jena.query.Query)2 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)1 QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 SPARQLParser10 (org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)1 UpdateException (org.apache.jena.update.UpdateException)1