@Override
    public synchronized void close() throws SQLException {
        rollBacked = false;
        if (isHeld() && shouldBeHeld()) {
            // if kept by a keeper, just hold the connection.
            return;
        }
        cleanXABranchContext();
        originalConnection.close();
    }
@Test
    public void testClose() throws Throwable {
        Connection connection = Mockito.mock(Connection.class);
        Mockito.when(connection.getAutoCommit()).thenReturn(true);

        XAConnection xaConnection = Mockito.mock(XAConnection.class);
        BaseDataSourceResource<ConnectionProxyXA> baseDataSourceResource = Mockito.mock(BaseDataSourceResource.class);
        String xid = "xxx";

        ConnectionProxyXA connectionProxyXA1 = new ConnectionProxyXA(connection, xaConnection, baseDataSourceResource, xid);
        connectionProxyXA1.init();
        // Kept
        connectionProxyXA1.setHeld(true);
        // call close on proxy
        connectionProxyXA1.close();
        // Assert the original connection was NOT closed
        Mockito.verify(connection, times(0)).close();

        ConnectionProxyXA connectionProxyXA2 = new ConnectionProxyXA(connection, xaConnection, baseDataSourceResource, xid);
        connectionProxyXA2.init();
        // Kept
        connectionProxyXA2.setHeld(false);
        // call close on proxy
        connectionProxyXA2.close();
        // Assert the original connection was ALSO closed
        Mockito.verify(connection).close();
    }