Search in sources :

Example 16 with SailException

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

the class SailTest method testBlankNodes.

// blank nodes /////////////////////////////////////////////////////////////
@Test
public void testBlankNodes() throws Throwable {
    URI uriA = sail.getValueFactory().createURI("http://example.org/test/S_POG#a");
    URI uriB = sail.getValueFactory().createURI("http://example.org/test/S_POG#b");
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        ValueFactory factory = sail.getValueFactory();
        BNode bNode = factory.createBNode();
        try {
            sc.addStatement(uriA, uriA, bNode);
        } catch (SailException se) {
            // FIXME: not supporting blank nodes ATM
            assertTrue(se.getCause() instanceof UnsupportedOperationException);
        }
        sc.commit();
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) BNode(org.openrdf.model.BNode) ValueFactory(org.openrdf.model.ValueFactory) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 17 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 18 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 19 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)

Example 20 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method computeCachedInformation.

private void computeCachedInformation() {
    if (_propertyRecords == null || _typeRecords == null) {
        getRepository();
        SailConnection sc = null;
        try {
            sc = _sail.getConnection();
        } catch (SailException e) {
            _logger.error("Failed to open sail connection in order to compute cached information", e);
        } catch (Exception e) {
        } finally {
        }
        if (sc != null) {
            try {
                internalBuildPropertyRecords(sc);
                internalBuildTypeRecords(sc);
            } finally {
                try {
                    sc.close();
                } catch (SailException e) {
                    _logger.warn("Failed to close sail connection", e);
                }
            }
        }
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException) SailException(org.openrdf.sail.SailException) OpenRDFException(org.openrdf.OpenRDFException)

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