public class SequenceIdGenerator extends AbstractDataSourceIdGenerator
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.| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
m_query |
m_allocated, m_dataSource, m_nextIdROLE| Constructor and Description |
|---|
SequenceIdGenerator() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
dispose, getConnection, initialize, servicegetNextBigDecimalId, getNextByteId, getNextIntegerId, getNextLongId, getNextLongIdChecked, getNextShortId, isUsingBigDecimals, setUseBigDecimalsprotected java.math.BigDecimal getNextBigDecimalIdInner()
throws IdException
getNextBigDecimalIdInner in class AbstractIdGeneratorIdException - if an Id could not be allocated for any reason.protected long getNextLongIdInner()
throws IdException
getNextLongIdInner in class AbstractIdGeneratorIdException - if an Id could not be allocated for any reason.public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
configure in interface org.apache.avalon.framework.configuration.Configurableconfigure in class AbstractDataSourceIdGeneratorconfiguration - configuration info used to setup the component.org.apache.avalon.framework.configuration.ConfigurationException - if there are any problems with the configuration.