User: starksm 
  Date: 02/04/18 10:05:02

  Modified:    src/main/org/jboss/test/cts/ejb CtsCmpBean.java
                        StatefulSessionBean.java
  Log:
  Add a local entity interface and testing of stateful session passivation
  of a bean that includes a java:comp/env context and local interface
  as instance session variables
  
  Revision  Changes    Path
  1.3       +8 -167    jbosstest/src/main/org/jboss/test/cts/ejb/CtsCmpBean.java
  
  Index: CtsCmpBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/cts/ejb/CtsCmpBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CtsCmpBean.java   15 Feb 2002 06:15:51 -0000      1.2
  +++ CtsCmpBean.java   18 Apr 2002 17:05:02 -0000      1.3
  @@ -1,90 +1,32 @@
   package org.jboss.test.cts.ejb;
   
  -import org.jboss.test.cts.keys.*;
   import java.rmi.RemoteException;
  -import java.util.Vector;
  -import java.util.Collection;
  -import java.sql.*;
   import javax.naming.*;
   import javax.ejb.*;
  -import javax.sql.DataSource;
   
  +import org.jboss.test.cts.keys.AccountPK;
   
   public class CtsCmpBean
      implements EntityBean
   {
      org.apache.log4j.Category log = 
org.apache.log4j.Category.getInstance(getClass());
      
  -   EntityContext               ctx        = null;
  -   DataSource                  ds         = null;
  +   EntityContext ctx = null;
   
      // cmp fields
      public AccountPK pk;
  -   public String accountNumber;
      public String personsName;
   
  -   /**
  -    * Method ejbCreate
  -    *
  -    *
  -    * @param pk
  -    * @param personsName
  -    *
  -    * @return
  -    *
  -    * @throws CreateException
  -    * @throws DuplicateKeyException
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public AccountPK ejbCreate (AccountPK pk, String personsName)
         throws CreateException, DuplicateKeyException, EJBException,
                RemoteException
      {
  -      log.debug("entry ejbCreate");
  -
  -      return new AccountPK(accountNumber);
  -   }
  -
  -   /**
  -    * Method ejbFindByPrimaryKey
  -    *
  -    *
  -    * @param pk
  -    *
  -    * @return
  -    *
  -    * @throws EJBException
  -    * @throws FinderException
  -    * @throws RemoteException
  -    *
  -    */
  -
  -   public AccountPK ejbFindByPrimaryKey (AccountPK pk)
  -      throws FinderException, EJBException, RemoteException
  -   {
  -      log.debug("entry ejbFindByPrimaryKey");
  -
  -      return pk;
  +      log.debug("entry ejbCreate, pk="+pk);
  +      this.pk = pk;
  +      this.personsName = personsName;
  +      return null;
      }
   
  -
  -   /**
  -    * Method ejbPostCreate
  -    *
  -    *
  -    * @param pk
  -    * @param personsName
  -    *
  -    * @throws CreateException
  -    * @throws DuplicateKeyException
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbPostCreate (AccountPK pk, String personsName)
         throws CreateException, DuplicateKeyException, EJBException,
                RemoteException
  @@ -92,15 +34,6 @@
         log.debug("ejbPostCreate (AccountPK, String) called");
      }
   
  -   /**
  -    * Method ejbLoad
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbLoad ()
         throws EJBException, RemoteException
      {
  @@ -108,15 +41,6 @@
   
      }
   
  -   /**
  -    * Method ejbStore
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbStore ()
         throws EJBException, RemoteException
      {
  @@ -124,15 +48,6 @@
   
      }
   
  -   /**
  -    * Method ejbRemove
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbRemove ()
         throws EJBException, RemoteException
      {
  @@ -140,75 +55,24 @@
   
      }
   
  -   /**
  -    * Method ejbActivate
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbActivate ()
         throws EJBException, RemoteException
      {
         log.debug("ejbActivate () called");
      }
   
  -   /**
  -    * Method ejbPassivate
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void ejbPassivate ()
         throws EJBException, RemoteException
      {
         log.debug("ejbPassivate () called");
      }
   
  -   /**
  -    * Method setEntityContext
  -    *
  -    *
  -    * @param ctx
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void setEntityContext (EntityContext ctx)
         throws EJBException, RemoteException
      {
  -      log.debug("setEntityContext (\"" + ctx.getPrimaryKey()
  -                         + "\") called");
  -
  +      log.debug("setEntityContext ('" + ctx.getPrimaryKey() + "') called");
         this.ctx = ctx;
  -
  -      // lookup the datasource
  -      try
  -      {
  -         ds = ( DataSource ) new InitialContext().lookup(
  -            "java:comp/env/datasource");
  -      }
  -      catch (NamingException nex)
  -      {
  -         throw new EJBException("Datasource not found: " + nex.getMessage());
  -      }
  -   }
  -
  -   /**
  -    * Method unsetEntityContext
  -    *
  -    *
  -    * @throws EJBException
  -    * @throws RemoteException
  -    *
  -    */
  +   }
   
      public void unsetEntityContext ()
         throws EJBException, RemoteException
  @@ -218,41 +82,18 @@
         ctx = null;
      }
   
  -   /**
  -    * Method setPersonsName
  -    *
  -    *
  -    * @param personsName
  -    *
  -    * @throws RemoteException
  -    *
  -    */
  -
      public void setPersonsName (String personsName)
         throws RemoteException
      {
         this.personsName = personsName;
      }
   
  -   /**
  -    * Method getPersonsName
  -    *
  -    *
  -    * @return
  -    *
  -    * @throws RemoteException
  -    *
  -    */
  -
      public String getPersonsName ()
         throws RemoteException
      {
         return this.personsName;
      }
   
  -
  -
   }
  -
   
   /*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
  
  
  
  1.15      +50 -56    
jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java
  
  Index: StatefulSessionBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StatefulSessionBean.java  15 Feb 2002 08:50:55 -0000      1.14
  +++ StatefulSessionBean.java  18 Apr 2002 17:05:02 -0000      1.15
  @@ -1,24 +1,22 @@
   package org.jboss.test.cts.ejb;
   
  -
  -
  -import org.jboss.test.util.ejb.*;
   import java.security.Principal;
   import java.io.*;
   import javax.naming.*;
   import java.util.*;
   import javax.ejb.*;
  +
   import org.jboss.test.cts.interfaces.*;
  +import org.jboss.test.cts.keys.AccountPK;
   import org.jboss.test.util.ejb.SessionSupport;
   
   
   /**
    *
    *   @see <related>
  - *   @author $Author: user57 $
  - *   @version $Revision: 1.14 $
  + *   @author $Author: starksm $
  + *   @version $Revision: 1.15 $
    */
  -
   public class StatefulSessionBean
      extends SessionSupport
      implements SessionSynchronization
  @@ -26,6 +24,9 @@
      static org.apache.log4j.Category log = 
org.apache.log4j.Category.getInstance(StatefulSessionBean.class);
      
      private int counter;
  +   private CtsCmpLocal entityBean;
  +   private Context enc;
  +   private boolean wasPassivated;
   
      /**
       * Method ejbCreate
  @@ -40,40 +41,29 @@
      {
      }
   
  -   /**
  -    * Method afterBegin
  -    *
  -    *
  -    */
  +   public void ejbActivate()
  +   {
  +      log.debug("Called ejbActivate( )...");
  +      wasPassivated = true;
  +   }
  +   public void ejbPassivate()
  +   {
  +      log.debug("Called ejbPassivate( )...");
  +      wasPassivated = true;
  +   }
   
      public void afterBegin ()
      {
  -      log.debug("Calling afterBegin( )...");
  +      log.debug("Called afterBegin( )...");
      }
  -
  -   /**
  -    * Method afterCompletion
  -    *
  -    *
  -    * @param isCommited
  -    *
  -    */
  -
      public void afterCompletion (boolean isCommited)
      {
  -      log.debug("Calling afterCompletion( )");
  +      log.debug("Called afterCompletion( )");
         log.debug("isCommited = " + isCommited);
      }
  -
  -   /**
  -    * Method beforeCompletion
  -    *
  -    *
  -    */
  -
      public void beforeCompletion ()
      {
  -      log.debug("Calling beforeCompletion( )...");
  +      log.debug("Called beforeCompletion( )...");
      }
   
      /**
  @@ -139,14 +129,6 @@
         counter = value;
      }
   
  -   /**
  -    * Method getBeanContextInfo
  -    *
  -    *
  -    * @return
  -    *
  -    */
  -
      public BeanContextInfo getBeanContextInfo ()
         throws java.rmi.RemoteException
      {
  @@ -167,12 +149,6 @@
         return ctx;
      }
   
  -   /**
  -    * Method loopbackTest
  -    *
  -    *
  -    */
  -
      public void loopbackTest ()
         throws java.rmi.RemoteException
      {
  @@ -201,26 +177,44 @@
         }
      }
   
  -   /**
  -    * Method loopbackTest
  -    *
  -    *
  -    * @param obj
  -    *
  -    * @throws java.rmi.RemoteException
  -    *
  -    */
  -
      public void loopbackTest (EJBObject obj)
         throws java.rmi.RemoteException
      {
  -
         // This should throw an exception. 
         StatefulSession bean = ( StatefulSession ) obj;
   
         bean.method1("Hello");
      }
  -}
   
  +   public boolean getWasPassivated()
  +   {
  +      return wasPassivated;
  +   }
  +
  +   public void createLocalEntity(AccountPK pk, String personsName)
  +         throws javax.ejb.CreateException
  +   {
  +      try
  +      {
  +         InitialContext ctx = new InitialContext();
  +         enc = (Context) ctx.lookup("java:comp/env");
  +         CtsCmpLocalHome home = (CtsCmpLocalHome) 
enc.lookup("ejb/CMPBeanLocalHome");
  +         entityBean = home.create(pk, personsName);
  +      }
  +      catch(Exception e)
  +      {
  +         log.error("CtsCmpLocal create failed", e);
  +         throw new EJBException("CtsCmpLocal create failed", e);
  +      }
  +   }
  +
  +   public String readAndRemoveEntity()
  +      throws javax.ejb.RemoveException
  +   {
  +      String name = entityBean.getPersonsName();
  +      entityBean.remove();
  +      return name;
  +   }
  +}
   
   /*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to