private void rollback(Transaction tx) { try { tx.failure(); tx.close(); } finally { tx = null; closeSession(); } }
private void commit(Transaction tx) { try { tx.success(); tx.close(); } finally { tx = null; closeSession(); } }
@Override public void success() { if ( tx != null ) { try { tx.success(); tx.close(); } finally { tx = null; closeSession(); } } }
@Override public void failure() { if ( tx != null ) { try { tx.failure(); tx.close(); } finally { tx = null; closeSession(); } } }
@Override public void close() { try { entities.close(); if ( closeTransaction ) { tx.success(); } } finally { if ( closeTransaction ) { tx.close(); } } } }
@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(); } }
if (btx == null && tx != null) { try { tx.close(); } catch(Throwable e1) { dbException = e1;
if (btx == null && tx != null) { try { tx.close(); } catch(Throwable e1) { dbException = e1;
tx.close(); } catch(Throwable e) { dbException = e;
tx.close(); } catch(Throwable e) { dbException = e;
@Test public void rollbackShouldCloseSessionWhenTransactionCloseThrows() { Transaction nativeTx = openTransactionMock(); doThrow(new RuntimeException("Close failed")).when(nativeTx).close(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(rollingBackTxManager(), nativeTx, nativeSession, READ_ONLY); try { boltTx.rollback(); fail("Exception expected"); } catch (Exception e) { assertThat(e.getMessage()).isEqualTo("Close failed"); } verify(nativeSession).close(); }
@Test public void commitShouldCloseSessionWhenTransactionCloseThrows() { Transaction nativeTx = openTransactionMock(); doThrow(new RuntimeException("Close failed")).when(nativeTx).close(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(committingTxManager(), nativeTx, nativeSession, READ_ONLY); try { boltTx.commit(); fail("Exception expected"); } catch (Exception e) { assertThat(e.getMessage()).isEqualTo("Close failed"); } verify(nativeSession).close(); }
@Test public void commitShouldCloseTransactionAndSession() { Transaction nativeTx = openTransactionMock(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(committingTxManager(), nativeTx, nativeSession, READ_ONLY); boltTx.commit(); InOrder inOrder = inOrder(nativeSession, nativeTx); inOrder.verify(nativeTx).close(); inOrder.verify(nativeSession).close(); }
@Test public void rollbackShouldCloseSessionWhenTransactionIsClosed() { Transaction nativeTx = closedTransactionMock(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(rollingBackTxManager(), nativeTx, nativeSession, READ_ONLY); boltTx.rollback(); verify(nativeTx, never()).close(); verify(nativeSession).close(); }
@Test public void rollbackShouldCloseTransactionAndSession() { Transaction nativeTx = openTransactionMock(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(rollingBackTxManager(), nativeTx, nativeSession, READ_ONLY); boltTx.rollback(); InOrder inOrder = inOrder(nativeSession, nativeTx); inOrder.verify(nativeTx).close(); inOrder.verify(nativeSession).close(); }
@Test public void commitShouldCloseSessionWhenTransactionIsClosed() { Transaction nativeTx = closedTransactionMock(); Session nativeSession = openSessionMock(); BoltTransaction boltTx = new BoltTransaction(committingTxManager(), nativeTx, nativeSession, READ_ONLY); try { boltTx.commit(); } catch (Exception ignore) { // do not care about exceptions, native session should just get closed at the end } verify(nativeTx, never()).close(); verify(nativeSession).close(); }
@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()); } } }