atg.service.idgen
Interface IdGenerator

All Known Implementing Classes:
AbstractSequentialIdGenerator, FileIdGenerator, ObfuscatedSQLIdGenerator, PersistentIdGenerator, SQLIdGenerator, TransientIdGenerator

public interface IdGenerator

Facility that generates ids as both Strings and longs. IdGenerators support the concept of an id space. Ids are unique within an id space, but not necessarily across id spaces. This allows a single id generator to generate ids for a related set of objects.

Users of an IdGenerator need not be aware that id spaces exist. All id generators support a default id space which is assumed when no other id space is specified. Additionality, id generators are responsible for initializing the default id space.

Implementations add functionality like: the ability to generate id that are unique in a distributed system; and user defined hooks to modify or filter generated ids.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Method Summary
 boolean addIdSpace(IdSpace pSpace)
          Add an id space to the id generator.
 long generateLongId()
          Generate a long id in the default name space.
 long generateLongId(java.lang.String pIdSpace)
          Generate a long id in the specified name space.
 java.lang.String generateStringId()
          Generate a String id in the default name space.
 java.lang.String generateStringId(java.lang.String pIdSpace)
          Generate a string id in the specified name space.
 boolean getAutoCreate()
          Get property autoCreate
 IdSpace getDefaultIdSpace()
          Get property DefaultIdSpace
 IdSpace getIdSpace(java.lang.String pName)
          Get a copy of the named id space from the generator.
 java.util.Map getIdSpaces()
          Get a copy of all the spaces defined in the generator.
 void initialize()
          Initialize the generator, preparing it to generate ids.
 boolean isAutoCreate()
          Test property autoCreate
 void removeAllIdSpaces()
          Remove all id spaces from the id generator.
 boolean removeIdSpace(IdSpace pSpace)
          Remove an id space from the id generator.
 void setAutoCreate(boolean pAutoCreate)
          Set property autoCreate
 

Field Detail

CLASS_VERSION

static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values
Method Detail

getDefaultIdSpace

IdSpace getDefaultIdSpace()
Get property DefaultIdSpace

Returns:
DefaultIdSpace

generateLongId

long generateLongId()
                    throws IdGeneratorException
Generate a long id in the default name space.

Returns:
the id
Throws:
IdGeneratorException - if there is an error generating the id

generateStringId

java.lang.String generateStringId()
                                  throws IdGeneratorException
Generate a String id in the default name space.

Returns:
the id
Throws:
IdGeneratorException - if there is an error generating the id

generateLongId

long generateLongId(java.lang.String pIdSpace)
                    throws IdGeneratorException
Generate a long id in the specified name space.

Parameters:
pIdSpace - name of id space to use, null means use the anonymous, default space
Returns:
the new id, or -1 if the id space is not recognized
Throws:
IdGeneratorException - if there is an error generating the id

generateStringId

java.lang.String generateStringId(java.lang.String pIdSpace)
                                  throws IdGeneratorException
Generate a string id in the specified name space.

Parameters:
pIdSpace - name of id space to use, null means use the anonymous, default space
Returns:
the new id
Throws:
IdGeneratorException - if there is an error generating the id

getIdSpace

IdSpace getIdSpace(java.lang.String pName)
Get a copy of the named id space from the generator.

Parameters:
name - of id space to get
Returns:
a copy of the named id space, or null if not found

getIdSpaces

java.util.Map getIdSpaces()
Get a copy of all the spaces defined in the generator.

Returns:
a Map of all the id spaces defined in the generator. The keys of the Map are the names of the spaces, and the values are IdSpace objects

addIdSpace

boolean addIdSpace(IdSpace pSpace)
                   throws IdGeneratorException
Add an id space to the id generator. The id space must not be null.

Parameters:
pSpace - space to add, cannot be null
Returns:
true if the space is added, or false if a space with the same name already exists in this id generator
Throws:
IdGeneratorException - if there is trouble adding the space

setAutoCreate

void setAutoCreate(boolean pAutoCreate)
Set property autoCreate

Parameters:
pAutoCreate - new value to set

getAutoCreate

boolean getAutoCreate()
Get property autoCreate

Returns:
autoCreate

isAutoCreate

boolean isAutoCreate()
Test property autoCreate

Returns:
autoCreate

removeIdSpace

boolean removeIdSpace(IdSpace pSpace)
                      throws IdGeneratorException
Remove an id space from the id generator. The id space must not be null. Removing an id space causes information associated with that id space to be lost. Take care that no facility is still using an id space before removing it.

Parameters:
pSpace - space to remove, cannot be null
Returns:
true if the space is removed, or false if it is not known to this id generator
Throws:
java.lang.IllegalArgumentException - if the specified space is null or otherwise invalid
IdGeneratorException - if there is trouble removing the space

removeAllIdSpaces

void removeAllIdSpaces()
                       throws IdGeneratorException
Remove all id spaces from the id generator. Removing id spaces causes information associated with those id spaces to be lost. Take care that no facility is still using any of the id spaces before removing them.

Throws:
IdGeneratorException - if there is trouble removing the spaces

initialize

void initialize()
                throws IdGeneratorException
Initialize the generator, preparing it to generate ids. After initialize() completes, the generator is ready for use. Therefore initialize must at the least ensure that the default id space is set up.

Throws:
IdGeneratorException - if there is an error initializing