Search in sources :

Example 11 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class LibSDB method findTriples.

/** Find triples, in the default graph or a named graph. */
public static Iterator<Triple> findTriples(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
    if (Var.isVar(g))
        throw new InternalErrorException("Graph node is a variable : " + g);
    final Node vs = varOrConst(s, "s");
    final Node vp = varOrConst(p, "p");
    final Node vo = varOrConst(o, "o");
    // Evaluate as an algebra expression
    Triple triple = new Triple(vs, vp, vo);
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = (g != null) ? new OpQuadPattern(g, pattern) : new OpBGP(pattern);
    Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
    QueryIterator qIter = plan.iterator();
    Iterator<Binding> iter;
    if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
        // Assumes iterator closed properly.
        iter = qIter;
    } else {
        // ---- Safe version: 
        List<Binding> x = Iter.toList(qIter);
        Iterator<Binding> qIter2 = x.iterator();
        qIter.close();
        iter = qIter2;
    }
    return Iter.map(iter, (b) -> bindingToTriple(vs, vp, vo, b));
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Plan(org.apache.jena.sparql.engine.Plan)

Example 12 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class TupleLib method triple.

private static Triple triple(NodeTable nodeTable, NodeId s, NodeId p, NodeId o) {
    if (!NodeId.isConcrete(s))
        throw new InternalErrorException("Invalid id for subject: " + fmt(s, p, o));
    if (!NodeId.isConcrete(p))
        throw new InternalErrorException("Invalid id for predicate: " + fmt(s, p, o));
    if (!NodeId.isConcrete(o))
        throw new InternalErrorException("Invalid id for object: " + fmt(s, p, o));
    Node sNode = nodeTable.getNodeForNodeId(s);
    if (sNode == null)
        throw new InternalErrorException("Invalid id node for subject (null node): " + fmt(s, p, o));
    Node pNode = nodeTable.getNodeForNodeId(p);
    if (pNode == null) {
        nodeTable.getNodeForNodeId(p);
        throw new InternalErrorException("Invalid id node for predicate (null node): " + fmt(s, p, o));
    }
    Node oNode = nodeTable.getNodeForNodeId(o);
    if (oNode == null)
        throw new InternalErrorException("Invalid id node for object (null node): " + fmt(s, p, o));
    return new Triple(sNode, pNode, oNode);
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 13 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class DatasetGraphInMemory method _commit.

private void _commit() {
    withLock(systemLock, () -> {
        quadsIndex().commit();
        defaultGraph().commit();
        quadsIndex().end();
        defaultGraph().end();
        if (transactionType().equals(WRITE)) {
            if (version.get() != generation.get())
                throw new InternalErrorException(String.format("Version=%d, Generation=%d", version.get(), generation.get()));
            generation.incrementAndGet();
        }
    });
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 14 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class NodeTransformExpr method transform.

/** Transform node then create a {@link ExprVar} or {@link NodeValue}. */
private Expr transform(Node input) {
    Node n = transform.apply(input);
    if (n == null)
        throw new InternalErrorException("NodeTransform creates a null");
    if (!Var.isVar(n))
        return NodeValue.makeNode(n);
    String name = Var.alloc(n).getVarName();
    return new ExprVar(n.getName());
}
Also used : Node(org.apache.jena.graph.Node) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 15 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class SPARQL_QueryGeneral method datasetFromDescription.

/**
     * Construct a Dataset based on a dataset description.
     */
protected static Dataset datasetFromDescription(HttpAction action, DatasetDescription datasetDesc) {
    try {
        if (datasetDesc == null)
            return null;
        if (datasetDesc.isEmpty())
            return null;
        List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
        List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
        if (graphURLs.size() == 0 && namedGraphs.size() == 0)
            return null;
        Dataset dataset = DatasetFactory.createGeneral();
        // ---- Default graph
        {
            Model model = ModelFactory.createDefaultModel();
            for (String uri : graphURLs) {
                if (uri == null || uri.equals(""))
                    throw new InternalErrorException("Default graph URI is null or the empty string");
                try {
                    //TODO Clearup - RIOT integration.
                    GraphLoadUtils.loadModel(model, uri, MaxTriples);
                    log.info(format("[%d] Load (default graph) %s", action.id, uri));
                } catch (RiotException ex) {
                    log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
                    errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
                } catch (Exception ex) {
                    log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
                    errorBadRequest("Failed to load URL " + uri);
                }
            }
            dataset.setDefaultModel(model);
        }
        // ---- Named graphs
        if (namedGraphs != null) {
            for (String uri : namedGraphs) {
                if (uri == null || uri.equals(""))
                    throw new InternalErrorException("Named graph URI is null or the empty string");
                try {
                    Model model = ModelFactory.createDefaultModel();
                    GraphLoadUtils.loadModel(model, uri, MaxTriples);
                    log.info(format("[%d] Load (named graph) %s", action.id, uri));
                    dataset.addNamedModel(uri, model);
                } catch (RiotException ex) {
                    log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
                    errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
                } catch (Exception ex) {
                    log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
                    errorBadRequest("Failed to load URL " + uri);
                }
            }
        }
        return dataset;
    } catch (ActionErrorException ex) {
        throw ex;
    } catch (Exception ex) {
        log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
        errorBadRequest("Parameter error: " + ex.getMessage());
        return null;
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) RiotException(org.apache.jena.riot.RiotException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Aggregations

InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)18 Node (org.apache.jena.graph.Node)5 Triple (org.apache.jena.graph.Triple)2 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 RiotException (org.apache.jena.riot.RiotException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Var (org.apache.jena.sparql.core.Var)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 Expr (org.apache.jena.sparql.expr.Expr)2 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 CmdException (jena.cmd.CmdException)1 ContentType (org.apache.jena.atlas.web.ContentType)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 DatasetDescriptionRegistry (org.apache.jena.fuseki.build.DatasetDescriptionRegistry)1 Graph (org.apache.jena.graph.Graph)1