--- Tejaswi Redkar <[EMAIL PROTECTED]> wrote:
> I think we all would like to use your bean. It is in
> high demand.
> 
> Could you please send it to us ?

Answering to popular demand, here is source
for SequenceEJB.java

To made a EJB from it, just throw it to ejbdoclet.
Adjust package names as appropriate. 

---snip---
/**

   This is sequence entity bean. Process this file
using ejbdoclet to
   create all necessary interfaces and deployment
descriptors. 
   
   Licensing policy is GNU LGPL ( check www.gnu.org
for exact conditions )

   Copyright by Konstantin Pribluda 2001. All rights
reserved. 
   No responsibility accepted. Satisfaction is not
guaranted. 


   Any usage of this software by military entities or
for military puproses
   is explicitly prohibited, and will be considered as
act of war
   against author. Author reserves the right to
retailate such acts of war
   by means which seem convenient for him, included
but not limited to
   usage of voodoo cult technics to remotely cause
severy diarrhoe
   to violators. 
   

   play cool java games: http://www.yook.de/

 */

package org.pribluda.Sequence.ejb;
import org.pribluda.Sequence.*;
import org.pribluda.interfaces.*;

import java.util.Collection;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.ejb.EJBException;


/**
 * Sequence bean. Use entity name as primary key
 *
 * @author Konstantin Pribluda ( [EMAIL PROTECTED]
)
 * @ejb:entity-cmp
 * @ejb:ejb-name Sequence 
 * @ejb:finder Collection findAll()
 * @ejb:finder Collection findById(String id)
 * @ejb:jndi-name sequenceProvider
 * @jboss:table-name sequences
 */


public abstract class SequenceEJB implements
javax.ejb.EntityBean {
  transient private EntityContext ctx;


  /**
   * ID of sequence
   * @ejb:pk-field
   * @ejb:persistent-field
   * @ejb:remote-method
   */
  public abstract String getId();
  /**
   * @ejb:remote-method
   * @ejb:pk-field
   * @ejb:persistent-field
   */
  public abstract void setId(String id);

  /**
   * Last sequence number used
   * @ejb:remote-method
   * @ejb:persistent-field
   */
  public abstract long getValue();

  /**
   * Set last sequence number
   * @ejb:persistent-field
   * @ejb:remote-method
   */
  public abstract void setValue(long nn);


  /**
   * Initial sequence value
   * @ejb:persistent-field
   * @ejb:remote-method
   */
  public abstract void setInitialValue(long iv);
  /**
   * Initial sequence value
   * @ejb:persistent-field
   * @ejb:remote-method
   */
   public abstract long getInitialValue();


   /**
    * Sequence Increment
    * @ejb:persistent-field
    * @ejb:remote-method
    */
   public abstract void setIncrement(long incr);

   /**
    * Sequence Increment
    * @ejb:persistent-field
    * @jboss:column-name inc
    * @ejb:remote-method
    */
   public abstract long getIncrement();

   /**
    * Wrap-around status
    * @ejb:persistent-field
    * @ejb:remote-method
    * @jboss:column-name inc
    */
   public abstract void setWrapAround(boolean ok);

   /**
    * Wrap around status
    * @ejb:persistent-field
    * @ejb:remote-method
    */
   public abstract boolean getWrapAround();

   /**
    * Generate new sequence number and advance by one
    * Can throw wrap-around exception
    * @ejb:remote-method
    */
   public long getNext() throws WrapAroundException {
    long rr = getValue() + getIncrement();
    if(
        (
          (rr >= getInitialValue() && getValue() <
getInitialValue()) ||
          (rr <= getInitialValue() && getValue() >
getInitialValue())
        ) && getWrapAround()
      ) {
        throw new WrapAroundException("Sequence " +
getId() + " wrapped around");
      }
    setValue(rr);
    return rr;
   }


   /**
    * Reset sequence
    * @ejb:remote-method
    */
    public void resetSequence() {
      setValue(getInitialValue());
    }

    /**
     * Bulk accessor.
     * @ejb:remote-method
     */
    public abstract void setData(SequenceData data);
    /**
     * Bulk accessor.
     * @ejb:remote-method
     */
    public abstract SequenceData getData();

    /**
     * Create sequence default way
     * @ejb:create-method
     */
    public Object ejbCreate(String name) throws 
RemoteException, CreateException {
      setId(name);
      setInitialValue(-1);
      setIncrement(1);
      setWrapAround(true);

      return null;
    }

    /**
     * Create Sequence from bulk data
     * @ejb:create-method
     */
    public Object ejbCreate(SequenceData data) throws
RemoteException, CreateException {
        setData(data);
        return null;
    }

    /**
     * Create Sequence
     * @ejb:create-method
     */
    public Object ejbCreate(String sequenceName,int
initialValue,int step,boolean canWrap)
           throws RemoteException, CreateException {
      setId(sequenceName);
      setInitialValue(initialValue);
      setIncrement(step);
      setWrapAround(canWrap);
      return null;
    }

    /*
     * post create methods
     */
    public void ejbPostCreate(SequenceData data)
throws RemoteException, CreateException { }
    public void ejbPostCreate(String name) throws
RemoteException, CreateException { }
    public void ejbPostCreate(String sequenceName,int
initialValue,int step,boolean canWrap) throws
RemoteException, CreateException { }

    /**
     * standart maintenance stuff...
     */
    public void setEntityContext(EntityContext ctx) {
this.ctx = ctx; }
    public void unsetEntityContext() { ctx = null; }
    public void ejbActivate() { }
    public void ejbPassivate()  { }
    public void ejbLoad()  { }
    public void ejbStore()  { }
    public void ejbRemove()  throws RemoveException{ }

}

---snap---

And  corresponding exception:

--- snip ---

package org.pribluda.Sequence;


public class WrapAroundException extends Exception {

  public WrapAroundException() {
    super();
  }

  public WrapAroundException(String s) {
    super(s);
  }
}

---snap---

have fun with it.


reards,

=====
Konstantin Priblouda ( ko5tik )    Freelance Software developer
< http://www.pribluda.de > < play java games -> http://www.yook.de >
< render charts online -> http://www.pribluda.de/povray/ >

__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to