1 16 17 package org.springframework.transaction.support; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 34 public abstract class TransactionSynchronizationUtils { 35 36 private static final Log logger = LogFactory.getLog(TransactionSynchronizationUtils.class); 37 38 39 45 public static void triggerBeforeCommit(boolean readOnly) { 46 for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) { 47 TransactionSynchronization synchronization = (TransactionSynchronization) it.next(); 48 synchronization.beforeCommit(readOnly); 49 } 50 } 51 52 56 public static void triggerBeforeCompletion() { 57 for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) { 58 TransactionSynchronization synchronization = (TransactionSynchronization) it.next(); 59 try { 60 synchronization.beforeCompletion(); 61 } 62 catch (Throwable tsex) { 63 logger.error("TransactionSynchronization.beforeCompletion threw exception", tsex); 64 } 65 } 66 } 67 68 74 public static void triggerAfterCommit() { 75 List synchronizations = TransactionSynchronizationManager.getSynchronizations(); 76 invokeAfterCommit(synchronizations); 77 } 78 79 85 public static void invokeAfterCommit(List synchronizations) { 86 if (synchronizations != null) { 87 for (Iterator it = synchronizations.iterator(); it.hasNext();) { 88 TransactionSynchronization synchronization = (TransactionSynchronization) it.next(); 89 try { 90 synchronization.afterCommit(); 91 } 92 catch (AbstractMethodError tserr) { 93 if (logger.isDebugEnabled()) { 94 logger.debug("Spring 2.0's TransactionSynchronization.afterCommit method not implemented in " + 95 "synchronization class [" + synchronization.getClass().getName() + "]", tserr); 96 } 97 } 98 } 99 } 100 } 101 102 112 public static void triggerAfterCompletion(int completionStatus) { 113 List synchronizations = TransactionSynchronizationManager.getSynchronizations(); 114 invokeAfterCompletion(synchronizations, completionStatus); 115 } 116 117 128 public static void invokeAfterCompletion(List synchronizations, int completionStatus) { 129 if (synchronizations != null) { 130 for (Iterator it = synchronizations.iterator(); it.hasNext();) { 131 TransactionSynchronization synchronization = (TransactionSynchronization) it.next(); 132 try { 133 synchronization.afterCompletion(completionStatus); 134 } 135 catch (Throwable tsex) { 136 logger.error("TransactionSynchronization.afterCompletion threw exception", tsex); 137 } 138 } 139 } 140 } 141 142 } 143 | Popular Tags |