OpMath

com.opmath.test.j2ee.uid
Class UniqueIdGeneratorBean

java.lang.Object
  |
  +--com.opmath.test.j2ee.uid.UniqueIdGeneratorBean
All Implemented Interfaces:
EnterpriseBean, EntityBean, Serializable

public abstract class UniqueIdGeneratorBean
extends Object
implements EntityBean

The business logic for the unique ID generator. This CMP EJB performs an immensely simple task: it holds one long value, amd increments it on request. This EJB also has a unique key, which is used by the container as a primary key.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SDK 1.3.1, J2SDKEE 1.3.1, EJB 2.0
Version:
OpMath J2EE Example v1.0
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
Serialized Form

Constructor Summary
UniqueIdGeneratorBean()
           
 
Method Summary
 void ejbActivate()
          Invoked when the instance is taken out of the pool of available instances to become associated with a specific EJB object.
 UniqueIdGeneratorPK ejbCreate(UniqueIdGeneratorPK key)
          Creates a new UniqueIdGenerator EJB instance.
 void ejbLoad()
          The container invokes this method to instruct the instance to synchronize its state by loading its state from the underlying database.
 void ejbPassivate()
          A container invokes this method on an instance before the instance becomes disassociated with a specific EJB object.
 void ejbPostCreate(UniqueIdGeneratorPK key)
          Executed after the create operation has completed.
 void ejbRemove()
          The container invokes this method before it removes the EJB object that is currently associated with the instance.
 void ejbStore()
          The container invokes this method to instruct the instance to synchronize its state by storing it to the underlying database.
abstract  long getId()
          Returns the current unique ID as issued by this UniqueIdGenerator EJB.
abstract  UniqueIdGeneratorPK getKey()
          Returns the primary key for this UniqueIdGenerator EJB.
 long nextId()
          Generates the next unique ID .
 void setEntityContext(EntityContext ctx)
          Sets the private entity context of this instance.
abstract  void setId(long id)
          Sets the unique ID for this UniqueIdGenerator EJB to the given long value.
abstract  void setKey(UniqueIdGeneratorPK key)
          Sets the primary key for this UniqueIdGenerator EJB to the given UniqueIdGeneratorPK object.
 void unsetEntityContext()
          Sets the private entity context of this instance to null.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueIdGeneratorBean

public UniqueIdGeneratorBean()
Method Detail

getKey

public abstract UniqueIdGeneratorPK getKey()

Returns the primary key for this UniqueIdGenerator EJB.

This method is implemented by the EJB 2.0 compliant container.

Returns:
the UniqueIdGeneratorPK uniquely identifying this instance.

setKey

public abstract void setKey(UniqueIdGeneratorPK key)

Sets the primary key for this UniqueIdGenerator EJB to the given UniqueIdGeneratorPK object. Note that this method should not be made available via the EJB's remote interface.

This method is implemented by the EJB 2.0 compliant container.

Parameters:
key - a UniqueIdGeneratorPK specifying the key.

getId

public abstract long getId()

Returns the current unique ID as issued by this UniqueIdGenerator EJB.

This method is implemented by the EJB 2.0 compliant container.

Returns:
a long indicating the current unique ID as issied by this UniqueIdGenerator EJB.

setId

public abstract void setId(long id)

Sets the unique ID for this UniqueIdGenerator EJB to the given long value. Note that this method should not be made available via the EJB's remote interface.

This method is implemented by the EJB 2.0 compliant container.

Parameters:
id - a long specifying the new unique ID value.

nextId

public long nextId()

Generates the next unique ID . The method returns the new unique ID value.

Returns:
a long indicating the new current unique ID as issied by this UniqueIdGenerator EJB.

ejbCreate

public UniqueIdGeneratorPK ejbCreate(UniqueIdGeneratorPK key)
                              throws CreateException

Creates a new UniqueIdGenerator EJB instance. The new instance will have the given key and will have its unique ID set to 0.

Parameters:
key - a UniqueIdGeneratorPK specifying the key.
Returns:
the UniqueIdGeneratorPK uniquely identifying this UniqueIdGenerator EJBinstance.
Throws:
CreateException - if the new instance could not be created, for whatever reason.

ejbPostCreate

public void ejbPostCreate(UniqueIdGeneratorPK key)
                   throws CreateException

Executed after the create operation has completed. Does nothing.

Parameters:
key - a UniqueIdGeneratorPK specifying the key.
Throws:
CreateException - if the method not be executed, for whatever reason (for example, because a UniqueIdGenerator with the same key already exists).

setEntityContext

public void setEntityContext(EntityContext ctx)

Sets the private entity context of this instance. The container invokes this method on an instance after it has been created.

Specified by:
setEntityContext in interface EntityBean
Parameters:
ctx - an EntityContext specifying the key.

unsetEntityContext

public void unsetEntityContext()

Sets the private entity context of this instance to null. The container calls this method before removing the instance.

Specified by:
unsetEntityContext in interface EntityBean

ejbLoad

public void ejbLoad()

The container invokes this method to instruct the instance to synchronize its state by loading its state from the underlying database. Does nothing.

Specified by:
ejbLoad in interface EntityBean

ejbStore

public void ejbStore()

The container invokes this method to instruct the instance to synchronize its state by storing it to the underlying database. Does nothing.

Specified by:
ejbStore in interface EntityBean

ejbRemove

public void ejbRemove()

The container invokes this method before it removes the EJB object that is currently associated with the instance. This method is invoked when a client invokes a remove operation on the enterprise Bean's home interface or the EJB object's remote interface.

This transitions the instance from the ready state to the pool of available instances.

Specified by:
ejbRemove in interface EntityBean

ejbActivate

public void ejbActivate()

Invoked when the instance is taken out of the pool of available instances to become associated with a specific EJB object.

This transitions the instance to the ready state.

Specified by:
ejbActivate in interface EntityBean

ejbPassivate

public void ejbPassivate()

A container invokes this method on an instance before the instance becomes disassociated with a specific EJB object.

After this method completes, the container will place the instance into the pool of available instances.

Specified by:
ejbPassivate in interface EntityBean

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK