User: fleury  
  Date: 00/09/26 17:46:31

  Added:       src/main/org/jboss/test/testbean/bean BMTStatefulBean.java
                        BMTStatelessBean.java EnterpriseEntityBean.java
                        EntityBMPBean.java EntityPKBean.java
                        StatefulSessionBean.java StatelessSessionBean.java
                        TxSessionBean.java
  Log:
  Added src for TestBean from ZOLA
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/BMTStatefulBean.java
  
  Index: BMTStatefulBean.java
  ===================================================================
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import org.jboss.test.testbean.interfaces.BMTStateful;
  import javax.transaction.UserTransaction;
  import javax.transaction.Status;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.Statement;
  import java.sql.ResultSet;
  import javax.sql.DataSource;
  import java.sql.SQLException;
  
  public class BMTStatefulBean implements SessionBean {
        private SessionContext sessionContext;
  
        public void ejbCreate() throws RemoteException, CreateException {
                System.out.println("BMTStatefulBean.ejbCreate() called");
        }
  
        public void ejbActivate() throws RemoteException {
                System.out.println("BMTStatefulBean.ejbActivate() called");
        }
  
        public void ejbPassivate() throws RemoteException {
                System.out.println("BMTStatefulBean.ejbPassivate() called");
        }
  
        public void ejbRemove() throws RemoteException {
                System.out.println("BMTStatefulBean.ejbRemove() called");
        }
  
        public void setSessionContext(SessionContext context) throws RemoteException {
                sessionContext = context;
        }
  
        public String txExists() throws RemoteException {
                String result = "";
                try {
                        UserTransaction ut1 = sessionContext.getUserTransaction();
                        result += "Got UserTransaction via 
sessionContext.getUserTransaction(): "+ statusName(ut1.getStatus()) + "\n";
                
                        UserTransaction ut2 = (UserTransaction)new 
InitialContext().lookup("java:comp/UserTransaction");
                        result += "Got UserTransaction via 
lookup(java:comp/UserTransaction): "+ statusName(ut2.getStatus()) + "\n";
                        
                        return result;
                } catch (Exception e) {
                e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
                
                
        public String txCommit() throws RemoteException {
            try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        String result = "Got transaction : " + 
statusName(tx.getStatus()) + "\n";
                        tx.begin();
                        result += "tx.begin(): " + statusName(tx.getStatus()) + "\n";
                        tx.commit();
                        result += "tx.commit(): " + statusName(tx.getStatus()) + "\n";
                
                        return result;
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
                
        }
                
        public String txRollback() throws RemoteException {
            try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        String result = "Got transaction : " + 
statusName(tx.getStatus()) + "\n";
                        tx.begin();
                        result += "tx.begin(): " + statusName(tx.getStatus()) + "\n";
                        tx.rollback();
                        result += "tx.rollback(): " + statusName(tx.getStatus()) + 
"\n";
                
                        return result;
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
                
          
  
        public String txBegin() throws RemoteException {
                try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        tx.begin();
                        return "status: " + statusName(tx.getStatus());
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
                
        }
        
        public String txEnd() throws RemoteException {
                try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        tx.commit();
                        return "status: " + statusName(tx.getStatus());
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
                
        }
        
        public void createTable() throws RemoteException {
                try {
                        Connection connection = ((DataSource)new 
InitialContext().lookup("java:comp/env/jdbc/myDatabase")).getConnection();
                        Statement stm = connection.createStatement();
                        try {
                                stm.executeQuery("CREATE TABLE bmttest (field 
VARCHAR(256))");
                        } catch (SQLException e) {
                                // ignore, table probably already exists
                        }
                        stm.executeQuery("INSERT INTO bmttest VALUES ('initial 
value')");
                        connection.close();
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
                        
        public void dropTable() throws RemoteException {
                try {
                        Connection connection = ((DataSource)new 
InitialContext().lookup("java:comp/env/jdbc/myDatabase")).getConnection();
                        Statement stm = connection.createStatement();
                        stm.executeQuery("DROP TABLE bmttest");
                        connection.close();
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
                        
        
        public String dbCommit() throws RemoteException {
                try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        tx.begin();
                        
                        Connection connection = ((DataSource)new 
InitialContext().lookup("java:comp/env/jdbc/myDatabase")).getConnection();
                        Statement stm = connection.createStatement();
                        
                        stm.executeQuery("UPDATE bmttest SET field = 'updated via 
dbCommit'");
                        connection.close();
                        
                        tx.commit();
                        return statusName(tx.getStatus());
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
                        
                        
                
        
        public String dbRollback() throws RemoteException {
                try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        tx.begin();
                        
                        Connection connection = ((DataSource)new 
InitialContext().lookup("java:comp/env/jdbc/myDatabase")).getConnection();
                        Statement stm = connection.createStatement();
                        
                        stm.executeQuery("UPDATE bmttest SET field = 'updated via 
dbRollback'");
                        connection.close();
                        
                        tx.rollback();
                        return statusName(tx.getStatus());
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
        
        
        public String getDbField() throws RemoteException {
                try {
                        Connection connection = ((DataSource)new 
InitialContext().lookup("java:comp/env/jdbc/myDatabase")).getConnection();
                        Statement stm = connection.createStatement();
                        ResultSet rs = stm.executeQuery("SELECT field FROM bmttest ");
                        String result = "not found";
                        if (rs.next()) {
                        result = rs.getString(1);
                        }
                        connection.close();
                        return result;
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
        }
        
        
        private String statusName(int s) {
                switch (s) {
                        case Status.STATUS_ACTIVE: return "STATUS_ACTIVE";
                        case Status.STATUS_COMMITTED: return "STATUS_COMMITED"; 
                        case Status.STATUS_COMMITTING: return "STATUS_COMMITTING"; 
                        case Status.STATUS_MARKED_ROLLBACK: return 
"STATUS_MARKED_ROLLBACK"; 
                        case Status.STATUS_NO_TRANSACTION: return 
"STATUS_NO_TRANSACTION"; 
                        case Status.STATUS_PREPARED: return "STATUS_PREPARED"; 
                        case Status.STATUS_PREPARING: return "STATUS_PREPARING"; 
                        case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK"; 
                        case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK"; 
                        case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN"; 
           }
           return "REALLY_UNKNOWN";
        }   
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/BMTStatelessBean.java
  
  Index: BMTStatelessBean.java
  ===================================================================
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import org.jboss.test.testbean.interfaces.BMTStateful;
  import javax.transaction.UserTransaction;
  import javax.transaction.Status;
  
  
  public class BMTStatelessBean implements SessionBean {
    private SessionContext sessionContext;
  
    public void ejbCreate() throws RemoteException, CreateException {
    System.out.println("BMTStatelessBean.ejbCreate() called");
    }
  
    public void ejbActivate() throws RemoteException {
      System.out.println("BMTStatelessBean.ejbActivate() called");
    }
  
    public void ejbPassivate() throws RemoteException {
        System.out.println("BMTStatelessBean.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException {
       System.out.println("BMTStatelessBean.ejbRemove() called");
    }
  
    public void setSessionContext(SessionContext context) throws RemoteException {
      sessionContext = context;
    }
  
        public String txExists() throws RemoteException {
                String result = "";
                try {
                        UserTransaction ut1 = sessionContext.getUserTransaction();
                        result += "Got UserTransaction via 
sessionContext.getUserTransaction()\n";
                
                        UserTransaction ut2 = (UserTransaction)new 
InitialContext().lookup("java:comp/UserTransaction");
                        result += "Got UserTransaction via 
lookup(java:comp/UserTransaction)\n";
                        return result;
                } catch (Exception e) {
                throw new RemoteException(e.getMessage());
                }
        }
                
                
        public String txCommit() throws RemoteException {
            try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        String result = "Got transaction : " + 
statusName(tx.getStatus()) + "\n";
                        tx.begin();
                        result += "tx.begin(): " + statusName(tx.getStatus()) + "\n";
                        tx.commit();
                        result += "tx.commit(): " + statusName(tx.getStatus()) + "\n";
                
                        return result;
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RemoteException(e.getMessage());
                }
                
        }
                
        public String txRollback() throws RemoteException {
            try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        String result = "Got transaction : " + 
statusName(tx.getStatus()) + "\n";
                        tx.begin();
                        result += "tx.begin(): " + statusName(tx.getStatus()) + "\n";
                        tx.rollback();
                        result += "tx.rollback(): " + statusName(tx.getStatus()) + 
"\n";
                
                        return result;
                        
                } catch (Exception e) {
                        throw new RemoteException(e.getMessage());
                }
        }
                
          
  
        // this should not be allowed by the container
        public String txBegin() throws RemoteException {
                try {
                        UserTransaction tx = sessionContext.getUserTransaction();
                
                        tx.begin();
                        return "status: " + statusName(tx.getStatus());
                } catch (Exception e) {
                        throw new RemoteException(e.getMessage());
                }
                
        }
  
        private String statusName(int s) {
                switch (s) {
                        case Status.STATUS_ACTIVE: return "STATUS_ACTIVE";
                        case Status.STATUS_COMMITTED: return "STATUS_COMMITED"; 
                        case Status.STATUS_COMMITTING: return "STATUS_COMMITTING"; 
                        case Status.STATUS_MARKED_ROLLBACK: return 
"STATUS_MARKED_ROLLBACK"; 
                        case Status.STATUS_NO_TRANSACTION: return 
"STATUS_NO_TRANSACTION"; 
                        case Status.STATUS_PREPARED: return "STATUS_PREPARED"; 
                        case Status.STATUS_PREPARING: return "STATUS_PREPARING"; 
                        case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK"; 
                        case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK"; 
                        case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN"; 
           }
           return "REALLY_UNKNOWN";
        }   
  
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/EnterpriseEntityBean.java
  
  Index: EnterpriseEntityBean.java
  ===================================================================
  
  //Title:        telkel
  //Version:      
  //Copyright:    Copyright (c) 1999
  //Author:       Marc Fleury
  //Company:      telkel
  //Description:  Your description
  
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  
  import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
  import org.jboss.test.testbean.interfaces.EnterpriseEntity;
  
  public class EnterpriseEntityBean implements EntityBean {
    private EntityContext entityContext;
    public String name;
    public int otherField = 0;
                                                              
  
    public void ejbCreate(String name) throws RemoteException, CreateException {
  
         System.out.println("EntityBean.ejbCreate("+name+") called");
         this.name = name;
    }
  
    // For usage in CMP only (void return)
    
    public void ejbFindByPrimaryKey(String name) throws RemoteException, 
FinderException {
  
        System.out.println("EntityBean.ejbFindByPrimaryKey() called");
    }
  
    public void ejbPostCreate(String name) throws RemoteException, CreateException {
  
         System.out.println("EntityBean.ejbPostCreate("+name+") called");
           
           EJBObject ejbObject = entityContext.getEJBObject();
           
           if (ejbObject == null) {
                   System.out.println("******************************* NULL EJBOBJECT 
in ejbPostCreate");
           }
           else {
                        System.out.println("&&&&&&&&&&&&&&&& EJBObject found in 
ejbPostCreate id is "+ejbObject.getPrimaryKey());   
           }
  
    }
  
    public void ejbActivate() throws RemoteException {
      System.out.println("EntityBean.ejbActivate() called");
    }
  
    public void ejbLoad() throws RemoteException {
     System.out.println("EntityBean.ejbLoad() called");
    }
  
    public void ejbPassivate() throws RemoteException {
  
       System.out.println("EntityBean.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException, RemoveException {
     System.out.println("EntityBean.ejbRemove() called "+hashCode());
    }
  
    public void ejbStore() throws RemoteException {
          
     System.out.println("EntityBean.ejbStore() called "+hashCode());
    }
  
    public String callBusinessMethodA() {
  
       System.out.println("EntityBean.callBusinessMethodA() called");
       return "EntityBean.callBusinessMethodA() called, my primaryKey is "+
              entityContext.getPrimaryKey().toString();
    }
    
    public String callBusinessMethodB() {
  
       System.out.println("EntityBean.callBusinessMethodB() called");
       
         EJBObject ejbObject = entityContext.getEJBObject();
         
         if (ejbObject == null) 
                return "NULL EJBOBJECT";
         
         else 
                return ejbObject.toString();
    }
    
    
     public String callBusinessMethodB(String words) {
      
          System.out.println("EntityBean.callBusinessMethodB(String) called");
       
         EJBObject ejbObject = entityContext.getEJBObject();
         
         if (ejbObject == null) 
                return "NULL EJBOBJECT";
         
         else 
                return ejbObject.toString()+ " words "+words;
    
        }
    public void setOtherField(int value) {
        
      System.out.println("EntityBean.setOtherField("+value+")");
      otherField = value;
    }
    
    public int getOtherField() {
       System.out.println("EntityBean.getOtherField() called");
       return otherField;
   }
    
    public EnterpriseEntity createEntity(String newName) throws RemoteException {
  
      System.out.println("EntityBean.createEntity() called");
      EnterpriseEntity newBean;
      try{
                EJBObject ejbObject = entityContext.getEJBObject();
                if (ejbObject == null) 
                System.out.println("************************** NULL EJBOBJECT");
                else
          System.out.println("************************** OK EJBOBJECT");
                
                EnterpriseEntityHome home = 
(EnterpriseEntityHome)entityContext.getEJBObject().getEJBHome();
            newBean = (EnterpriseEntity)home.create(newName);
  
      
        }catch(Exception e)
      {
                e.printStackTrace();
          throw new RemoteException("create entity did not work check messages");   
      }
       
       return newBean;
    }
    
    public void setEntityContext(EntityContext context) throws RemoteException {
       System.out.println("EntityBean.setSessionContext() called");
       entityContext = context;
    }
  
    public void unsetEntityContext() throws RemoteException {
       System.out.println("EntityBean.unsetSessionContext() called");
      entityContext = null;
    }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/EntityBMPBean.java
  
  Index: EntityBMPBean.java
  ===================================================================
  package org.jboss.test.testbean.bean;
  
  
  import java.rmi.*;
  import javax.ejb.*;
  import javax.naming.Context;
  import javax.sql.DataSource;
  import javax.naming.InitialContext;
  import java.sql.Connection;
  import org.jboss.test.testbean.interfaces.StatelessSession;
  import org.jboss.test.testbean.interfaces.StatelessSessionHome;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Vector;
  import java.util.Enumeration;
  
  public class EntityBMPBean implements EntityBean {
    private EntityContext entityContext;
    public String name;
    private StatelessSession statelessSession;
    private boolean wasFind = false;
  
  
    public String ejbCreate() throws RemoteException, CreateException {
          
           System.out.println("EntityBMP.ejbCreate() called");
         this.name = "noname";
  
         return name;
    
          
    }
    public String ejbCreate(String name) throws RemoteException, CreateException {
  
         System.out.println("EntityBMP.ejbCreate("+name+") called");
         this.name = name;
  
         return name;
    }
  
    // For usage in BMP only (The return is the primary key type)
  
    public String ejbFindByPrimaryKey(String name) throws RemoteException, 
FinderException {
  
        System.out.println("EntityBMP.ejbFindByPrimaryKey() called");
  
        wasFind = true;
  
        return name;
    }
  
    public Collection ejbFindCollectionKeys(int num) throws RemoteException, 
FinderException {
  
        System.out.println("EntityBMP.ejbFindMultipleKeys() called with num "+num);
        Collection pks = new Vector();
        pks.add("primary key number 1");
        pks.add("primary key number 2");
        pks.add("primary key number 3");
  
        return pks;
    }
    public Enumeration ejbFindEnumeratedKeys(int num) throws RemoteException, 
FinderException {
  
        System.out.println("EntityBMP.ejbFindEnumeratedKeys() called with num "+num);
        Collection pks = new Vector();
        pks.add("primary key number 1");
        pks.add("primary key number 2");
        pks.add("primary key number 3");
  
        return Collections.enumeration(pks);
    }
  
    public void ejbPostCreate(String name) throws RemoteException, CreateException {
  
         System.out.println("EntityBMP.ejbPostCreate("+name+") called");
    }
  
    public void ejbActivate() throws RemoteException {
      System.out.println("EntityBMP.ejbActivate() called");
    }
  
    public void ejbLoad() throws RemoteException {
     System.out.println("EntityBMP.ejbLoad() called");
    }
  
    public void ejbPassivate() throws RemoteException {
  
       System.out.println("Was Find "+wasFind);
       System.out.println("EntityBMP.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException, RemoveException {
     System.out.println("EntityBMP.ejbRemove() called");
    }
  
    public void ejbStore() throws RemoteException {
         
     System.out.println("EntityBMP.ejbStore() called");
    }
  
    public String callBusinessMethodA() throws RemoteException{
  
       System.out.println("EntityBMP.callBusinessMethodA() called");
       return "EntityBMP.callBusinessMethodA() called, my primaryKey is "+
              entityContext.getPrimaryKey().toString();
    }
  
     public String callBusinessMethodB() throws RemoteException {
  
       System.out.println("EntityBMP.callBusinessMethodB() called, calling B2B");
       String b2bMessage = statelessSession.callBusinessMethodB();
       System.out.println("EntityBMP called stateless Bean and it said "+b2bMessage);
       return "EntityBMP.callBusinessMethodB() called, called other bean (B2B) and it 
said \""+b2bMessage+"\"";
  
    }
    
     public String callBusinessMethodB(String words) throws RemoteException {
         System.out.println("EntityBMP.callBusinessMethodB(String) called, calling 
B2B");
       String b2bMessage = statelessSession.callBusinessMethodB();
       System.out.println("EntityBMP called stateless Bean and it said "+b2bMessage);
       return "EntityBMP.callBusinessMethodB() called, called other bean (B2B) and it 
said \""+b2bMessage+"\""+" words "+words;
  
    }
  
    public void setEntityContext(EntityContext context) throws RemoteException {
       System.out.println("EntityBMP.setSessionContext() called");
       entityContext = context;
  
       //we use the setEntityContext to lookup the connection and the EJBReference
  
          try {
  
              Context namingContext = new InitialContext();
  
              Connection connection = ((DataSource) 
namingContext.lookup("java:comp/env/jdbc/myDatabase")).getConnection();
  
              System.out.println("EntityBMP I did get the connection to the database 
for BMP");
          }
  
          catch (Exception e) {
  
              e.printStackTrace();
  
              System.out.println("EntityBMP Could not find the database connection, 
check settings");
  
              throw new RemoteException("EntityBMP Could not find the database 
connection");
          }
  
          try {
  
              Context namingContext = new InitialContext();
  
              System.out.println("EntityBMP Looking up Stateless Home");
  
              StatelessSessionHome statelessHome = ((StatelessSessionHome) 
namingContext.lookup("java:comp/env/ejb/myEJBRef"));
  
              System.out.println("EntityBMP Calling create on Stateless Home");
              
              statelessSession = statelessHome.create();
  
              System.out.println("EntityBMP Found the EJB Reference in my 
java:comp/env/ environment");
  
  
          }
  
          catch (Exception e) {
  
              e.printStackTrace();
  
              System.out.println("EntityBMP Could not find the EJB Reference called 
myEJBRef, check settings");
  
              throw new RemoteException("EntityBean Could not find EJB Reference");
          }
      }
  
      public void unsetEntityContext() throws RemoteException {
  
          System.out.println("EntityBMP.unsetSessionContext() called");
          entityContext = null;
      }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/EntityPKBean.java
  
  Index: EntityPKBean.java
  ===================================================================
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import org.jboss.test.testbean.interfaces.AComplexPK;
  
  /*
  * The purpose of this class is to test
  * 1- the storage of all the types of primitives we know
  * 2- the complex primary key AComplexPK
  *
  */
  
  public class EntityPKBean implements EntityBean {
      public boolean aBoolean;
      public int anInt;
      public long aLong;
      public double aDouble;
      public String aString;
  
        public int otherField;
      
        private EntityContext entityContext;
  
  
      public AComplexPK ejbCreate(boolean aBoolean, int anInt, long aLong, double 
aDouble, String aString) throws RemoteException, CreateException {
  
          System.out.println("EntityPK.ejbCreate() called");
  
          this.aBoolean = aBoolean;
          this.anInt = anInt;
          this.aLong = aLong;
          this.aDouble = aDouble;
          this.aString = aString;
  
          return new AComplexPK(aBoolean, anInt, aLong, aDouble, aString);
      }
  
  
      public void ejbPostCreate(boolean aBoolean, int anInt, long aLong, double 
aDouble, String aString) throws RemoteException, CreateException {
  
          System.out.println("EntityPK.ejbPostCreate(pk) called");
      }
  
      public void ejbActivate() throws RemoteException {
  
          System.out.println("EntityPK.ejbActivate() called");
      }
  
      public void ejbLoad() throws RemoteException {
  
          System.out.println("EntityPK.ejbLoad() called");
      }
  
      public void ejbPassivate() throws RemoteException {
  
          System.out.println("EntityPK.ejbPassivate() called");
      }
  
      public void ejbRemove() throws RemoteException, RemoveException {
  
          System.out.println("EntityPK.ejbRemove() called");
      }
  
      public void ejbStore() throws RemoteException {
  
          System.out.println("EntityPK.ejbStore() called");
      }
  
  
      public void setEntityContext(EntityContext context) throws RemoteException {
  
          System.out.println("EntityPK.setSessionContext() called");
          entityContext = context;
      }
  
      public void unsetEntityContext() throws RemoteException {
  
          System.out.println("EntityBMP.unsetSessionContext() called");
          entityContext = null;
      }
  
      public void updateAllValues(AComplexPK aComplexPK){
  
          this.aBoolean = aComplexPK.aBoolean;
          this.aDouble = aComplexPK.aDouble;
          this.aLong = aComplexPK.aLong;
          this.anInt = aComplexPK.anInt;
          this.aString = aComplexPK.aString;
  
      };
  
      public AComplexPK readAllValues() {
  
          return new AComplexPK(aBoolean, anInt, aLong, aDouble, aString);
  
  
      };
        
        public int getOtherField() {
                return otherField;
        }
        
        public void setOtherField(int newValue) {
                otherField = newValue;
        }
        
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/StatefulSessionBean.java
  
  Index: StatefulSessionBean.java
  ===================================================================
  
  //Title:        telkel
  //Version:      
  //Copyright:    Copyright (c) 1999
  //Author:       Marc Fleury
  //Company:      telkel
  //Description:  Your description
  
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  
  public class StatefulSessionBean implements SessionBean {
    private SessionContext sessionContext;
    public String name;
  
    public void ejbCreate() throws RemoteException, CreateException {
        
          System.out.println("StatefulSessionBean.ejbCreate() called");
          this.name= "noname";
    }
    
    public void ejbCreate(String name) throws RemoteException, CreateException {
        System.out.println("StatefulSessionBean.ejbCreate("+name+") called");
        this.name = name;
    }
  
    public void ejbCreate(String name, String address) throws RemoteException, 
CreateException {
        System.out.println("StatefulSessionBean.ejbCreate("+name+"@"+address+") 
called");
        this.name = name;
    }
  
    public void ejbActivate() throws RemoteException {
        System.out.println("StatefulSessionBean.ejbActivate() called");
    }
  
    public void ejbPassivate() throws RemoteException {
       System.out.println("StatefulSessionBean.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException {
       System.out.println("StatefulSessionBean.ejbRemove() called");
    }
  
    public String callBusinessMethodA() {
       System.out.println("StatefulSessionBean.callBusinessMethodA() called");
       return "I was created with Stateful String "+name;
    }
  
        public String callBusinessMethodB() {
                 System.out.println("StatefulSessionBean.callBusinessMethodB() 
called");
           // Check that my EJBObject is there
                 EJBObject ejbObject = sessionContext.getEJBObject();
                 if (ejbObject == null) {
                         return "ISNULL:NOT FOUND!!!!!";
                
                 }
                 else {
                        return "OK ejbObject is "+ejbObject.toString();
                        
                 }                       
    }
    
    
    public String callBusinessMethodB(String words) {
         System.out.println("StatefulSessionBean.callBusinessMethodB(String) called");
           // Check that my EJBObject is there
                 EJBObject ejbObject = sessionContext.getEJBObject();
                 if (ejbObject == null) {
                         return "ISNULL:NOT FOUND!!!!!";
                
                 }
                 else {
                        return "OK ejbObject is "+ejbObject.toString()+" words "+words;
                        
                 }                       
    
    }
    
    
    public void setSessionContext(SessionContext context) throws RemoteException {
       System.out.println("StatefulSessionBean.setSessionContext("+context+") called");
       sessionContext = context;
    }
  } 
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/StatelessSessionBean.java
  
  Index: StatelessSessionBean.java
  ===================================================================
  
  //Title:        telkel
  //Version:
  //Copyright:    Copyright (c) 1999
  //Author:       Marc Fleury
  //Company:      telkel
  //Description:  Your description
  
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import org.jboss.test.testbean.interfaces.BusinessMethodException;
  
  public class StatelessSessionBean implements SessionBean {
    private SessionContext sessionContext;
  
    public void ejbCreate() throws RemoteException, CreateException {
    System.out.println("StatelessSessionBean.ejbCreate() called");
    }
  
    public void ejbActivate() throws RemoteException {
      System.out.println("StatelessSessionBean.ejbActivate() called");
    }
  
    public void ejbPassivate() throws RemoteException {
        System.out.println("StatelessSessionBean.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException {
       System.out.println("StatelessSessionBean.ejbRemove() called");
    }
  
    public void setSessionContext(SessionContext context) throws RemoteException {
      sessionContext = context;
      //Exception e = new Exception("in set Session context");
      //e.printStackTrace();
    }
  
    public void callBusinessMethodA() {
        //Do nothing just make sure the call works
          
        try {
           Object tx = ((javax.transaction.TransactionManager) new 
InitialContext().lookup("TransactionManager")).getTransaction();
           if (tx == null) 
             System.out.println("I don't see a transaction");
           else
             System.out.println("I see a transaction "+tx.hashCode());
        }
        catch (Exception e) {e.printStackTrace();}
        System.out.println("StatelessSessionBean.callBusinessMethodA() called");
     }
  
    public String callBusinessMethodB() {
         System.out.println("StatelessSessionBean.callBusinessMethodB() called");
         try {
  
             Context context = new InitialContext();
             String name = (String) context.lookup("java:comp/env/myNameProp");
             return "from the environment properties my name is "+name;
  
         }catch (Exception e) { return "Error in the lookup of properties  
"+e.getMessage();}
    }
  
    public String callBusinessMethodB(String words) {
           // test if overloaded methods are properly called
           System.out.println("StatelessSessionBean.callBusinessMethodB(String) 
called");
           // Check that my EJBObject is there
          EJBObject ejbObject = sessionContext.getEJBObject();
          if (ejbObject == null) {
            return "ISNULL:NOT FOUND!!!!!";
         
          }
          else {
           return "OK ejbObject is "+ejbObject.toString()+" words "+words;
           
          }                      
    
    }
  
    public String callBusinessMethodC() {
         System.out.println("StatelessSessionBean.callBusinessMethodC() called");
         try {
  
             Context context = new InitialContext();
             String name = (String) 
context.lookup("java:comp/env/subContext/myNameProp");
             return "from the environment properties (subContext) my name is "+name;
  
         }catch (Exception e) { return "Error in the lookup of properties  
"+e.getMessage();}
    }
  
     public void callBusinessMethodD() throws BusinessMethodException {
         System.out.println("StatelessSessionBean.callBusinessMethodD() called");
         throw new BusinessMethodException();
    }
    
    public String callBusinessMethodE() {
          System.out.println("StatelessSessionBean.callBusinessMethodE() called");
           // Check that my EJBObject is there
          EJBObject ejbObject = sessionContext.getEJBObject();
          if (ejbObject == null) {
            return "ISNULL:NOT FOUND!!!!!";
          }
          else {
           return ejbObject.toString();
          }                      
    }
    
     public void testClassLoading() throws BusinessMethodException {
         System.out.println("StatelessSessionBean.testClassLoading() called");
         
          try{
              Class.forName("org.somepackage.SomeClass");
          } catch( Exception e){
              e.printStackTrace();
              throw new BusinessMethodException();
          }
    }
    
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/testbean/bean/TxSessionBean.java
  
  Index: TxSessionBean.java
  ===================================================================
  /******************************************************
   * File: TxSessionBean.java
   * created 07-Sep-00 7:39:53 PM by Administrator
   */
  
  
  package org.jboss.test.testbean.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import org.jboss.test.testbean.interfaces.TxSession;
  
  
  public class TxSessionBean implements SessionBean {
    private SessionContext sessionContext;
  
    public void ejbCreate() throws RemoteException, CreateException {
    System.out.println("TxSessionBean.ejbCreate() called");
    }
  
    public void ejbActivate() throws RemoteException {
      System.out.println("TxSessionBean.ejbActivate() called");
    }
  
    public void ejbPassivate() throws RemoteException {
        System.out.println("TxSessionBean.ejbPassivate() called");
    }
  
    public void ejbRemove() throws RemoteException {
       System.out.println("TxSessionBean.ejbRemove() called");
    }
  
    public void setSessionContext(SessionContext context) throws RemoteException {
      sessionContext = context;
      //Exception e = new Exception("in set Session context");
      //e.printStackTrace();
    }
  
    /*
    * This method is defined with "Required"
    */
    public String txRequired() {
   
        System.out.println("TxSessionBean.txRequired() called");  
        
        try {
           Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required sees no transaction");
           else
             return ("required sees a transaction "+tx.hashCode());
        }
        catch (Exception e) {e.printStackTrace(); return e.getMessage();}
     }
    
    
    /*
    * This method is defined with "Requires_new"
    */
    public String txRequiresNew() {
   
        System.out.println("TxSessionBean.txRequiresNew() called");  
        
        try {
           Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("RequiresNew sees no transaction");
           else
             return ("requiresNew sees a transaction "+tx.hashCode());
        }
        catch (Exception e) {e.printStackTrace();return e.getMessage();}
     }
    
     /*
    * testSupports is defined with Supports
    */
     
    public String txSupports() {
        
        System.out.println("TxSessionBean.txSupports() called");  
        
        try {
            
          Object tx =getDaTransaction();
          
          if (tx == null) 
             return "supports sees no transaction";
          else
             return "supports sees a transaction "+tx.hashCode();
      }
      catch (Exception e) {e.printStackTrace();return e.getMessage();}
   }  
   
   
    /*
    * This method is defined with "Mandatory"
    */
    public String txMandatory() {
   
        System.out.println("TxSessionBean.txMandatory() called");  
        
        try {
           Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Mandatory sees no transaction");
           else
             return ("mandatory sees a transaction "+tx.hashCode());
        }
        catch (Exception e) {e.printStackTrace();return e.getMessage();}
     }
    
     /*
    * This method is defined with "Never"
    */
    public String txNever() {
   
        System.out.println("TxSessionBean.txNever() called");  
        
        try {
           Object tx =getDaTransaction();
           if (tx == null) 
             return "never sees no transaction";
           else
               throw new Error("txNever sees a transaction");
        }
        catch (Exception e) {e.printStackTrace();return e.getMessage();}
     }
      /*
    * This method is defined with "TxNotSupported"
    */
    
    public String txNotSupported() {
   
        System.out.println("TxSessionBean.txNotSupported() called");  
        
        try {
           Object tx =getDaTransaction();
           if (tx == null) 
             return "notSupported sees no transaction";
           else
               throw new Error("txNotSupported sees a transaction");
        }
        catch (Exception e) {e.printStackTrace();return e.getMessage();}
     }
   
    /*
    * This method is defined with "Required" and it passes it to a Supports Tx
    */
    public String requiredToSupports() throws RemoteException {
        
        System.out.println("TxSessionBean.requiredToSupports() called");
        
        String message;        
        Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction");
           else
             message = "Required sees a transaction "+tx.hashCode()+ " Supports should 
see the same ";
       
        message = message + ((TxSession) sessionContext.getEJBObject()).txSupports();
    
         // And after invocation we should have the same transaction
         tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction COMING BACK");
           else
             return message + " on coming back Required sees a transaction 
"+tx.hashCode() ;
   
    }   
    
      /*
    * This method is defined with "Required" and it passes it to a NotSupported Tx
    */
    public String requiredToNotSupported() throws RemoteException {
        
        System.out.println("TxSessionBean.requiredToNotSupported() called");
        
        String message;        
        Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction");
           else
             message = "Required sees a transaction "+tx.hashCode()+ " NotSupported 
should see the same ";
      
          
        message = message + ((TxSession) 
sessionContext.getEJBObject()).txNotSupported();
        
        // And after invocation we should have the same transaction
         tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction COMING BACK");
           else
             return message + " on coming back Required sees a transaction 
"+tx.hashCode() ;
    }
    
    public String requiredToRequiresNew() throws RemoteException{
        
        System.out.println("TxSessionBean.requiredToRequiresNew() called");
        
        String message;        
        Object tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction");
           else
             message = "Required sees a transaction "+tx.hashCode()+ " Requires new 
should see a new transaction ";
      
      message =  message + ((TxSession) sessionContext.getEJBObject()).txRequiresNew();
        
       // And after invocation we should have the same transaction
         tx =getDaTransaction();
           if (tx == null) 
             throw new Error("Required doesn't see a transaction COMING BACK");
           else
             return message + " on coming back Required sees a transaction 
"+tx.hashCode() ;
    }
        
  
    
    private Object getDaTransaction() {
    
       try { 
          
          return ((javax.transaction.TransactionManager) new 
InitialContext().lookup("TransactionManager")).getTransaction();
      }
      catch (Exception e) { return null;}
    }
               
  }
  
  
  

Reply via email to