User: user57  
  Date: 02/02/15 20:41:32

  Added:       varia/src/main/org/jboss/varia/autonumber AutoNumber.java
                        AutoNumberEJB.java AutoNumberEJB2.java
                        AutoNumberFactory.java AutoNumberHome.java
                        package.html
  Log:
   o Moved this stuff over to varia.  Does anyone styill use it?
   o Changed to use Logging instead of printStackTrace, but didn't
     even attempt to change the mass of try/catch blocks.
   o Does not appear to be used anywhere, or be turned into a deployable
     I assume this is just an application support component.
  
  Revision  Changes    Path
  1.1                  
contrib/varia/src/main/org/jboss/varia/autonumber/AutoNumber.java
  
  Index: AutoNumber.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.varia.autonumber;
  
  import javax.ejb.EJBObject;
  import java.rmi.RemoteException;
  
  /**
   * AutoNumber stores autonumbers for items in a collection.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
   * @version $Revision: 1.1 $
   */
  public interface AutoNumber
     extends EJBObject
  {
     /**
      * Gets the current value of the autonumber.
      */
     Integer getValue() throws RemoteException;
     
     /**
      * Sets the current value of the autonumber.
      */
     void setValue(Integer value) throws RemoteException;
  }
  
  
  
  1.1                  
contrib/varia/src/main/org/jboss/varia/autonumber/AutoNumberEJB.java
  
  Index: AutoNumberEJB.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.varia.autonumber;
  
  import javax.ejb.EntityBean;
  import javax.naming.InitialContext;
  
  /**
   * ???
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
   * @version $Revision: 1.1 $
   */
  public class AutoNumberEJB
     implements EntityBean
  {
     public String name;
     public Integer value; 
     
     public String ejbCreate(String name) {
        this.name = name;
        this.value = new Integer(0);
        
        return null;
     }
     
     public void ejbPostCreate(String name) {}
     
     public Integer getValue()  {
        return value;
     }
     
     public void setValue(Integer value)  {
        this.value = value;
     }
     
     public void ejbActivate() {}
     public void ejbPassivate() {}
     public void ejbLoad() {}
     public void ejbStore() {}
     public void ejbRemove() {}
     public void setEntityContext(javax.ejb.EntityContext ec) {}
     public void unsetEntityContext() {}
  }
  
  
  
  1.1                  
contrib/varia/src/main/org/jboss/varia/autonumber/AutoNumberEJB2.java
  
  Index: AutoNumberEJB2.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.varia.autonumber;
  
  import javax.ejb.EntityBean;
  import javax.naming.InitialContext;
  
  /**
   * The CMP 2 compatible version of AutoNumberEJB
   * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Ignacio Coloma</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AutoNumberEJB2
     implements EntityBean
  {
     public abstract Integer getValue();
     public abstract void setValue(Integer value);
     
     public abstract String getName();
     public abstract void setName(String name);
     
     public String ejbCreate(String name)
     {
        return null;
     }
     
     public void ejbPostCreate(String name) {}
     
     public void ejbActivate() {}
     public void ejbPassivate() {}
     public void ejbLoad() {}
     public void ejbStore() {}
     public void ejbRemove() {}
     public void setEntityContext(javax.ejb.EntityContext unused) {}
     public void unsetEntityContext() {}
     
  }
  
  
  
  1.1                  
contrib/varia/src/main/org/jboss/varia/autonumber/AutoNumberFactory.java
  
  Index: AutoNumberFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.varia.autonumber;
  
  import javax.naming.InitialContext;
  
  import org.jboss.logging.Logger;
  
  /**
   * AutoNumberFactory can persistently auto number items. 
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
   * @version $Revision: 1.1 $
   */
  public class AutoNumberFactory
  {
     private static final Logger log = Logger.getLogger(AutoNumberFactory.class);
     
     private static AutoNumberHome autoNumberHome;
     
     /**
      * Gets the next key for the given collection.
      * Note 1: you must deploy EJB AutoNumber
      * Note 2: the keys are persistent in your database, independent of 
      * the actual table
      * Note 3: you can only add instances to the collection which have a 
      * key generated by this method, otherwise the keys are not guaranteed
      * to be unique
      * Note 4: key values are >= 0
      * @param collectionName the name of the collection for which you want an 
autonumber
      * @throws ArrayIndexOutOfBoundsException if no more numbers are available
      */
     public static Integer getNextInteger(String collectionName)
        throws ArrayIndexOutOfBoundsException
     {
        Integer value = null;
        AutoNumber autoNumber = null;
        if (autoNumberHome == null) {
           try {
              autoNumberHome = (AutoNumberHome)new 
InitialContext().lookup("JBossUtilAutoNumber");
           }
           catch (javax.naming.NamingException e) {
              log.error("operation failed", e);
           }
        }
        
        try {
           autoNumber = (AutoNumber)autoNumberHome.findByPrimaryKey(collectionName);
        }
        catch (javax.ejb.FinderException e) {
           // autonumber does not exist yet, create one at value 0
           try {
              autoNumber = autoNumberHome.create(collectionName);
           }
           catch (javax.ejb.CreateException x) {
              log.error("operation failed", x);
           }
           catch (java.rmi.RemoteException x) {
              log.error("operation failed", x);
           }
           
           try {
              autoNumber.setValue(new Integer(0));
           }
           catch (java.rmi.RemoteException x) {
              log.error("operation failed", x);
           }
        }
        catch (java.rmi.RemoteException e) {
           log.error("operation failed", e);
        }
        
        try {
           value = autoNumber.getValue();
           autoNumber.setValue(new Integer(value.intValue()+1));
        }
        catch (java.rmi.RemoteException e) {
           log.error("operation failed", e);
        }
        
        return value;
     }
     
     /**
      * Resets the given autonumber to zero.
      * Use with extreme care!
      */
     public static void resetAutoNumber(String collectionName) {
        setAutoNumber(collectionName,new Integer(0));
     }
     
     /**
      * Sets the given autonumber to the given value so that it starts
      * counting at the given value.
      * Use with extreme care!
      */
     public static void setAutoNumber(String collectionName, Integer value) {
        AutoNumber autoNumber = null;
        if (autoNumberHome == null) {
           try {
              autoNumberHome = (AutoNumberHome)
                 new InitialContext().lookup("JBossUtilAutoNumber");
           }
           catch (javax.naming.NamingException e) {
              log.error("operation failed", e);            
           }
        }
        
        try {
           autoNumber = (AutoNumber)autoNumberHome.findByPrimaryKey(collectionName);
        }
        catch (javax.ejb.FinderException e) {
           // autonumber does not exist yet, create one
  
           try {
              autoNumber = autoNumberHome.create(collectionName);
           }
           catch (javax.ejb.CreateException x) {
              log.error("operation failed", x);
           }
           catch (java.rmi.RemoteException x) {
              log.error("operation failed", x);
           }
        }
        catch (java.rmi.RemoteException e) {
           log.error("operation failed", e);
        }
        
        try {
           autoNumber.setValue(value);
        }
        catch (java.rmi.RemoteException e) {
           log.error("operation failed", e);
        }
     }  
  }
  
  
  
  1.1                  
contrib/varia/src/main/org/jboss/varia/autonumber/AutoNumberHome.java
  
  Index: AutoNumberHome.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.varia.autonumber;
  
  import javax.ejb.EJBHome;
  import javax.ejb.CreateException;
  import javax.ejb.FinderException;
  import java.rmi.RemoteException;
  
  /**
   * ???
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
   * @version $Revision: 1.1 $
   */
  public interface AutoNumberHome
     extends EJBHome
  {
     /**
      * Creates an AutoNumber of given name.
      * 
      * @param name the name of the AutoNumber
      */
     AutoNumber create(String name) throws CreateException, RemoteException;
     
     /**
      * Finds an AutoNumber by its name.
      */
     AutoNumber findByPrimaryKey(String name) throws FinderException, RemoteException;
  }
  
  
  
  1.1                  contrib/varia/src/main/org/jboss/varia/autonumber/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
    <head>
      <!-- $Id: package.html,v 1.1 2002/02/16 04:41:32 user57 Exp $ -->
      <!--
  
      JBoss: The OpenSource J2EE WebOS 
  
      Distributable under LGPL license.
      See terms of license at gnu.org.
  
      -->
    </head>
  
    <body bgcolor="white">
      <p>AutoNumber EJB components.
  
      <h2>Package Specification</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
        
      <h2>Related Documentation</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
  
      <h2>Package Status</h2>
      <ul>
        <li><font color="green"><b>STABLE</b></font>
      </ul>
  
      <h2>Todo</h2>
      <ul>
        <li>???
      </ul>
  
      <!-- Put @see and @since tags down here. -->
  
    </body>
  </html>
  
  
  

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

Reply via email to