org.apache.avalon.excalibur.datasource.ids
Class AbstractIdGenerator

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.excalibur.datasource.ids.AbstractIdGenerator
All Implemented Interfaces:
Component, IdGenerator, LogEnabled, ThreadSafe
Direct Known Subclasses:
AbstractDataSourceIdGenerator

public abstract class AbstractIdGenerator
extends AbstractLogEnabled
implements IdGenerator, ThreadSafe

Since:
4.1
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:17 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.excalibur.datasource.ids.IdGenerator
ROLE
 
Constructor Summary
AbstractIdGenerator()
           
 
Method Summary
 java.math.BigDecimal getNextBigDecimalId()
          Returns the next Id from the pool.
protected abstract  java.math.BigDecimal getNextBigDecimalIdInner()
          Gets the next id as a Big Decimal.
 byte getNextByteId()
          Returns the next Id from the pool.
 int getNextIntegerId()
          Returns the next Id from the pool.
 long getNextLongId()
          Returns the next Id from the pool.
protected  long getNextLongIdChecked(long maxId)
          Gets the next Long Id constraining the value to be less than the specified maxId.
protected abstract  long getNextLongIdInner()
          Gets the next id as a long.
 short getNextShortId()
          Returns the next Id from the pool.
protected  boolean isUsingBigDecimals()
          Returns true if the internal data type is using BigDecimals, false if it is using longs.
protected  void setUseBigDecimals(boolean useBigDecimals)
          By default, the IdGenerator will operate using a backend datatype of type long.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIdGenerator

public AbstractIdGenerator()
Method Detail

getNextBigDecimalIdInner

protected abstract java.math.BigDecimal getNextBigDecimalIdInner()
                                                          throws IdException
Gets the next id as a Big Decimal. This method will only be called when synchronized and when the data type is configured to be BigDecimal.

Returns:
the next id as a BigDecimal.
Throws:
IdException - if an Id could not be allocated for any reason.

getNextLongIdInner

protected abstract long getNextLongIdInner()
                                    throws IdException
Gets the next id as a long. This method will only be called when synchronized and when the data type is configured to be long.

Returns:
the next id as a long.
Throws:
IdException - if an Id could not be allocated for any reason.

setUseBigDecimals

protected final void setUseBigDecimals(boolean useBigDecimals)
By default, the IdGenerator will operate using a backend datatype of type long. This is the most efficient, however it does not allow for Ids that are larger than Long.MAX_VALUE. To allow very large Ids, it is necessary to make use of the BigDecimal data storage type. This method should only be called durring initialization.

Parameters:
useBigDecimals - True to set BigDecimal as the internal data type.

isUsingBigDecimals

protected final boolean isUsingBigDecimals()
Returns true if the internal data type is using BigDecimals, false if it is using longs.


getNextLongIdChecked

protected final long getNextLongIdChecked(long maxId)
                                   throws IdException
Gets the next Long Id constraining the value to be less than the specified maxId.

Throws:
IdException - if the next id is larger than the specified maxId.

getNextBigDecimalId

public final java.math.BigDecimal getNextBigDecimalId()
                                               throws IdException
Returns the next Id from the pool.

Specified by:
getNextBigDecimalId in interface IdGenerator
Returns:
the next Id.
Throws:
IdException

getNextLongId

public final long getNextLongId()
                         throws IdException
Returns the next Id from the pool.

Specified by:
getNextLongId in interface IdGenerator
Returns:
the next Id.
Throws:
IdException - if the next id is outside of the range of valid longs.

getNextIntegerId

public final int getNextIntegerId()
                           throws IdException
Returns the next Id from the pool.

Specified by:
getNextIntegerId in interface IdGenerator
Returns:
the next Id.
Throws:
IdException - if the next id is outside of the range of valid integers.

getNextShortId

public final short getNextShortId()
                           throws IdException
Returns the next Id from the pool.

Specified by:
getNextShortId in interface IdGenerator
Returns:
the next Id.
Throws:
IdException - if the next id is outside of the range of valid shorts.

getNextByteId

public final byte getNextByteId()
                         throws IdException
Returns the next Id from the pool.

Specified by:
getNextByteId in interface IdGenerator
Returns:
the next Id.
Throws:
IdException - if the next id is outside of the range of valid bytes.


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.