private static Transaction openTransactionMock() { Transaction tx = mock(Transaction.class); when(tx.isOpen()).thenReturn(true); return tx; }
@Override public void rollback() { try { if (transactionManager.canRollback()) { LOGGER.debug("Rolling back native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.failure(); nativeTransaction.close(); } else { LOGGER.warn("Transaction is already closed"); } closeNativeSessionIfPossible(); } } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.rollback(); } }
@Override public void rollback() { try { if (transactionManager.canRollback()) { LOGGER.debug("Rolling back native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.failure(); nativeTransaction.close(); } else { LOGGER.warn("Transaction is already closed"); } closeNativeSessionIfPossible(); } } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.rollback(); } }
@Before public void setUp() throws Exception { BoltDriver driver = new BoltDriver(nativeDriver); session = new Neo4jSession(new MetaData("org.neo4j.ogm.empty"), driver); when(nativeDriver.session(any(AccessMode.class), anyIterable())).thenReturn(nativeSession); when(nativeSession.beginTransaction().isOpen()).thenReturn(true); when(nativeSession.lastBookmark()).thenReturn("last-bookmark"); }
@Override public void commit() { final boolean canCommit = transactionManager.canCommit(); try { if (canCommit) { LOGGER.debug("Committing native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.success(); nativeTransaction.close(); nativeSession.close(); } else { throw new IllegalStateException("Transaction is already closed"); } } } catch (ClientException ce) { closeNativeSessionIfPossible(); if (ce.code().startsWith(NEO_CLIENT_ERROR_SECURITY)) { throw new ConnectionException("Security Error: " + ce.code() + ", " + ce.getMessage(), ce); } throw new CypherException(ce.code(), ce.getMessage(), ce); } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.commit(); if (canCommit) { transactionManager.bookmark(nativeSession.lastBookmark()); } } }
@Override public void commit() { final boolean canCommit = transactionManager.canCommit(); try { if (canCommit) { LOGGER.debug("Committing native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.success(); nativeTransaction.close(); nativeSession.close(); } else { throw new IllegalStateException("Transaction is already closed"); } } } catch (ClientException ce) { closeNativeSessionIfPossible(); if (ce.code().startsWith(NEO_CLIENT_ERROR_SECURITY)) { throw new ConnectionException("Security Error: " + ce.code() + ", " + ce.getMessage(), ce); } throw new CypherException(ce.code(), ce.getMessage(), ce); } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.commit(); if (canCommit) { transactionManager.bookmark(nativeSession.lastBookmark()); } } }