Search in sources :

Example 1 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class PatternMatchTDB2 method execute.

// The worker.  Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (Quad.isUnionGraph(graphNode))
        graphNode = Node.ANY;
    if (Quad.isDefaultGraph(graphNode))
        graphNode = null;
    List<Triple> triples = pattern.getList();
    boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
    int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
    if (graphNode == null) {
        if (3 != tupleLen)
            throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
    } else {
        if (4 != tupleLen)
            throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
    }
    // Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
    List<Abortable> killList = new ArrayList<>();
    for (Triple triple : triples) {
        Tuple<Node> patternTuple = null;
        if (graphNode == null)
            // 3-tuples
            patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
        else
            // 4-tuples.
            patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
        // Plain RDF, no RDF-star
        // chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
        // ;
        // RDF-star SA
        chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
        chain = makeAbortable(chain, killList);
    }
    Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
    // "killList" will be aborted on timeout.
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) TDBException(org.apache.jena.tdb2.TDBException) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Triple(org.apache.jena.graph.Triple) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 2 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class NodeIdFactory method create.

private static NodeId create(int v1, long v2) {
    if (!BitsInt.isSet(v1, 32))
        return createPtrLong(v1, v2);
    int t = v1 >> 24;
    NodeIdType type = NodeIdType.intToEnum(t);
    if (type == NodeIdType.SPECIAL)
        throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
    return createNew(type, 0, v2);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 3 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class NodeIdFactory method create64.

// ---- Create from binary.
// 64 bit create
private static NodeId create64(long value2) {
    if (!BitsLong.isSet(value2, 63))
        return createPtr(value2);
    // Inline.
    long v2 = value2;
    if (BitsLong.isSet(v2, 62)) {
        // XSD_DOUBLE
        v2 = DoubleNode62.removeType(v2);
        return NodeId.createRaw(NodeIdType.XSD_DOUBLE, v2);
    }
    // 7 bits
    int t = (int) BitsLong.unpack(v2, 56, 63);
    v2 = BitsLong.clear(v2, 56, 64);
    NodeIdType type = NodeIdType.intToEnum(t);
    if (type == NodeIdType.SPECIAL)
        throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
    return NodeId.createRaw(type, v2);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 4 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class StoreParamsCodec method getStringArray.

private static String[] getStringArray(JsonObject json, String key) {
    if (!json.hasKey(key))
        throw new TDBException("StoreParamsCodec.getStringArray: no such key: " + key);
    JsonArray a = json.get(key).getAsArray();
    String[] x = new String[a.size()];
    for (int i = 0; i < a.size(); i++) {
        x[i] = a.get(i).getAsString().value();
    }
    return x;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 5 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class NodeTableCache method testForConsistency.

private void testForConsistency() {
    Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator();
    for (; iter1.hasNext(); ) {
        Node n = iter1.next();
        NodeId nId = node2id_Cache.getIfPresent(n);
        if (!id2node_Cache.containsKey(nId))
            throw new TDBException("Inconsistent: " + n + " => " + nId);
        if (notPresent.containsKey(n))
            throw new TDBException("Inconsistent: " + n + " in notPresent cache (1)");
    }
    Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator();
    for (; iter2.hasNext(); ) {
        NodeId nId = iter2.next();
        Node n = id2node_Cache.getIfPresent(nId);
        if (!node2id_Cache.containsKey(n))
            throw new TDBException("Inconsistent: " + nId + " => " + n);
        if (notPresent.containsKey(n))
            throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)");
    }
}
Also used : Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId)

Aggregations

TDBException (org.apache.jena.tdb2.TDBException)20 NodeId (org.apache.jena.tdb2.store.NodeId)6 Node (org.apache.jena.graph.Node)4 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)4 Location (org.apache.jena.dboe.base.file.Location)3 Record (org.apache.jena.dboe.base.record.Record)3 RiotThriftException (org.apache.jena.riot.thrift.RiotThriftException)2 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 TException (org.apache.thrift.TException)2 ArrayList (java.util.ArrayList)1 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1 FileSet (org.apache.jena.dboe.base.file.FileSet)1 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)1 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)1 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)1