Search in sources :

Example 11 with SailException

use of org.openrdf.sail.SailException in project blueprints by tinkerpop.

the class SailGraph method rollback.

public void rollback() {
    try {
        SailConnection sc = this.sailConnection.get();
        sc.rollback();
        sc.begin();
    } catch (SailException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException)

Example 12 with SailException

use of org.openrdf.sail.SailException in project blueprints by tinkerpop.

the class SailVertex method updateLiteral.

private void updateLiteral(final Literal oldLiteral, final Literal newLiteral) {
    try {
        final Set<Statement> statements = new HashSet<Statement>();
        final CloseableIteration<? extends Statement, SailException> results = this.graph.getSailConnection().get().getStatements(null, null, oldLiteral, false);
        while (results.hasNext()) {
            statements.add(results.next());
        }
        results.close();
        this.graph.getSailConnection().get().removeStatements(null, null, oldLiteral);
        for (Statement statement : statements) {
            SailHelper.addStatement(statement.getSubject(), statement.getPredicate(), newLiteral, statement.getContext(), this.graph.getSailConnection().get());
        }
    } catch (SailException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Statement(org.openrdf.model.Statement) SailException(org.openrdf.sail.SailException) HashSet(java.util.HashSet)

Example 13 with SailException

use of org.openrdf.sail.SailException in project blueprints by tinkerpop.

the class PropertyGraphSailConnection method evaluateInternal.

protected CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluateInternal(final TupleExpr query, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) throws SailException {
    try {
        TripleSource tripleSource = new SailConnectionTripleSource(this, context.valueFactory, includeInferred);
        EvaluationStrategyImpl strategy = new EvaluationStrategyImpl(tripleSource, dataset);
        return strategy.evaluate(query, bindings);
    } catch (QueryEvaluationException e) {
        throw new SailException(e);
    }
}
Also used : SailConnectionTripleSource(net.fortytwo.sesametools.SailConnectionTripleSource) TripleSource(org.openrdf.query.algebra.evaluation.TripleSource) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) SailConnectionTripleSource(net.fortytwo.sesametools.SailConnectionTripleSource) SailException(org.openrdf.sail.SailException) EvaluationStrategyImpl(org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl)

Example 14 with SailException

use of org.openrdf.sail.SailException in project blueprints by tinkerpop.

the class PropertyGraphSailConnection method getStatements_xPO.

private CloseableIteration<Statement, SailException> getStatements_xPO(final URI predicate, final Value object) throws SailException {
    if (predicate.equals(RDF.TYPE)) {
        if (object.equals(PropertyGraphSail.VERTEX)) {
            Source<Vertex> s = new Source<Vertex>(context.graph.getVertices().iterator(), vertexTypes);
            return new StatementIteration(s);
        } else if (object.equals(PropertyGraphSail.EDGE) && firstClassEdges) {
            Source<Edge> s = new Source<Edge>(context.graph.getEdges().iterator(), edgeTypes);
            return new StatementIteration(s);
        } else {
            return new StatementIteration();
        }
    } else if (predicate.equals(PropertyGraphSail.ID)) {
        Object id = literalToObject(object);
        if (null == id) {
            return new StatementIteration();
        } else {
            Vertex v = context.graph.getVertex(id);
            Edge e = firstClassEdges ? context.graph.getEdge(id) : null;
            if (null == v && null == e) {
                return new StatementIteration();
            } else {
                Collection<Statement> s = new LinkedList<Statement>();
                if (null != v) {
                    vertexIds.generate(v, s);
                }
                if (null != e) {
                    edgeIds.generate(e, s);
                }
                return new SimpleCloseableIteration<Statement, SailException>(s.iterator());
            }
        }
    } else if (predicate.equals(PropertyGraphSail.LABEL)) {
        if (!firstClassEdges) {
            return new StatementIteration();
        }
        // TODO: find edges faster using indices
        Object label = literalToObject(object);
        if (null == label || !(label instanceof String)) {
            return new StatementIteration();
        } else {
            Source<Edge> edges = new Source<Edge>(context.graph.getEdges().iterator(), matchingLabels((String) label, object));
            return new StatementIteration(edges);
        }
    } else if (predicate.equals(PropertyGraphSail.HEAD)) {
        if (!firstClassEdges) {
            return new StatementIteration();
        }
        Vertex v = object instanceof URI ? vertexForURI((URI) object) : null;
        if (null == v) {
            return new StatementIteration();
        } else {
            Iterator<Edge> edgeIterator = v.getEdges(Direction.IN).iterator();
            Source<Edge> edges = new Source<Edge>(edgeIterator, heads);
            return new StatementIteration(edges);
        }
    } else if (predicate.equals(PropertyGraphSail.TAIL)) {
        if (!firstClassEdges) {
            return new StatementIteration();
        }
        Vertex v = object instanceof URI ? vertexForURI((URI) object) : null;
        if (null == v) {
            return new StatementIteration();
        } else {
            Iterator<Edge> edgeIterator = v.getEdges(Direction.OUT).iterator();
            Source<Edge> edges = new Source<Edge>(edgeIterator, tails);
            return new StatementIteration(edges);
        }
    } else if (isPropertyPredicate(predicate)) {
        Object value = literalToObject(object);
        if (null == value) {
            return new StatementIteration();
        } else {
            // TODO: lookup matching vertices and edges faster using indices
            String key = keyFromPredicate(predicate);
            Source<Vertex> vertices = new Source<Vertex>(context.graph.getVertices().iterator(), vertexPropertiesWithKeyAndValue(key, predicate, value, (Literal) object));
            if (firstClassEdges) {
                Source<Edge> edges = new Source<Edge>(context.graph.getEdges().iterator(), edgePropertiesWithKeyAndValue(key, predicate, value, (Literal) object));
                return new StatementIteration(vertices, edges);
            } else {
                return new StatementIteration(vertices);
            }
        }
    } else if (isRelationPredicate(predicate)) {
        if (!(object instanceof URI)) {
            return new StatementIteration();
        } else {
            String label = labelForRelationPredicate(predicate);
            Vertex vObj = vertexForURI((URI) object);
            if (null != vObj) {
                Source<Vertex> s = new Source<Vertex>(new SingleItemIterator<Vertex>(vObj), new RelationGenerator(label, true));
                return new StatementIteration(s);
            } else {
                return new StatementIteration();
            }
        }
    } else {
        return new StatementIteration();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Statement(org.openrdf.model.Statement) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) SailConnectionTripleSource(net.fortytwo.sesametools.SailConnectionTripleSource) TripleSource(org.openrdf.query.algebra.evaluation.TripleSource) Iterator(java.util.Iterator) Collection(java.util.Collection) Edge(com.tinkerpop.blueprints.Edge)

Example 15 with SailException

use of org.openrdf.sail.SailException in project blueprints by tinkerpop.

the class GraphSailConnection method getStatementsInternal.

public CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final URI predicate, final Value object, final boolean includeInferred, final Resource... contexts) throws SailException {
    int index = 0;
    if (null != subject) {
        index |= 0x1;
    }
    if (null != predicate) {
        index |= 0x2;
    }
    if (null != object) {
        index |= 0x4;
    }
    if (0 == contexts.length) {
        return createIteration(store.matchers[index].match(subject, predicate, object, null, includeInferred));
    } else {
        Collection<CloseableIteration<Statement, SailException>> iterations = new LinkedList<CloseableIteration<Statement, SailException>>();
        // TODO: as an optimization, filter on multiple contexts simultaneously (when context is not used in the matcher), rather than trying each context consecutively.
        for (Resource context : contexts) {
            index |= 0x8;
            Matcher m = store.matchers[index];
            iterations.add(createIteration(m.match(subject, predicate, object, context, includeInferred)));
        }
        return new CompoundCloseableIteration<Statement, SailException>(iterations);
    }
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) CompoundCloseableIteration(net.fortytwo.sesametools.CompoundCloseableIteration) CompoundCloseableIteration(net.fortytwo.sesametools.CompoundCloseableIteration) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) LinkedList(java.util.LinkedList)

Aggregations

SailException (org.openrdf.sail.SailException)23 SailConnection (org.openrdf.sail.SailConnection)10 Statement (org.openrdf.model.Statement)8 URI (org.openrdf.model.URI)8 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Namespace (org.openrdf.model.Namespace)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 SailConnectionTripleSource (net.fortytwo.sesametools.SailConnectionTripleSource)3 Resource (org.openrdf.model.Resource)3 TripleSource (org.openrdf.query.algebra.evaluation.TripleSource)3 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)3 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Properties (java.util.Properties)2 Value (org.openrdf.model.Value)2 ValueFactory (org.openrdf.model.ValueFactory)2 EvaluationStrategyImpl (org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl)2 Graph (com.tinkerpop.blueprints.Graph)1 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)1