KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > dtm > ejb > AccountSessionBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.dtm.ejb;
23
24 import javax.ejb.SessionSynchronization JavaDoc;
25
26 import org.jboss.logging.Logger;
27 import org.jboss.test.util.ejb.SessionSupport;
28
29
30 /**
31  * Implementation class for the Account stateful session bean.
32  *
33  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
34  * @version $Revision: 58115 $
35  */

36 public class AccountSessionBean
37    extends SessionSupport
38    implements SessionSynchronization JavaDoc
39 {
40    private static transient Logger log =
41       Logger.getLogger(AccountSessionBean.class);
42    
43    private transient int balanceAtTxStart;
44    private String JavaDoc testName;
45    private int balance;
46
47    public void ejbCreate(String JavaDoc 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