@Test void testConnectionCommittedWhenTransactionScopeInsideUnitOfWork() throws Exception { doAnswer(invocation -> { final Object spy = spy(invocation.callRealMethod()); mockConnection = (Connection) spy; return spy; }).when(dataSource).getConnection(); UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(null); Transaction transaction = springTransactionManager.startTransaction(); uow.onCommit(u -> transaction.commit()); uow.onRollback(u -> transaction.rollback()); Connection innerConnection = connectionProvider.getConnection(); assertNotSame(innerConnection, mockConnection); innerConnection.commit(); verify(mockConnection, never()).commit(); uow.commit(); verify(mockConnection).commit(); }
@Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); }
SpringDataSourceConnectionProvider implements ConnectionProvider { @Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); } }
SpringDataSourceConnectionProvider implements ConnectionProvider { @Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); } SpringDataSourceConnectionProvider(DataSource dataSource); }
SpringDataSourceConnectionProvider implements ConnectionProvider { @Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); } SpringDataSourceConnectionProvider(DataSource dataSource); @Override Connection getConnection(); }
SpringDataSourceConnectionProvider implements ConnectionProvider { @Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); } SpringDataSourceConnectionProvider(DataSource dataSource); @Override Connection getConnection();  }