Search in sources :

Example 36 with SailException

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

the class SailTest method showNamespaces.

private void showNamespaces(final SailConnection c) throws SailException {
    System.out.println("namespaces:");
    CloseableIteration<? extends Namespace, SailException> iter = c.getNamespaces();
    try {
        while (iter.hasNext()) {
            Namespace n = iter.next();
            System.out.println("\t" + n.getPrefix() + ":\t" + n.getName());
        }
    } finally {
        iter.close();
    }
}
Also used : SailException(org.openrdf.sail.SailException) Namespace(org.openrdf.model.Namespace)

Example 37 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 38 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 39 with SailException

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

the class GraphSailTest method testCodePlay.

@Test
public void testCodePlay() throws Exception {
    Sail sail = new GraphSail(new TinkerGraph());
    sail.initialize();
    try {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            ValueFactory vf = sail.getValueFactory();
            sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#knows"), vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com"));
            sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("marko"), vf.createURI("http://tinkerpop.com"));
            sc.addStatement(vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("josh"), vf.createURI("http://tinkerpop.com"));
            CloseableIteration<? extends Statement, SailException> results = sc.getStatements(null, null, null, false);
            try {
                System.out.println("get statements: ?s ?p ?o ?g");
                while (results.hasNext()) {
                    System.out.println(results.next());
                }
            } finally {
                results.close();
            }
            System.out.println("\nget statements: http://tinkerpop.com#3 ?p ?o ?g");
            results = sc.getStatements(vf.createURI("http://tinkerpop.com#3"), null, null, false);
            try {
                while (results.hasNext()) {
                    System.out.println(results.next());
                }
            } finally {
                results.close();
            }
            SPARQLParser parser = new SPARQLParser();
            CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults;
            String queryString = "SELECT ?x ?y WHERE { ?x <http://tinkerpop.com#knows> ?y }";
            ParsedQuery query = parser.parseQuery(queryString, "http://tinkerPop.com");
            System.out.println("\nSPARQL: " + queryString);
            sparqlResults = sc.evaluate(query.getTupleExpr(), query.getDataset(), new EmptyBindingSet(), false);
            try {
                while (sparqlResults.hasNext()) {
                    System.out.println(sparqlResults.next());
                }
            } finally {
                sparqlResults.close();
            }
            Graph graph = ((GraphSail) sail).getBaseGraph();
            System.out.println();
            for (Vertex v : graph.getVertices()) {
                System.out.println("------");
                System.out.println(v);
                for (String key : v.getPropertyKeys()) {
                    System.out.println(key + "=" + v.getProperty(key));
                }
            }
            for (Edge e : graph.getEdges()) {
                System.out.println("------");
                System.out.println(e);
                for (String key : e.getPropertyKeys()) {
                    System.out.println(key + "=" + e.getProperty(key));
                }
            }
        } finally {
            sc.rollback();
            sc.close();
        }
    } finally {
        sail.shutDown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ValueFactory(org.openrdf.model.ValueFactory) SailException(org.openrdf.sail.SailException) EmptyBindingSet(org.openrdf.query.impl.EmptyBindingSet) SailConnection(org.openrdf.sail.SailConnection) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Sail(org.openrdf.sail.Sail) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 40 with SailException

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

the class SailTest method testClearNamespaces.

// namespaces //////////////////////////////////////////////////////////////
@Test
public void testClearNamespaces() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        CloseableIteration<? extends Namespace, SailException> namespaces;
        int count;
        count = 0;
        namespaces = sc.getNamespaces();
        while (namespaces.hasNext()) {
            namespaces.next();
            count++;
        }
        namespaces.close();
        assertTrue(count > 0);
    // TODO: actually clear namespaces (but this wipes them out for
    // subsequent tests)
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException) Test(org.junit.Test)

Aggregations

SailException (org.openrdf.sail.SailException)46 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)17 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RyaClientException (org.apache.rya.api.client.RyaClientException)13 SailConnection (org.openrdf.sail.SailConnection)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 Sail (org.openrdf.sail.Sail)11 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)10 URI (org.openrdf.model.URI)10 RepositoryException (org.openrdf.repository.RepositoryException)10 MalformedQueryException (org.openrdf.query.MalformedQueryException)9 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)8 Statement (org.openrdf.model.Statement)8 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 Resource (org.openrdf.model.Resource)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)4