1 10 11 package org.mule.transaction; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.config.i18n.Message; 16 import org.mule.config.i18n.Messages; 17 import org.mule.umo.TransactionException; 18 import org.mule.umo.UMOTransaction; 19 20 23 public abstract class AbstractTransaction implements UMOTransaction 24 { 25 26 protected final transient Log logger = LogFactory.getLog(getClass()); 27 28 33 public boolean isRollbackOnly() throws TransactionException 34 { 35 return getStatus() == STATUS_MARKED_ROLLBACK; 36 } 37 38 43 public boolean isBegun() throws TransactionException 44 { 45 int status = getStatus(); 46 return status != STATUS_NO_TRANSACTION && status != STATUS_UNKNOWN; 47 } 48 49 54 public boolean isRolledBack() throws TransactionException 55 { 56 return getStatus() == STATUS_ROLLEDBACK; 57 } 58 59 64 public boolean isCommitted() throws TransactionException 65 { 66 return getStatus() == STATUS_COMMITTED; 67 } 68 69 74 public void begin() throws TransactionException 75 { 76 logger.debug("Beginning transaction"); 77 doBegin(); 78 TransactionCoordination.getInstance().bindTransaction(this); 79 } 80 81 86 public void commit() throws TransactionException 87 { 88 try 89 { 90 logger.debug("Committing transaction"); 91 92 if (isRollbackOnly()) 93 { 94 throw new IllegalTransactionStateException(new Message(Messages.TX_MARKED_FOR_ROLLBACK)); 95 } 96 97 doCommit(); 98 } 99 finally 100 { 101 TransactionCoordination.getInstance().unbindTransaction(this); 102 } 103 } 104 105 110 public void rollback() throws TransactionException 111 { 112 try 113 { 114 logger.debug("Rolling back transaction"); 115 setRollbackOnly(); 116 doRollback(); 117 } 118 finally 119 { 120 TransactionCoordination.getInstance().unbindTransaction(this); 121 } 122 } 123 124 129 protected abstract void doBegin() throws TransactionException; 130 131 136 protected abstract void doCommit() throws TransactionException; 137 138 143 protected abstract void doRollback() throws TransactionException; 144 145 } 146 | Popular Tags |