Polishing
This commit is contained in:
@@ -51,19 +51,21 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
|
||||
private final TransactionalEventListener annotation;
|
||||
|
||||
|
||||
public ApplicationListenerMethodTransactionalAdapter(String beanName, Class<?> targetClass, Method method) {
|
||||
super(beanName, targetClass, method);
|
||||
this.annotation = findAnnotation(method);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronization transactionSynchronization = createTransactionSynchronization(event);
|
||||
TransactionSynchronizationManager.registerSynchronization(transactionSynchronization);
|
||||
}
|
||||
else if (annotation.fallbackExecution()) {
|
||||
if (annotation.phase() == TransactionPhase.AFTER_ROLLBACK) {
|
||||
else if (this.annotation.fallbackExecution()) {
|
||||
if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK) {
|
||||
logger.warn("Processing '" + event + "' as a fallback execution on AFTER_ROLLBACK phase.");
|
||||
}
|
||||
processEvent(event);
|
||||
@@ -80,8 +82,8 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
}
|
||||
|
||||
static TransactionalEventListener findAnnotation(Method method) {
|
||||
TransactionalEventListener annotation = AnnotatedElementUtils
|
||||
.findMergedAnnotation(method, TransactionalEventListener.class);
|
||||
TransactionalEventListener annotation =
|
||||
AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class);
|
||||
if (annotation == null) {
|
||||
throw new IllegalStateException("No TransactionalEventListener annotation found on '" + method + "'");
|
||||
}
|
||||
@@ -97,7 +99,7 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
|
||||
private final TransactionPhase phase;
|
||||
|
||||
protected TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
|
||||
public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
|
||||
ApplicationEvent event, TransactionPhase phase) {
|
||||
|
||||
this.listener = listener;
|
||||
@@ -107,20 +109,20 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
|
||||
@Override
|
||||
public void beforeCommit(boolean readOnly) {
|
||||
if (phase == TransactionPhase.BEFORE_COMMIT) {
|
||||
if (this.phase == TransactionPhase.BEFORE_COMMIT) {
|
||||
processEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(int status) {
|
||||
if (phase == TransactionPhase.AFTER_COMPLETION) {
|
||||
if (this.phase == TransactionPhase.AFTER_COMPLETION) {
|
||||
processEvent();
|
||||
}
|
||||
else if (phase == TransactionPhase.AFTER_COMMIT && status == STATUS_COMMITTED) {
|
||||
else if (this.phase == TransactionPhase.AFTER_COMMIT && status == STATUS_COMMITTED) {
|
||||
processEvent();
|
||||
}
|
||||
else if (phase == TransactionPhase.AFTER_ROLLBACK && status == STATUS_ROLLED_BACK) {
|
||||
else if (this.phase == TransactionPhase.AFTER_ROLLBACK && status == STATUS_ROLLED_BACK) {
|
||||
processEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,18 +34,20 @@ public class TransactionalEventListenerFactory implements EventListenerFactory,
|
||||
|
||||
private int order = 50;
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsMethod(Method method) {
|
||||
return AnnotationUtils.findAnnotation(method, TransactionalEventListener.class) != null;
|
||||
return (AnnotationUtils.findAnnotation(method, TransactionalEventListener.class) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user