BackendTransactionManager implements TransactionManager { @Override public void commit() throws SQLException { if (connection.getTransactionStatus().isInTransaction()) { try { if (TransactionType.LOCAL == transactionType || null == shardingTransactionManager) { localTransactionManager.commit(); } else { shardingTransactionManager.commit(); } } finally { connection.getTransactionStatus().setInTransaction(false); } } } BackendTransactionManager(final BackendConnection backendConnection); @Override void begin(); @Override void commit(); @Override void rollback();  }
@Test public void assertCommitForLocalTransaction() throws SQLException { newBackendTransactionManager(TransactionType.LOCAL, true); backendTransactionManager.commit(); verify(transactionStatus).setInTransaction(false); verify(localTransactionManager).commit(); }
@Test public void assertCommitForDistributedTransaction() throws SQLException { newBackendTransactionManager(TransactionType.XA, true); backendTransactionManager.commit(); verify(transactionStatus).setInTransaction(false); verify(shardingTransactionManager).commit(); }
@Test public void assertCommitWithoutTransaction() throws SQLException { newBackendTransactionManager(TransactionType.LOCAL, false); backendTransactionManager.commit(); verify(transactionStatus, times(0)).setInTransaction(false); verify(localTransactionManager, times(0)).commit(); verify(shardingTransactionManager, times(0)).commit(); }