1 22 package org.jboss.test.dtm.ejb; 23 24 import javax.ejb.SessionSynchronization ; 25 26 import org.jboss.logging.Logger; 27 import org.jboss.test.util.ejb.SessionSupport; 28 29 30 36 public class AccountSessionBean 37 extends SessionSupport 38 implements SessionSynchronization 39 { 40 private static transient Logger log = 41 Logger.getLogger(AccountSessionBean.class); 42 43 private transient int balanceAtTxStart; 44 private String testName; 45 private int balance; 46 47 public void ejbCreate(String name, int initialBalance) 48 { 49 this.testName = name; 50 this.balance = initialBalance; 51 log = Logger.getLogger(AccountSessionBean.class.getName() + 52 "#" + testName); 53 log.debug("ejbCreate(" + name + ", " + initialBalance + 54 "), ctx=" + sessionCtx); 55 } 56 57 public void afterBegin() 58 { 59 log.debug("afterBegin()..., balance=" + balance); 60 balanceAtTxStart = balance; 61 } 62 public void afterCompletion(boolean isCommited) 63 { 64 log.debug("afterCompletion(), isCommited=" + isCommited + ", balance=" + 65 balance + ", balanceAtTxStart=" + balanceAtTxStart); 66 if( isCommited == false ) 67 { 68 balance = balanceAtTxStart; 69 log.debug("Rolling balance back to: " + balance); 70 } 71 else 72 { 73 log.debug("Committed updated balance: " + balance); 74 } 75 } 76 public void beforeCompletion() 77 { 78 log.debug("beforeCompletion(), balance=" + balance + 79 ", balanceAtTxStart=" + balanceAtTxStart); 80 } 81 82 public int getBalance() 83 { 84 return balance; 85 } 86 87 public void setBalance(int balance) 88 { 89 this.balance = balance; 90 } 91 92 public void addToBalance(int delta) 93 { 94 balance += delta; 95 } 96 97 public void setRollbackOnly() 98 { 99 sessionCtx.setRollbackOnly(); 100 } 101 102 } 103 | Popular Tags |