Search in sources :

Example 1 with TransactionHandler

use of org.apache.jena.graph.TransactionHandler in project jena by apache.

the class TransactionHandlerContractTest method testTransactionsExistAsPerTransactionSupported.

/**
	 * Test that Graphs have transaction support methods, and that if they fail
	 * on some g they fail because they do not support the operation.
	 */
@SuppressWarnings("deprecation")
@ContractTest
public void testTransactionsExistAsPerTransactionSupported() {
    // Write out explicitly
    Command cmd = new Command() {

        @Override
        public Object execute() {
            return null;
        }
    };
    TransactionHandler th = getTransactionHandlerProducer().newInstance();
    if (th.transactionsSupported()) {
        th.begin();
        th.abort();
        th.begin();
        th.commit();
        th.execute(() -> {
        });
        th.calculate(() -> null);
        th.executeInTransaction(cmd);
        th.executeInTransaction(() -> null);
    } else {
        try {
            th.begin();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.abort();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.commit();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        /* */
        try {
            th.execute(() -> {
            });
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.calculate(() -> null);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.executeInTransaction(cmd);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.executeInTransaction(() -> null);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
    }
}
Also used : Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) ContractTest(org.xenei.junit.contract.ContractTest)

Example 2 with TransactionHandler

use of org.apache.jena.graph.TransactionHandler in project jena by apache.

the class TestSpecials method zero_graph_txn_5.

@Test(expected = JenaException.class)
public void zero_graph_txn_5() {
    DatasetGraph dsg = DatasetGraphZero.create();
    Graph g = dsg.getDefaultGraph();
    TransactionHandler h = g.getTransactionHandler();
    h.commit();
}
Also used : Graph(org.apache.jena.graph.Graph) TransactionHandler(org.apache.jena.graph.TransactionHandler) Test(org.junit.Test)

Example 3 with TransactionHandler

use of org.apache.jena.graph.TransactionHandler in project jena by apache.

the class TransactionHandlerContractTest method testExecuteInTransactionCatchesThrowable.

@SuppressWarnings("deprecation")
@ContractTest
public void testExecuteInTransactionCatchesThrowable() {
    TransactionHandler th = getTransactionHandlerProducer().newInstance();
    if (th.transactionsSupported()) {
        Command cmd = new Command() {

            @Override
            public Object execute() throws Error {
                throw new Error();
            }
        };
        try {
            th.executeInTransaction(cmd);
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.execute(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.calculate(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) ContractTest(org.xenei.junit.contract.ContractTest)

Example 4 with TransactionHandler

use of org.apache.jena.graph.TransactionHandler in project jena by apache.

the class TxnDataset2Graph method addHandler.

private static void addHandler(Map<Object, TransactionHandler> handlers, Graph graph) {
    TransactionHandler th = graph.getTransactionHandler();
    if (!th.transactionsSupported())
        return;
    Object key = calcKey(graph);
    if (th.transactionsSupported())
        handlers.put(key, th);
}
Also used : TransactionHandler(org.apache.jena.graph.TransactionHandler)

Example 5 with TransactionHandler

use of org.apache.jena.graph.TransactionHandler in project jena by apache.

the class TestSpecials method zero_graph_txn_3.

@Test(expected = JenaException.class)
public void zero_graph_txn_3() {
    DatasetGraph dsg = DatasetGraphZero.create();
    Graph g = dsg.getDefaultGraph();
    TransactionHandler h = g.getTransactionHandler();
    h.begin();
    h.begin();
}
Also used : Graph(org.apache.jena.graph.Graph) TransactionHandler(org.apache.jena.graph.TransactionHandler) Test(org.junit.Test)

Aggregations

TransactionHandler (org.apache.jena.graph.TransactionHandler)11 Graph (org.apache.jena.graph.Graph)8 Test (org.junit.Test)8 Command (org.apache.jena.shared.Command)2 ContractTest (org.xenei.junit.contract.ContractTest)2 JenaException (org.apache.jena.shared.JenaException)1