@Override
    public void begin() {
        if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
            connection.getConnectionSession().getTransactionStatus().setInTransaction(true);
            getTransactionContext().beginTransaction(String.valueOf(transactionType));
            connection.closeHandlers(true);
            connection.closeConnections(false);
        }
        for (TransactionHook each : transactionHooks) {
            each.beforeBegin(getTransactionContext());
        }
        if (TransactionType.LOCAL == transactionType || null == distributionTransactionManager) {
            localTransactionManager.begin();
        } else {
            distributionTransactionManager.begin();
        }
        for (TransactionHook each : transactionHooks) {
            each.afterBegin(getTransactionContext());
        }
    }
@Test
    void assertBeginForDistributedTransaction() {
        ContextManager contextManager = mockContextManager(TransactionType.XA);
        when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
        newBackendTransactionManager(TransactionType.XA, true);
        backendTransactionManager.begin();
        verify(transactionStatus, times(0)).setInTransaction(true);
        verify(databaseConnectionManager, times(0)).closeConnections(false);
        verify(distributionTransactionManager).begin();
    }