Search in sources :

Example 6 with SailConnection

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

the class SailTest method testPersistentCommits.

// connections and transactions ////////////////////////////////////////////
@Test
public void testPersistentCommits() throws Exception {
    SailConnection sc;
    int count;
    URI uriA = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#a");
    URI uriB = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#b");
    URI uriC = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#c");
    sc = sail.getConnection();
    try {
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.rollback();
        sc.close();
        sc = sail.getConnection();
        sc.begin();
        sc.addStatement(uriA, uriB, uriC);
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(1, count);
        sc.commit();
        sc.close();
        sc = sail.getConnection();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(1, count);
        sc.rollback();
        sc.close();
        sc = sail.getConnection();
        sc.begin();
        sc.removeStatements(uriA, null, null);
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.commit();
        sc.close();
        sc = sail.getConnection();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 7 with SailConnection

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

the class SailTest method testGetStatementsPO_SG.

@Test
public void testGetStatementsPO_SG() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        URI uriA = sail.getValueFactory().createURI("http://example.org/test/PO_SG#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/PO_SG#b");
        URI foo = sail.getValueFactory().createURI("http://example.org/ns#foo");
        URI firstName = sail.getValueFactory().createURI("http://example.org/ns#firstName");
        Literal plainLitA = sail.getValueFactory().createLiteral("arbitrary plain literal 8765675");
        Literal fooLabel = sail.getValueFactory().createLiteral("foo", XMLSchema.STRING);
        int before, after;
        // Add statement to the implicit null context.
        sc.removeStatements(null, null, null, uriA);
        sc.commit();
        sc.begin();
        before = countStatements(sc, null, uriA, uriB, false);
        sc.addStatement(uriA, uriA, uriB);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, uriA, uriB, false);
        assertEquals(0, before);
        assertEquals(1, after);
        // Add plain literal statement to the default context.
        sc.removeStatements(null, null, plainLitA);
        sc.commit();
        sc.begin();
        before = countStatements(sc, null, uriA, plainLitA, false);
        sc.addStatement(uriA, uriA, plainLitA);
        sc.addStatement(uriA, uriB, plainLitA);
        sc.addStatement(uriB, uriB, plainLitA);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, uriA, plainLitA, false);
        assertEquals(0, before);
        assertEquals(1, after);
        // Add string-typed literal statement to the default context.
        sc.removeStatements(null, null, fooLabel);
        sc.commit();
        sc.begin();
        before = countStatements(sc, null, firstName, fooLabel, false);
        sc.addStatement(foo, firstName, fooLabel);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, firstName, fooLabel, false);
        assertEquals(0, before);
        assertEquals(1, after);
        assertEquals(foo, toSet(sc.getStatements(null, firstName, fooLabel, false)).iterator().next().getSubject());
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Literal(org.openrdf.model.Literal) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 8 with SailConnection

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

the class SailTest method testGetStatementsWithVariableContexts.

@Test
public void testGetStatementsWithVariableContexts() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        URI uriA = sail.getValueFactory().createURI("http://example.org/uriA");
        URI uriB = sail.getValueFactory().createURI("http://example.org/uriB");
        URI uriC = sail.getValueFactory().createURI("http://example.org/uriC");
        int count;
        sc.clear();
        //sc.removeStatements(uriA, uriA, uriA);
        sc.commit();
        sc.begin();
        Resource[] contexts = { uriA, null };
        sc.addStatement(uriA, uriB, uriC, contexts);
        sc.commit();
        sc.begin();
        // Get statements from all contexts.
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(2, count);
        // Get statements from a specific partition context.
        count = countStatements(sc, null, null, null, false, uriA);
        assertEquals(1, count);
        // Get statements from the null context.
        Resource[] c = { null };
        count = countStatements(sc, null, null, null, false, c);
        //assertTrue(count > 0);
        assertEquals(1, count);
        int countLast = count;
        // Get statements from more than one context.
        count = countStatements(sc, null, null, null, false, contexts);
        assertEquals(1 + countLast, count);
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 9 with SailConnection

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

the class SailTest method testGetStatementsSP_OG.

@Test
public void testGetStatementsSP_OG() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        URI uriA = sail.getValueFactory().createURI("http://example.org/test/SP_OG#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/SP_OG#b");
        URI uriC = sail.getValueFactory().createURI("http://example.org/test/SP_OG#c");
        int before, after;
        // Add statement to the implicit null context.
        sc.removeStatements(null, null, null);
        before = countStatements(sc, uriA, uriB, null, false);
        sc.addStatement(uriA, uriB, uriC);
        sc.commit();
        sc.begin();
        after = countStatements(sc, uriA, uriB, null, false);
        assertEquals(0, before);
        assertEquals(1, after);
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 10 with SailConnection

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

the class SailTest method testRemoveNamespace.

@Test
public void testRemoveNamespace() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        String prefix = "foo";
        String emptyPrefix = "";
        String name = "http://example.org/foo";
        // Set namespace initially.
        sc.setNamespace(prefix, name);
        sc.commit();
        sc.begin();
        assertEquals(sc.getNamespace(prefix), name);
        // Remove the namespace and make sure it's gone.
        sc.removeNamespace(prefix);
        sc.commit();
        sc.begin();
        assertNull(sc.getNamespace(prefix));
        // Same thing for the default namespace.
        sc.setNamespace(emptyPrefix, name);
        sc.commit();
        sc.begin();
        assertEquals(sc.getNamespace(emptyPrefix), name);
        sc.removeNamespace(emptyPrefix);
        sc.commit();
        sc.begin();
        assertNull(sc.getNamespace(emptyPrefix));
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Test(org.junit.Test)

Aggregations

SailConnection (org.openrdf.sail.SailConnection)55 Test (org.junit.Test)34 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)28 URI (org.openrdf.model.URI)25 SailException (org.openrdf.sail.SailException)14 Sail (org.openrdf.sail.Sail)10 ValueFactory (org.openrdf.model.ValueFactory)9 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)8 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)5 RyaClient (org.apache.rya.api.client.RyaClient)5 Literal (org.openrdf.model.Literal)5 Resource (org.openrdf.model.Resource)5 Statement (org.openrdf.model.Statement)5 ParsedQuery (org.openrdf.query.parser.ParsedQuery)5 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)5 URIImpl (org.openrdf.model.impl.URIImpl)4 BindingSet (org.openrdf.query.BindingSet)4 Vertex (com.tinkerpop.blueprints.Vertex)3 EmptyBindingSet (org.openrdf.query.impl.EmptyBindingSet)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3