/** Test that Graphs have transaction support methods, and that if they fail on some g they fail because they do not support the operation. */ public void testHasTransactions() { Graph g = getGraph(); TransactionHandler th = g.getTransactionHandler(); th.transactionsSupported(); try { th.begin(); } catch (UnsupportedOperationException x) {} try { th.abort(); } catch (UnsupportedOperationException x) {} try { th.begin(); th.commit(); } catch (UnsupportedOperationException x) {} /* */ Command cmd = new Command() { @Override public Object execute() { return null; } }; try { th.execute( ()->{} ); } catch (UnsupportedOperationException x) {} }
/** * Execute the supplier <code>action</code> within a transaction. If it completes normally, * commit the transaction and return the result, otherwise abort the transaction. */ @Override public <T> T calculateInTxn( Supplier<T> action ) { return getTransactionHandler().calculate( action ); }
@SuppressWarnings("deprecation") @Override public Object executeInTransaction( Command cmd ) { return getTransactionHandler().executeInTransaction( cmd ); }
private void beginTransaction(SDBConnection sdbConn) { if (sdbConn.getTransactionHandler().transactionsSupported()) { sdbConn.getTransactionHandler().begin(); } }
private void abortTransaction(SDBConnection sdbConn) { if (sdbConn.getTransactionHandler().transactionsSupported()) { sdbConn.getTransactionHandler().abort(); } }
private void commitTransaction(SDBConnection sdbConn) { if (sdbConn.getTransactionHandler().transactionsSupported()) { sdbConn.getTransactionHandler().commit(); } }
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) { th.abort(); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { th.commit(); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { th.execute(()->{}); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { } try { th.calculate(()->null); fail("Should have thrown UnsupportedOperationException");
@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) { } } }
public void testExecuteInTransactionCatchesThrowable() { Graph g = getGraph(); TransactionHandler th = g.getTransactionHandler(); if (th.transactionsSupported()) { try { th.execute( ()-> { throw new Error() ; } ); } catch (JenaException x) {} } }
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) ; }
@Override public void executeInTxn( Runnable action ) { getTransactionHandler().execute( action ); }
@Override public Model begin() { getTransactionHandler().begin(); return this; }
@Override public void commit() { getBaseHandler().commit(); } }
@Override public Model abort() { getTransactionHandler().abort(); return this; }
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) { th.abort(); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { th.commit(); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { th.execute(()->{}); fail("Should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException x) { } try { th.calculate(()->null); fail("Should have thrown UnsupportedOperationException");
@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) { } } }
public void testExecuteInTransactionCatchesThrowable() { Graph g = getGraph(); TransactionHandler th = g.getTransactionHandler(); if (th.transactionsSupported()) { try { th.execute( ()-> { throw new Error() ; } ); } catch (JenaException x) {} } }