User: oberg   
  Date: 00/08/25 06:43:43

  Added:       src/main/org/jboss/test/perf/ejb EntityBean.java
                        SessionBean.java
  Log:
  Added perf tests and idgen
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/perf/ejb/EntityBean.java
  
  Index: EntityBean.java
  ===================================================================
  package org.jboss.test.perf.ejb;
  // EntityBean.java
  import org.jboss.test.perf.interfaces.EntityPK;
  
  public class EntityBean implements javax.ejb.EntityBean {
  
    private javax.ejb.EntityContext _context;
    private transient boolean       isDirty; //WL
  
    public int the_key;
    public int the_value;
  
    public int read() {
      // WL
      setModified(false); // to avoid writing
      return the_value;
    }
    
    public void write(int the_value) {
      // WL
      setModified(true); // to force writing
      this.the_value = the_value;
    }
  
    public EntityPK ejbCreate(int the_key, int the_value) {
      this.the_key = the_key;
      this.the_value = the_value;
      return null;
    }
  
    public void ejbPostCreate(int the_key, int the_value) {
    }
  
    public void ejbRemove() {
    }
  
    public void setEntityContext(javax.ejb.EntityContext context) {
      _context = context;
    }
  
    public void unsetEntityContext() {
      _context = null;
    }
  
    public void ejbActivate() {
    }
  
    public void ejbPassivate() {
    }
  
    public void ejbLoad() {
      // WL
      setModified(false); // to avoid writing
    }
  
    public void ejbStore() {
      // WL
      setModified(false); // to avoid writing
    }
  
    public String toString() {
      return "EntityBean[the_key=" + the_key + ",the_value=" + the_value +"]";
    }
  
    // WL
    public boolean isModified() {
      return isDirty;
    }
    // WL
    public void setModified(boolean flag) {
      isDirty = flag;
    }
  
  
  }
  
  
  
  1.1                  jbosstest/src/main/org/jboss/test/perf/ejb/SessionBean.java
  
  Index: SessionBean.java
  ===================================================================
  package org.jboss.test.perf.ejb;
  // SessionBean.java
  
  import org.jboss.test.perf.interfaces.EntityHome;
  import org.jboss.test.perf.interfaces.Entity;
  import org.jboss.test.perf.interfaces.EntityPK;
  
  public class SessionBean implements javax.ejb.SessionBean {
  
    private EntityHome _entityHome;
  
    public void setSessionContext(javax.ejb.SessionContext context) {
    }
  
    public void ejbCreate(String entityName) throws javax.ejb.CreateException {
      try {
        javax.naming.Context context = new javax.naming.InitialContext();
        Object ref = context.lookup(entityName);
  
        _entityHome = (EntityHome) ref;
        /** CHANGES: Note that WebLogic does not support the EJB Spec
         ** compliant way of casting, this code is commented out
         ** and a Java cast is used to enable code compilation
          _entityHome = (EntityHome) javax.rmi.PortableRemoteObject.narrow(ref, 
EntityHome.class);
         **/
      }
      catch(javax.naming.NamingException e) {
        throw new javax.ejb.CreateException("Cound not resolve name: " + e);
      }
    }
  
    private Entity findByPrimaryKey(int key) throws java.rmi.RemoteException {
      try {
        EntityPK primaryKey = new EntityPK(key);
        return _entityHome.findByPrimaryKey(primaryKey);
      }
      catch(javax.ejb.FinderException e) {
        throw new java.rmi.ServerException("Cound not find Entity: " + key, e);
      }
    }
  
    private java.util.Enumeration findInRange(int min, int max) throws 
java.rmi.RemoteException {
      try {
        return _entityHome.findInRange(min, max);
      }
      catch(javax.ejb.FinderException e) {
        throw new java.rmi.ServerException
          ("Cound not findInRange(" + min + ", " + max + "): ", e);
      }
    }
  
    public void create(int low, int high) 
      throws java.rmi.RemoteException, javax.ejb.CreateException {
      for(int i = low; i < high; i++) {
        _entityHome.create(i, 0);
      }
    }
  
    public void remove(int low, int high) 
      throws java.rmi.RemoteException, javax.ejb.RemoveException {
      if(low + 1 == high) {
        Entity entity = findByPrimaryKey(low);
        entity.remove();
      }
      else {
        java.util.Enumeration elements = findInRange(low, high);
        while(elements.hasMoreElements()) {
          Entity entity = (Entity) elements.nextElement();
          entity.remove();
        }
      }
    }
  
    public void read(int id) throws java.rmi.RemoteException {
      Entity entity = findByPrimaryKey(id);
      entity.read();
    }
  
    public void read(int low, int high) throws java.rmi.RemoteException {
      java.util.Enumeration elements = findInRange(low, high);
      while(elements.hasMoreElements()) {
        Entity entity = (Entity) elements.nextElement();
        /** CHANGES: Note that WebLogic does not support the EJB Spec
         ** compliant way of casting, this code is commented out
         ** and a Java cast is used to enable code compilation
         Entity entity = (Entity) 
javax.rmi.PortableRemoteObject.narrow(elements.nextElement(), Entity.class);
         **/
        entity.read();
      }
    }
  
    public void write(int id) throws java.rmi.RemoteException {
      Entity entity = findByPrimaryKey(id);
      int value = entity.read();
      entity.write(value + 1);
    }
    
    public void write(int low, int high) throws java.rmi.RemoteException {
      java.util.Enumeration elements = findInRange(low, high);
      while(elements.hasMoreElements()) {
        Entity entity = (Entity) elements.nextElement();
        /** CHANGES: Note that WebLogic does not support the EJB Spec
         ** compliant way of casting, this code is commented out
         ** and a Java cast is used to enable code compilation
         Entity entity = (Entity) 
javax.rmi.PortableRemoteObject.narrow(elements.nextElement(), Entity.class);
         **/
        int value = entity.read();
        entity.write(value + 1);
      }
    }
  
    public void ejbRemove() {
    }
  
    public void ejbActivate() {
    }
  
    public void ejbPassivate() {
    }
  
  }
  
  
  

Reply via email to