Search in sources :

Example 21 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class QueryIterProcessBinding method hasNextBinding.

/**
     * Are there any more acceptable objects.
     * 
     * @return true if there is another acceptable object.
     */
@Override
protected boolean hasNextBinding() {
    // Needs to be idempotent.?
    if (isFinished())
        return false;
    if (nextBinding != null)
        return true;
    // Null iterator.
    if (getInput() == null)
        throw new ARQInternalErrorException(Lib.className(this) + ": Null iterator");
    while (getInput().hasNext()) {
        // Skip forward until a binding to return is found.
        Binding input = getInput().nextBinding();
        Binding output = accept(input);
        if (output != null) {
            nextBinding = output;
            return true;
        }
    }
    nextBinding = null;
    return false;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 22 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class QueryIterPeek method moveToNextBinding.

@Override
protected Binding moveToNextBinding() {
    if (!hasNextBinding())
        throw new ARQInternalErrorException("No next binding");
    Binding b = binding;
    binding = null;
    return b;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 23 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class NodeUtils method compareLiteralsBySyntax.

/** Compare literals by kind - not by value.
     *  Gives a determinitics, stable, arbitrary ordering between unrelated literals.
     * 
     * Ordering:
     *  <ol> 
     *  <li>By lexical form</li>
     *  <li> For same lexical form:
     *       <ul> 
     *       <li>  RDF 1.0 : simple literal < literal by lang < literal with type
     *       <li>  RDF 1.1 : xsd:string < rdf:langString < other dataypes.<br/>
     *             This is the closest to SPARQL 1.1: treat xsd:string as a simple literal</ul></li>
     *  <li> Lang by sorting on language tag (first case insensistive then case sensitive)
     *  <li> Datatypes by URI
     *  </ol>
     */
private static int compareLiteralsBySyntax(Node node1, Node node2) {
    if (node1 == null || !node1.isLiteral() || node2 == null || !node2.isLiteral())
        throw new ARQInternalErrorException("compareLiteralsBySyntax called with non-literal: (" + node1 + "," + node2 + ")");
    if (node1.equals(node2))
        return Expr.CMP_EQUAL;
    String lex1 = node1.getLiteralLexicalForm();
    String lex2 = node2.getLiteralLexicalForm();
    int x = StrUtils.strCompare(lex1, lex2);
    if (x != Expr.CMP_EQUAL)
        return x;
    // Same lexical form. Not .equals()
    if (// node2 not a simple string because they
    isSimpleString(node1))
        // would be .equals
        return Expr.CMP_LESS;
    if (isSimpleString(node2))
        return Expr.CMP_GREATER;
    // Both language strings?
    if (isLangString(node1) && isLangString(node2)) {
        String lang1 = node1.getLiteralLanguage();
        String lang2 = node2.getLiteralLanguage();
        x = StrUtils.strCompareIgnoreCase(lang1, lang2);
        if (x != Expr.CMP_EQUAL)
            return x;
        x = StrUtils.strCompare(lang1, lang2);
        if (x != Expr.CMP_EQUAL)
            return x;
        throw new ARQInternalErrorException("compareLiteralsBySyntax: lexical form and languages tags identical on non.equals literals");
    }
    // One a language string?
    if (isLangString(node1))
        return Expr.CMP_LESS;
    if (isLangString(node2))
        return Expr.CMP_GREATER;
    // Both have other datatypes. Neither simple nor language tagged.
    String dt1 = node1.getLiteralDatatypeURI();
    String dt2 = node2.getLiteralDatatypeURI();
    // Two datatypes.
    return StrUtils.strCompare(dt1, dt2);
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 24 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class ModelUtils method tripleToStatement.

public static Statement tripleToStatement(Model model, Triple t) {
    if (model == null)
        throw new ARQInternalErrorException("Attempt to create statement with null model");
    Node sNode = t.getSubject();
    Node pNode = t.getPredicate();
    Node oNode = t.getObject();
    if (!isValidAsStatement(sNode, pNode, oNode))
        return null;
    return model.asStatement(t);
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 25 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class qparse method exec.

@Override
protected void exec() {
    try {
        Query query = modQuery.getQuery();
        try {
            LogCtl.disable(ParserBase.ParserLoggerName);
            QueryUtils.checkQuery(query, true);
        } catch (QueryCheckException ex) {
            System.err.println();
            System.err.println("**** Check failure: " + ex.getMessage());
            if (ex.getCause() != null)
                ex.getCause().printStackTrace(System.err);
        } finally {
            LogCtl.setLevel(ParserBase.ParserLoggerName, "INFO");
        }
        // Print the query out in some syntax
        if (printQuery) {
            divider();
            modOutput.output(query);
        }
        // Print internal forms.
        if (printOp) {
            divider();
            modOutput.outputOp(query, false);
        }
        if (printQuad) {
            divider();
            modOutput.outputQuad(query, false);
        }
        if (printOpt) {
            divider();
            modOutput.outputOp(query, true);
        }
        if (printQuadOpt) {
            divider();
            modOutput.outputQuad(query, true);
        }
        if (printPlan) {
            divider();
            // This forces internal query initialization - must be after QueryUtils.checkQuery
            QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral());
            QueryOutputUtils.printPlan(query, qExec);
        }
    } catch (ARQInternalErrorException intEx) {
        System.err.println(intEx.getMessage());
        if (intEx.getCause() != null) {
            System.err.println("Cause:");
            intEx.getCause().printStackTrace(System.err);
            System.err.println();
        }
        intEx.printStackTrace(System.err);
    } catch (ResultSetException ex) {
        System.err.println(ex.getMessage());
        ex.printStackTrace(System.err);
    } catch (QueryException qEx) {
        //System.err.println(qEx.getMessage()) ;
        throw new CmdException("Query Exeception", qEx);
    } catch (JenaException ex) {
        ex.printStackTrace();
        throw ex;
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new CmdException("Exception", ex);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException)

Aggregations

ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)34 Node (org.apache.jena.graph.Node)6 NodeValue (org.apache.jena.sparql.expr.NodeValue)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 Var (org.apache.jena.sparql.core.Var)4 BigDecimal (java.math.BigDecimal)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)3 BigInteger (java.math.BigInteger)2 CmdException (jena.cmd.CmdException)2 TerminationException (jena.cmd.TerminationException)2 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)2 Graph (org.apache.jena.graph.Graph)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 JenaException (org.apache.jena.shared.JenaException)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)2