Hey

jBoss CVS Development wrote:
> 
>   User: mgroot
>   Date: 01/01/24 12:35:27
> 
>   Added:       src/main/org/jboss/util AutoNumberHome.java
>                         AutoNumberEJB.java AutoNumberFactory.java
>                         AutoNumber.java
>   Log:
>   Autonumber utility classes & EJB

Why are these in main JBoss CVS and not in the Zola CVS module? I don't
see why we should put EJB's, of any kind, into the server CVS.

regards,
  Rickard

> 
>   Revision  Changes    Path
>   1.1                  jboss/src/main/org/jboss/util/AutoNumberHome.java
> 
>   Index: AutoNumberHome.java
>   ===================================================================
>   /*
>    * JBoss, the OpenSource EJB server
>    *
>    * Distributable under LGPL license.
>    * See terms of license at gnu.org.
>    */
> 
>   package org.jboss.util;
> 
>   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
>          */
>         public AutoNumber create(String name) throws CreateException, 
>RemoteException;
> 
>         /**
>          * Finds an AutoNumber by its name.
>          */
>         public AutoNumber findByPrimaryKey(String name) throws FinderException, 
>RemoteException;
>   }
> 
> 
>   1.1                  jboss/src/main/org/jboss/util/AutoNumberEJB.java
> 
>   Index: AutoNumberEJB.java
>   ===================================================================
>   /*
>    * JBoss, the OpenSource EJB server
>    *
>    * Distributable under LGPL license.
>    * See terms of license at gnu.org.
>    */
> 
>   package org.jboss.util;
> 
>   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                  jboss/src/main/org/jboss/util/AutoNumberFactory.java
> 
>   Index: AutoNumberFactory.java
>   ===================================================================
>   /*
>    * JBoss, the OpenSource EJB server
>    *
>    * Distributable under LGPL license.
>    * See terms of license at gnu.org.
>    */
> 
>   package org.jboss.util;
> 
>   import javax.naming.InitialContext;
> 
>   /**
>    * 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 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) {
>                                 e.printStackTrace();
>                         }
>                 }
>                 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 e11) {
>                                 e11.printStackTrace();
>                         } catch (java.rmi.RemoteException e12) {
>                                 e12.printStackTrace();
>                         }
>                         try {
>                                 autoNumber.setValue(new Integer(0));
>                         } catch (java.rmi.RemoteException e21) {
>                                 e21.printStackTrace();
>                         }
>                 } catch (java.rmi.RemoteException e2) {
>                         e2.printStackTrace();
>                 }
>                 try {
>                         value = autoNumber.getValue();
>                         autoNumber.setValue(new Integer(value.intValue()+1));
>                 } catch (java.rmi.RemoteException e) {
>                         e.printStackTrace();
>                 }
> 
>                 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) {
>                                 e.printStackTrace();
>                         }
>                 }
>                 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 e11) {
>                                 e11.printStackTrace();
>                         } catch (java.rmi.RemoteException e12) {
>                                 e12.printStackTrace();
>                         }
>                 } catch (java.rmi.RemoteException e2) {
>                         e2.printStackTrace();
>                 }
>                 try {
>                         autoNumber.setValue(value);
>                 } catch (java.rmi.RemoteException e) {
>                         e.printStackTrace();
>                 }
>         }
>   }
> 
> 
>   1.1                  jboss/src/main/org/jboss/util/AutoNumber.java
> 
>   Index: AutoNumber.java
>   ===================================================================
>   /*
>    * JBoss, the OpenSource EJB server
>    *
>    * Distributable under LGPL license.
>    * See terms of license at gnu.org.
>    */
> 
>   package org.jboss.util;
> 
>   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.
>          */
>         public Integer getValue() throws RemoteException;
> 
>         /**
>          * Sets the current value of the autonumber.
>          */
>         public void setValue(Integer value) throws RemoteException;
>   }
> 
> 

-- 
Rickard Öberg

Email: [EMAIL PROTECTED]

Reply via email to