Search in sources :

Example 11 with SailConnection

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

the class SailTest method testGetStatementsS_POG.

// statement manipulation //////////////////////////////////////////////////
@Test
public void testGetStatementsS_POG() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        URI uriA = sail.getValueFactory().createURI("http://example.org/test/S_POG#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/S_POG#b");
        URI uriC = sail.getValueFactory().createURI("http://example.org/test/S_POG#c");
        URI uriD = sail.getValueFactory().createURI("http://example.org/test/S_POG#d");
        int before, after;
        // default context, different S,P,O
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        before = countStatements(sc, uriA, null, null, false);
        sc.addStatement(uriA, uriB, uriC);
        sc.commit();
        sc.begin();
        after = countStatements(sc, uriA, null, null, false);
        assertEquals(0, before);
        System.out.flush();
        assertEquals(1, after);
        // one specific context, different S,P,O
        sc.removeStatements(uriA, null, null, uriD);
        sc.commit();
        sc.begin();
        before = countStatements(sc, uriA, null, null, false, uriD);
        sc.addStatement(uriA, uriB, uriC, uriD);
        sc.commit();
        sc.begin();
        after = countStatements(sc, uriA, null, null, false, uriD);
        assertEquals(0, before);
        assertEquals(1, after);
        // one specific context, same S,P,O,G
        sc.removeStatements(uriA, null, null, uriA);
        sc.commit();
        sc.begin();
        before = countStatements(sc, uriA, null, null, false, uriA);
        sc.addStatement(uriA, uriB, uriC, uriA);
        sc.commit();
        sc.begin();
        after = countStatements(sc, uriA, null, null, false, uriA);
        assertEquals(0, before);
        assertEquals(1, after);
        // default context, same S,P,O
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        before = countStatements(sc, uriA, null, null, false);
        sc.addStatement(uriA, uriB, uriC);
        sc.commit();
        sc.begin();
        after = countStatements(sc, uriA, null, 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 12 with SailConnection

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

the class SailTest method testSailChangedListeners.

@Test
public void testSailChangedListeners() throws Exception {
    if (sail instanceof NotifyingSail) {
        final Collection<SailChangedEvent> events = new LinkedList<SailChangedEvent>();
        SailChangedListener listener = new SailChangedListener() {

            public void sailChanged(final SailChangedEvent event) {
                events.add(event);
            }
        };
        ((NotifyingSail) sail).addSailChangedListener(listener);
        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");
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            sc.clear();
            sc.commit();
            sc.begin();
            events.clear();
            assertEquals(0, events.size());
            sc.addStatement(uriA, uriB, uriC, uriA);
            sc.addStatement(uriB, uriC, uriA, uriA);
            // Events are buffered until the commit
            assertEquals(0, events.size());
            sc.commit();
            sc.begin();
            // Only one SailChangedEvent per commit
            assertEquals(1, events.size());
            SailChangedEvent event = events.iterator().next();
            assertTrue(event.statementsAdded());
            assertFalse(event.statementsRemoved());
            events.clear();
            assertEquals(0, events.size());
            sc.removeStatements(uriA, uriB, uriC, uriA);
            sc.commit();
            sc.begin();
            assertEquals(1, events.size());
            event = events.iterator().next();
            assertFalse(event.statementsAdded());
            assertTrue(event.statementsRemoved());
            events.clear();
            assertEquals(0, events.size());
            sc.clear();
            sc.commit();
            sc.begin();
            assertEquals(1, events.size());
            event = events.iterator().next();
            assertFalse(event.statementsAdded());
            assertTrue(event.statementsRemoved());
        } finally {
            sc.rollback();
            sc.close();
        }
    }
}
Also used : NotifyingSail(org.openrdf.sail.NotifyingSail) SailChangedEvent(org.openrdf.sail.SailChangedEvent) NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) SailChangedListener(org.openrdf.sail.SailChangedListener) URI(org.openrdf.model.URI) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with SailConnection

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

the class SailTest method testNullContext.

/*
    // TODO: restore me... but only for ACID-compliant stores
    @Ignore
    @Test
    public void testVisibilityOfChanges() throws Exception {
        SailConnection sc1, sc2;
        int count;
        URI uriA = sail.getValueFactory().createURI(
                "http://example.org/test/visibilityOfChanges#a");
        sc1 = sail.getConnection();
        sc2 = sail.getConnection();
        try {
            sc1.clear();
            sc2.clear();

            // Statement doesn't exist for either connection.
            count = countStatements(sc1, uriA, null, null);
            assertEquals(0, count);
            count = countStatements(sc2, uriA, null, null);
            assertEquals(0, count);
            // First connection adds a statement. It is visible to the first
            // connection, but not to the second.
            sc1.addStatement(uriA, uriA, uriA);
            count = countStatements(sc1, null, null, null);
            assertEquals(1, count);
            count = countStatements(sc2, uriA, null, null);
            assertEquals(0, count);
            // ...
        }
        finally {
            sc2.close();
            sc1.close();
        }
    }
    */
@Test
public void testNullContext() throws Exception {
    URI uriA = sail.getValueFactory().createURI("http://example.org/test/nullContext#a");
    URI uriB = sail.getValueFactory().createURI("http://example.org/test/nullContext#b");
    URI uriC = sail.getValueFactory().createURI("http://example.org/test/nullContext#c");
    int count = 0;
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.addStatement(uriA, uriB, uriC);
        Statement statement = sc.getStatements(uriA, uriB, uriC, false, new Resource[] { null }).next();
        Resource context = statement.getContext();
        assertNull(context);
        sc.removeStatements(uriA, null, null);
        sc.commit();
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 14 with SailConnection

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

the class SailTest method testGetStatementsO_SPG.

@Test
public void testGetStatementsO_SPG() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        URI uriA = sail.getValueFactory().createURI("http://example.org/test/O_SPG#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/O_SPG#b");
        URI uriC = sail.getValueFactory().createURI("http://example.org/test/O_SPG#c");
        Literal plainLitA = sail.getValueFactory().createLiteral("arbitrary plain literal 9548734867");
        Literal stringLitA = sail.getValueFactory().createLiteral("arbitrary string literal 8765", XMLSchema.STRING);
        int before, after;
        // Add statement to a specific context.
        sc.removeStatements(null, null, uriA, uriA);
        sc.commit();
        sc.begin();
        before = countStatements(sc, null, null, uriA, false);
        sc.addStatement(uriB, uriC, uriA);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, null, uriA, 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, null, plainLitA, false);
        sc.addStatement(uriA, uriA, plainLitA);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, null, plainLitA, false);
        assertEquals(0, before);
        assertEquals(1, after);
        // Add string-typed literal statement to the default context.
        sc.removeStatements(null, null, plainLitA);
        sc.commit();
        sc.begin();
        before = countStatements(sc, null, null, stringLitA, false);
        sc.addStatement(uriA, uriA, stringLitA);
        sc.commit();
        sc.begin();
        after = countStatements(sc, null, null, stringLitA, false);
        assertEquals(0, before);
        assertEquals(1, after);
    } 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 15 with SailConnection

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

the class SailTest method testRemoveStatements.

@Test
public void testRemoveStatements() 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");
        Resource[] contexts = { uriA, null };
        int count;
        // Remove from all contexts.
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.addStatement(uriA, uriB, uriC, contexts);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(2, count);
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        // Remove from one partition context.
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.addStatement(uriA, uriB, uriC, contexts);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(2, count);
        Resource[] oneContext = { uriA };
        sc.removeStatements(uriA, null, null, oneContext);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(1, count);
        // Remove from the null context.
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.addStatement(uriA, uriB, uriC, contexts);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(2, count);
        Resource[] nullContext = { null };
        sc.removeStatements(uriA, null, null, nullContext);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(1, count);
        // Remove from more than one context.
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(0, count);
        sc.addStatement(uriA, uriB, uriC, contexts);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false);
        assertEquals(2, count);
        sc.removeStatements(uriA, null, null);
        sc.commit();
        sc.begin();
        count = countStatements(sc, uriA, null, null, false, contexts);
        assertEquals(0, 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)

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