KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > txiiop > ejb > StatefulSessionBean


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.txiiop.ejb;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.ByteArrayOutputStream JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.io.ObjectOutputStream JavaDoc;
28 import java.rmi.RemoteException JavaDoc;
29 import javax.ejb.CreateException JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.EJBObject JavaDoc;
32 import javax.ejb.Handle JavaDoc;
33 import javax.ejb.RemoveException JavaDoc;
34 import javax.ejb.SessionSynchronization JavaDoc;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37
38 import org.jboss.logging.Logger;
39 import org.jboss.test.cts.interfaces.BeanContextInfo;
40 import org.jboss.test.cts.interfaces.CtsCmpLocal;
41 import org.jboss.test.cts.interfaces.CtsCmpLocalHome;
42 import org.jboss.test.cts.interfaces.StatefulSession;
43 import org.jboss.test.cts.interfaces.StatefulSessionHome;
44 import org.jboss.test.cts.interfaces.StatelessSession;
45 import org.jboss.test.cts.interfaces.StatelessSessionHome;
46 import org.jboss.test.cts.keys.AccountPK;
47 import org.jboss.test.util.ejb.SessionSupport;
48
49
50 /** The stateful session ejb implementation
51  *
52  * @author Scott.Stark@jboss.org
53  * @version $Revision: 58115 $
54  */

55 public class StatefulSessionBean
56    extends SessionSupport
57    implements SessionSynchronization JavaDoc
58 {
59    private static transient Logger log = Logger.getLogger(StatefulSessionBean.class);
60    private transient int counterAtTxStart;
61    private String JavaDoc testName;
62    private int counter;
63
64    public void ejbCreate(String JavaDoc testName)
65    {
66       this.testName = testName;
67       log = Logger.getLogger(StatefulSessionBean.class.getName()+"#"+testName);
68       log.debug("ejbCreate("+testName+"), ctx="+sessionCtx);
69    }
70
71    public void afterBegin ()
72    {
73       log.debug("afterBegin()..., counter="+counter);
74       counterAtTxStart = counter;
75    }
76    public void afterCompletion (boolean isCommited)
77    {
78       log.debug("afterCompletion(), isCommited="+isCommited
79          +", counter="+counter+", counterAtTxStart="+counterAtTxStart);
80       if( isCommited == false )
81       {
82          counter = counterAtTxStart;
83          log.debug("Rolling counter back to: "+counter);
84       }
85       else
86       {
87          log.debug("Committed updated counter: "+counter);
88       }
89    }
90    public void beforeCompletion ()
91    {
92       log.debug("beforeCompletion(), counter="+counter
93          +", counterAtTxStart="+counterAtTxStart);
94    }
95
96    public void incCounter ()
97    {
98       counter++;
99    }
100
101    public void decCounter ()
102    {
103       counter--;
104    }
105
106    public int getCounter ()
107    {
108       return counter;
109    }
110
111    public void setCounter (int value)
112    {
113       counter = value;
114    }
115
116    public String JavaDoc txMandatoryMethod(String JavaDoc msg)
117    {
118       log.debug("txMandatoryMethod( ), msg="+msg);
119       return msg;
120    }
121
122 }
123
Popular Tags