Oracle ATG Web Commerce 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 Oracle ATG Web Commerce 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. For example, you might have an IdSpace
with a seed of 1 and a batch size of 10000, and two IdGenerators
. The IDGenerators execute as follows:
When the first
IdGenerator
starts, it performs the following tasks:Consults the
IdSpace
.Starts with the seed ID and reserves all IDs that start with the seed, up to the batch size, 10000.
Sets the value in the ID generator database table to 10001.
When the second
IdGenerator
starts, it performs these tasks:Consults the ID generator table and finds that the first available ID is 10001.
Reserves all IDs from 10001 to 20000
Sets the value in the ID generator database table to 20000.
When each
IdGenerator
exhausts its supply of reserved IDs, it returns to the ID generator table and reserves another batch of IDs. It does not need to consult with otherIdGenerators
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:
tableName=my_id_generator
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 an 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 | Description | Type and Default Value |
---|---|---|
| If true, the |
|
| If no name is specified for an |
|
| Defines the properties needed to construct the default |
|