org.dasein.persist
Class Sequencer

java.lang.Object
  extended by org.dasein.persist.Sequencer
Direct Known Subclasses:
DaseinSequencer

public abstract class Sequencer
extends Object

Provides a generic interface for sequence generation that may be implemented by a number of different sequence providers. You request sequencer instances by calling getInstance(String) with the name of the sequence or getInstance(Class) with the class for which the sequence should be unique. You may configure what sequencer is used through the configuration file dasein-persistence.properties. You specify a concrete sequencer using the following:
dasein.sequencer.NAME=CLASSNAME

For example:
dasein.sequencer.pageId=org.dasein.persist.DaseinSequencer

In code, you might have the following:

Sequencer seq = Sequencer.getInstance(this.class);
id = seq.next();

Last modified $Date: 2005/08/15 16:15:59 $

Version:
$Revision: 1.2 $
Author:
George Reese

Field Summary
static String PROPERTIES
           
 
Constructor Summary
Sequencer()
          Constructs an empty sequencer with no name.
 
Method Summary
static Sequencer getInstance(Class cls)
          Returns a sequencer that will provide unique identifiers across all instances of the specified class.
static Sequencer getInstance(String name)
          Looks to see if a sequencer has been generated for the sequence with the specified name.
 String getName()
           
abstract  long next()
          Generates a new unique number based on the implementation class' algorithm of choice.
 void setName(String nom)
          Sets the sequencer name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTIES

public static final String PROPERTIES
See Also:
Constant Field Values
Constructor Detail

Sequencer

public Sequencer()
Constructs an empty sequencer with no name. This constructor should be followed by a call to setName(String) before the sequencer is used.

Method Detail

getInstance

public static final Sequencer getInstance(String name)
Looks to see if a sequencer has been generated for the sequence with the specified name. If not, it will instantiate one. Multiple calls to this method with the same name are guaranteed to receive the same sequencer object. For best performance, classes should save a reference to the sequencer once they get it in order to avoid the overhead of a HashMap lookup.

Parameters:
name - the name of the desired sequencer
Returns:
the sequencer with the specified name

getInstance

public static Sequencer getInstance(Class cls)
Returns a sequencer that will provide unique identifiers across all instances of the specified class. This method is simply a convenience method for calling getInstance(String) where the name being used for the desired sequence is the name of the class passed to this method.

Parameters:
cls - the class for which unique IDs are desired
Returns:
a sequencer that generates unique IDs for the specified class

getName

public String getName()
Returns:
the name of the sequencer

next

public abstract long next()
                   throws PersistenceException
Generates a new unique number based on the implementation class' algorithm of choice. The generated number must be a Java long that is guaranteed to be unique for all sequences sharing this name.

Returns:
a unique number for the sequence of this sequencer's name
Throws:
PersistenceException - a data store error occurred while generating the number

setName

public final void setName(String nom)
Sets the sequencer name.

Parameters:
nom - the name of the sequencer


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.