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

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.avalon.excalibur.datasource.ids.AbstractIdGenerator
          extended by org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceIdGenerator
              extended by org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceBlockIdGenerator
All Implemented Interfaces:
IdGenerator, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.thread.ThreadSafe
Direct Known Subclasses:
TableIdGenerator

public abstract class AbstractDataSourceBlockIdGenerator
extends AbstractDataSourceIdGenerator

The AbstractDataSourceBlockIdGenerator allocates blocks of ids from a DataSource and then provides them as needed. This is useful in reducing communication with the DataSource.

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

Field Summary
private  int m_allocated
          The number of ids which have been allocated from the current block.
private  int m_blockSize
          The number of ids loaded in each block.
private  java.math.BigDecimal m_firstBigDecimal
          The first id in a batch of Ids loaded in from the DataSource.
private  long m_firstLong
          The first id in a batch of Ids loaded in from the DataSource.
 
Fields inherited from class org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceIdGenerator
m_dataSource, m_nextId
 
Fields inherited from interface org.apache.avalon.excalibur.datasource.ids.IdGenerator
ROLE
 
Constructor Summary
AbstractDataSourceBlockIdGenerator()
           
 
Method Summary
protected abstract  java.math.BigDecimal allocateBigDecimalIdBlock(int blockSize)
          Allocates a block, of the given size, of ids from the database.
protected abstract  long allocateLongIdBlock(int blockSize)
          Allocates a block, of the given size, of ids from the database.
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Called by the Container to configure the component.
protected  java.math.BigDecimal getNextBigDecimalIdInner()
          Gets the next id as a Big Decimal.
protected  long getNextLongIdInner()
          Gets the next id as a long.
 void initialize()
          Called by the Container to initialize the component.
 
Methods inherited from class org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceIdGenerator
dispose, getConnection, service
 
Methods inherited from class org.apache.avalon.excalibur.datasource.ids.AbstractIdGenerator
getNextBigDecimalId, getNextByteId, getNextIntegerId, getNextLongId, getNextLongIdChecked, getNextShortId, isUsingBigDecimals, setUseBigDecimals
 
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
 

Field Detail

m_firstBigDecimal

private java.math.BigDecimal m_firstBigDecimal
The first id in a batch of Ids loaded in from the DataSource.


m_firstLong

private long m_firstLong
The first id in a batch of Ids loaded in from the DataSource.


m_blockSize

private int m_blockSize
The number of ids loaded in each block.


m_allocated

private int m_allocated
The number of ids which have been allocated from the current block.

Constructor Detail

AbstractDataSourceBlockIdGenerator

public AbstractDataSourceBlockIdGenerator()
Method Detail

allocateBigDecimalIdBlock

protected abstract java.math.BigDecimal allocateBigDecimalIdBlock(int blockSize)
                                                           throws IdException
Allocates a block, of the given size, of ids from the database.

Parameters:
blockSize - number of Ids which are to be allocated.
Returns:
The first id in the allocated block.
Throws:
IdException - if there it was not possible to allocate a block of ids.

allocateLongIdBlock

protected abstract long allocateLongIdBlock(int blockSize)
                                     throws IdException
Allocates a block, of the given size, of ids from the database.

Parameters:
blockSize - number of Ids which are to be allocated.
Returns:
The first id in the allocated block.
Throws:
IdException - if there it was not possible to allocate a block of ids.

getNextBigDecimalIdInner

protected 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.

Specified by:
getNextBigDecimalIdInner in class AbstractIdGenerator
Returns:
the next id as a BigDecimal.
Throws:
IdException - if an Id could not be allocated for any reason.

getNextLongIdInner

protected 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.

Specified by:
getNextLongIdInner in class AbstractIdGenerator
Returns:
the next id as a long.
Throws:
IdException - if an Id could not be allocated for any reason.

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Called by the Container to configure the component.

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Overrides:
configure in class AbstractDataSourceIdGenerator
Parameters:
configuration - configuration info used to setup the component.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if there are any problems with the configuration.

initialize

public void initialize()
                throws java.lang.Exception
Called by the Container to initialize the component.

Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Overrides:
initialize in class AbstractDataSourceIdGenerator
Throws:
java.lang.Exception - if there were any problems durring initialization.