Hi all,

I have a question regarding support of transaction when using the Sesame 2
driver on top of 5.0.7. I have a test case which tries to add a statement
and then attempt a rollback. The statement still exist after the rollback. I
have attached a test case to see whether anyone can shed some light on the
transaction support.

Cheers,

Will

package virtuoso.test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Test;
import org.openrdf.model.URI;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;

import virtuoso.sesame2.driver.VirtuosoRepository;

public class TransactionTestCase {

    @Test
    public void testTransaction() throws Exception {

        Repository repository = null;
        RepositoryConnection connection = null;
        try {
            repository = new
VirtuosoRepository("jdbc:virtuoso://localhost:1111", "xxx", "xxx");
            repository.initialize();
            connection = repository.getConnection();

            // disable auto-commit to start a transaction.
            connection.setAutoCommit(false);

            URI subject = repository.getValueFactory().createURI("urn:s");
            URI predicate = repository.getValueFactory().createURI("urn:p");
            URI object = repository.getValueFactory().createURI("urn:o");
            URI context = repository.getValueFactory().createURI("urn:c");

            // The triple should be non-existent before add.
            connection.clear(context);
            assertThat(connection.getStatements(subject, predicate, object,
false, context).hasNext(), equalTo(false));

            // 1. add the triple.
            connection.add(subject, predicate, object, context);

            // 2. test if the triple now exist.
            assertThat(connection.getStatements(subject, predicate, object,
false, context).hasNext(), equalTo(true));

            // 3. force a rollback
            connection.rollback();

            // 4. make sure the triple still exist after the commit.
            assertThat(connection.getStatements(subject, predicate, object,
false, context).hasNext(), equalTo(false));
        } catch (Exception e) {
            fail("not expecting an exception");
        } finally {
            if (connection != null) {
                connection.close();
            }
            if (repository != null) {
                repository.shutDown();
            }
        }

    }
}

Reply via email to