com.gruelbox.transactionoutbox.StubThreadLocalTransactionManager Maven / Gradle / Ivy
package com.gruelbox.transactionoutbox;
import java.sql.Connection;
import lombok.extern.slf4j.Slf4j;
/**
* A stub transaction manager that assumes no underlying database and thread local transaction
* management.
*/
@Slf4j
public class StubThreadLocalTransactionManager
extends AbstractThreadLocalTransactionManager {
@Beta
public StubThreadLocalTransactionManager() {
// Nothing to do
}
@Override
public T inTransactionReturnsThrows(
ThrowingTransactionalSupplier work) throws E {
return withTransaction(
atx -> {
T result = work.doWork(atx);
((SimpleTransaction) atx).processHooks();
return result;
});
}
private T withTransaction(ThrowingTransactionalSupplier work)
throws E {
Connection mockConnection = Utils.createLoggingProxy(new ProxyFactory(), Connection.class);
try (SimpleTransaction transaction =
pushTransaction(new SimpleTransaction(mockConnection, null))) {
return work.doWork(transaction);
} finally {
popTransaction();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy