1 回答
TA贡献1946条经验 获得超3个赞
您可能可以为此使用装饰器模式。实现您自己的PlatformTransactionManager并将您当前的经理作为委托传递给它。在 中getTransaction,如果当前线程不是您所期望的,则抛出异常。
public class MyTransactionManager implements PlatformTransactionManager {
private final PlatformTransactionManager delegate;
public MyTransactionManager(PlatformTransactionManager delegate) {
this.delegate = delegate;
}
@Override
public void commit(TransactionStatus status) {
delegate.commit(status);
}
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) {
if (Thread.getCurrentThread() == /*something*/) {
return delegate.getTransaction(definition);
}
else {
throw new RuntimeException();
}
}
@Override
public void rollback(TransactionStatus status) {
delegate.rollback(status);
}
}
添加回答
举报