|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.AbstractDataSourceBlockIdGenerator
org.apache.avalon.excalibur.datasource.ids.TableIdGenerator
public class TableIdGenerator
The TableIdGenerator requests blocks of ids from a Database table. The table consists of two
columns one called table_name
of type CHAR or VARCHAR, and the second called
next_id
of an integer type large enough to hold your largest ids.
The Configuration to use a TableIdGenerator looks like the following:
<id-generators> <table name="user-ids" big-decimals="true" block-size="1" table="ids" key-table="event-type" logger="cm.ids"> <dbpool>user-db</dbpool> </table> </id-generators>Where user-db is the name of a DataSource configured in a datasources element, block-size is the number if ids that are allocated with each query to the databse (defaults to "10"), table is the name of the table which contains the ids (defaults to "ids"), and key-table is the table_name of the row from which the block of ids are allocated (defaults to "id").
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="table" class="org.apache.avalon.excalibur.datasource.ids.TableIdGenerator"/> </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.
Depending on your database, the ids table should look something like the following:
CREATE TABLE ids ( table_name varchar(16) NOT NULL, next_id INTEGER NOT NULL, PRIMARY KEY (table_name) );
Field Summary | |
---|---|
private java.lang.String |
m_table
The name of the table containing the ids. |
private java.lang.String |
m_tableName
TableName used to reference which ids to allocate. |
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 | |
---|---|
TableIdGenerator()
|
Method Summary | |
---|---|
protected java.math.BigDecimal |
allocateBigDecimalIdBlock(int blockSize)
Allocates a block, of the given size, of ids from the database. |
private java.lang.Object |
allocateIdBlock(int blockSize,
boolean useBigDecimals)
Allocates a block of ids of the given size and returns the first id. |
protected 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. |
Methods inherited from class org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceBlockIdGenerator |
---|
getNextBigDecimalIdInner, getNextLongIdInner, initialize |
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 |
---|
private java.lang.String m_table
private java.lang.String m_tableName
Constructor Detail |
---|
public TableIdGenerator()
Method Detail |
---|
private java.lang.Object allocateIdBlock(int blockSize, boolean useBigDecimals) throws IdException
blockSize
- number of ids to allocate.useBigDecimals
- returns the first id as a BigDecimal if true, otherwise as a Long.
IdException
- if a block of ids can not be allocated.protected java.math.BigDecimal allocateBigDecimalIdBlock(int blockSize) throws IdException
allocateBigDecimalIdBlock
in class AbstractDataSourceBlockIdGenerator
blockSize
- number of Ids which are to be allocated.
IdException
- if there it was not possible to allocate a block of ids.protected long allocateLongIdBlock(int blockSize) throws IdException
allocateLongIdBlock
in class AbstractDataSourceBlockIdGenerator
blockSize
- number of Ids which are to be allocated.
IdException
- if there it was not possible to allocate a block of ids.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.Configurable
configure
in class AbstractDataSourceBlockIdGenerator
configuration
- configuration info used to setup the component.
org.apache.avalon.framework.configuration.ConfigurationException
- if there are any problems with the configuration.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |