org.apache.avalon.excalibur.datasource.ids
Class SequenceIdGenerator
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.excalibur.datasource.ids.AbstractIdGenerator
org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceIdGenerator
org.apache.avalon.excalibur.datasource.ids.SequenceIdGenerator
- All Implemented Interfaces:
- Component, Configurable, Disposable, IdGenerator, Initializable, LogEnabled, Serviceable, ThreadSafe
- public class SequenceIdGenerator
- extends AbstractDataSourceIdGenerator
The SequenceIdGenerator requests each Id using a sequence in a database. While not
actually pooling batches of Ids like other IdGenerator implementations, making use of this class
does make code compatable with other IdGenerators on a configuration basis.
The Configuration to use a SequenceIdGenerator look like the following:
<id-generators>
<sequence name="user-ids" logger="cm.ids">
<dbpool>user-db</dbpool>
<query>SELECT NEXTVAL('category_ids')</query>
</sequence>
</id-generators>
or
<id-generators>
<sequence name="user-ids" logger="cm.ids">
<dbpool>user-db</dbpool>
<query>SELECT category_ids.nextval FROM DUAL</query>
</sequence>
</id-generators>
Where user-db is the name of a DataSource configured in a datasources element, and query is
any query which will return a single id while maintaining state so that successive calls
will continue to return incremented ids.
With the following roles declaration:
<role name="org.apache.avalon.excalibur.datasource.ids.IdGeneratorSelector"
shorthand="id-generators"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
<hint shorthand="sequence"
class="org.apache.avalon.excalibur.datasource.ids.SequenceIdGenerator"/>
</role>
To configure your component to use the IdGenerator declared above, its configuration should look
something like the following:
<user-service logger="cm">
<dbpool>user-db</dbpool>
<id-generator>user-ids</id-generator>
</user-service>
Your component obtains a reference to an IdGenerator using the same method as it obtains a
DataSource, by making use of a ComponentSelector.
- Since:
- 4.1
- Version:
- CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:17 $
- Author:
- Avalon Development Team
Fields inherited from interface org.apache.avalon.excalibur.datasource.ids.IdGenerator |
ROLE |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SequenceIdGenerator
public SequenceIdGenerator()
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(Configuration configuration)
throws ConfigurationException
- Called by the Container to configure the component.
- Specified by:
configure
in interface Configurable
- Overrides:
configure
in class AbstractDataSourceIdGenerator
- Parameters:
configuration
- configuration info used to setup the component.
- Throws:
ConfigurationException
- if there are any problems with the configuration.
Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.