Search in sources :

Example 21 with InternalErrorException

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

the class TupleLib method quad.

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

Example 22 with InternalErrorException

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

the class PageBlockMgr method promoteInPlace.

/**
 * Promote a page to be writable in-place (block id does not change, hence page does not change id).
 */
public void promoteInPlace(Page page) {
    Block block = page.getBackingBlock();
    block.getByteBuffer().rewind();
    Block block2 = blockMgr.promote(block);
    block2.setReadOnly(false);
    if (block2.getId() != block.getId())
        throw new InternalErrorException("Block id changed");
    if (block2 == block)
        return;
// Change - reset Block in page.
// The details should not have changed.
// page.reset(block2);
}
Also used : Block(org.apache.jena.dboe.base.block.Block) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 23 with InternalErrorException

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

the class ShexValidationTest method run.

@Override
public void run() {
    Graph graph = RDFDataMgr.loadGraph(data.getURI());
    try {
        if (ShexTests.dumpTest)
            describeTest();
        ShexReport report;
        switch(this.testType) {
            case ShapeFocus:
                report = ShexValidator.get().validate(graph, shapes, shape, focus);
                break;
            case ShapeMap:
                report = ShexValidator.get().validate(graph, shapes, shapeMap);
                break;
            case StartFocus:
                {
                    ShexShape startShape = shapes.getStart();
                    report = ShexValidator.get().validate(graph, shapes, startShape, focus);
                    break;
                }
            default:
                throw new InternalErrorException("No test type");
        }
        boolean b = (positiveTest == report.conforms());
        if (!b) {
            if (!ShexTests.dumpTest)
                describeTest();
        }
        assertEquals(entry.getName(), positiveTest, report.conforms());
    } catch (java.lang.AssertionError ex) {
        throw ex;
    } catch (Throwable ex) {
        describeTest();
        System.out.println("Exception: " + ex.getMessage());
        if (!(ex instanceof Error))
            ex.printStackTrace(System.out);
        else
            System.out.println(ex.getClass().getName());
        Shex.printSchema(shapes);
        throw ex;
    }
}
Also used : Graph(org.apache.jena.graph.Graph) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 24 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 25 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)48 Node (org.apache.jena.graph.Node)14 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 AccessStep (org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)3 Graph (org.apache.jena.graph.Graph)3 Triple (org.apache.jena.graph.Triple)3 Var (org.apache.jena.sparql.core.Var)3 StringReader (java.io.StringReader)2 DataAccessPoint (org.apache.jena.fuseki.server.DataAccessPoint)2 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 Table (org.apache.jena.sparql.algebra.Table)2 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2