001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.txiiop.ejb;
023:
024: import java.io.ByteArrayInputStream;
025: import java.io.ByteArrayOutputStream;
026: import java.io.ObjectInputStream;
027: import java.io.ObjectOutputStream;
028: import java.rmi.RemoteException;
029: import javax.ejb.CreateException;
030: import javax.ejb.EJBException;
031: import javax.ejb.EJBObject;
032: import javax.ejb.Handle;
033: import javax.ejb.RemoveException;
034: import javax.ejb.SessionSynchronization;
035: import javax.naming.Context;
036: import javax.naming.InitialContext;
037:
038: import org.apache.log4j.Category;
039: import org.jboss.test.cts.interfaces.BeanContextInfo;
040: import org.jboss.test.cts.interfaces.CtsCmpLocal;
041: import org.jboss.test.cts.interfaces.CtsCmpLocalHome;
042: import org.jboss.test.cts.interfaces.StatefulSession;
043: import org.jboss.test.cts.interfaces.StatefulSessionHome;
044: import org.jboss.test.cts.interfaces.StatelessSession;
045: import org.jboss.test.cts.interfaces.StatelessSessionHome;
046: import org.jboss.test.cts.keys.AccountPK;
047: import org.jboss.test.util.ejb.SessionSupport;
048:
049: /** The stateful session ejb implementation
050: *
051: * @author Scott.Stark@jboss.org
052: * @version $Revision: 57211 $
053: */
054: public class StatefulSessionBean extends SessionSupport implements
055: SessionSynchronization {
056: private static transient Category log = Category
057: .getInstance(StatefulSessionBean.class);
058: private transient int counterAtTxStart;
059: private String testName;
060: private int counter;
061:
062: public void ejbCreate(String testName) {
063: this .testName = testName;
064: log = Category.getInstance(StatefulSessionBean.class.getName()
065: + "#" + testName);
066: log.debug("ejbCreate(" + testName + "), ctx=" + sessionCtx);
067: }
068:
069: public void afterBegin() {
070: log.debug("afterBegin()..., counter=" + counter);
071: counterAtTxStart = counter;
072: }
073:
074: public void afterCompletion(boolean isCommited) {
075: log.debug("afterCompletion(), isCommited=" + isCommited
076: + ", counter=" + counter + ", counterAtTxStart="
077: + counterAtTxStart);
078: if (isCommited == false) {
079: counter = counterAtTxStart;
080: log.debug("Rolling counter back to: " + counter);
081: } else {
082: log.debug("Committed updated counter: " + counter);
083: }
084: }
085:
086: public void beforeCompletion() {
087: log.debug("beforeCompletion(), counter=" + counter
088: + ", counterAtTxStart=" + counterAtTxStart);
089: }
090:
091: public void incCounter() {
092: counter++;
093: }
094:
095: public void decCounter() {
096: counter--;
097: }
098:
099: public int getCounter() {
100: return counter;
101: }
102:
103: public void setCounter(int value) {
104: counter = value;
105: }
106:
107: public String txMandatoryMethod(String msg) {
108: log.debug("txMandatoryMethod( ), msg=" + msg);
109: return msg;
110: }
111:
112: }
|