Dynamo includes a full-featured IdGenerator implementation that can be used in a distributed system. This component, located at /atg/dynamo/service/IdGenerator and with a class name atg.service.idgen.SQLIdGenerator, uses an IdSpace to reserve a batch of IDs. Because of the way that the SQLIdGenerator stores information about IdSpaces in a database table, SQLIdGenerators operating in different Dynamo servers can independently assign IDs while being assured that the IDs are unique across the system.

Using IdSpaces with the SQLIdGenerator

IdSpaces used by the SQLIdGenerator should define a batch-size attribute. The batch size determines how many IDs the IdGenerator should reserve. Thus, for instance, suppose you have an IdSpace with a seed of 1 and a batch size of 10000, and two IdGenerators. When the first IdGenerator starts up for the first time, it consults the IdSpace. It starts with the seed ID and reserves to itself all the IDs that start with the seed, up to the batch size, 10000. It then sets the value in the ID generator database table to 10001. When the second IdGenerator starts up, it consults the ID generator table and finds that the first available ID is now 10001. It reserves to itself all the IDs from 10001 to 20000, and sets the value in the ID generator database table to 20000. Each IdGenerator then goes about its business, reserving unique IDs as needed. When an IdGenerator has exhausted its supply of reserved IDs, it can return to the ID generator table and reserve another batch of IDs. It does not need to consult with any other IdGenerators to guarantee that its reserved IDs are unique.

Because an IdGenerator must access the database each time it gets another batch of IDs, it is best for performance purposes to make batch sizes comparatively large. As IDs are Java longs (64 bit ints), you will not run out of IDs for millions of years even with a batch size of 1 million and 1000 application restarts each day.

For example, the following XML tag defines an IdSpace named MessageIds, with a seed of 1 and a batch size of 10000:

<id-space name="MessageIds" seed="1" batch-size="10000"/>

If for some reason it is essential that your IDs be generated sequentially with no gaps for unused IDs, you can create an IdSpace like this:

<id-space name="costly_id_space" seed="0" batch-size="1"/>

However, every time you generate an ID, it requires an extra database request. Therefore, this is not generally recommended unless you use this IdSpace very infrequently.

das_id_generator Database Table

The SQLIdGenerator uses a database table to store persistently information about what portion of the IdSpace has been assigned. This table must be present when the SQLIdGenerator starts up. By default, this table is named das_id_generator. If you have a different database table with this name, problems occur unless you configure the SQLIdGenerator to use a different database table name, using the tableName property:


The ID generator table has a row for each IdSpace, and a column for each of the properties defined in the XML file for the IdSpace: name, seed, batch size, prefix, and suffix. You can also specify different values for these column names by setting the following properties of the SQLIdGenerator:

Property Name

Default Value











Each time that a SQLIdGenerator accesses the IdSpace for another batch of IDs, it increments the seed value for that ID space by the number of IDs, as specified by the batch size. So, at any given moment, the seed value of the IdSpace indicates the first ID of the next batch of IDs to be reserved.

In addition to configuring the ID generator table properties, you can configure other properties of the SQLIdGenerator:

Property Name


Type and Default Value


If true, the SQLIdGenerator can automatically create an IdSpace on each attempt to generate an ID, if it does not find one.



If no name is specified for an IdSpace, this default IdSpace is used.



Defines the properties needed to construct the default IdSpace. The properties in order are: name, seed, lastSeed, batchSize, prefix, and suffix.


loading table of contents...