
com.gruelbox.transactionoutbox.StubThreadLocalTransactionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of transactionoutbox-core Show documentation
Show all versions of transactionoutbox-core Show documentation
A safe implementation of the transactional outbox pattern for Java (core library)
package com.gruelbox.transactionoutbox;
import com.gruelbox.transactionoutbox.spi.AbstractThreadLocalTransactionManager;
import com.gruelbox.transactionoutbox.spi.ProxyFactory;
import com.gruelbox.transactionoutbox.spi.SimpleTransaction;
import com.gruelbox.transactionoutbox.spi.Utils;
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 {
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