Advanced Database Persistence for Java Examples & Reference Manual |
Database sequences are available on the majority of databases—MySQL being a notable exception. Their purpose if to provide unique numbers to identify database elements, usually table rows.
Most of the time sequences are used to generate primary key values and
are used in tandem with SQL insert statements. HotRod's
<auto-generated-column>
tag on the
<table>
tag implements this functionality.
However, some times the application may have a need to retrieve sequential numbers for other purposes than immediately—or ever—inserting a row into a table. It could be the row may be eventually inserted after some other conditions are met, but the sequence number is needed right away for some purpose. It could be sequential numbers are needed to generate unique files in the file system, or to send identification numbers over the network to communicate with other applications.
Whatever the need is, sequences can provide unique numeric values to the Java application.
In HotRod one or more
<sequence>
tag can be added to any
<table>
,
<view>
, or
<dao>
tag to produce Java methods that retrieve a sequence value from the
database sequence.
HotRod doesn't impose or require any relationship to exist between
the sequence used by the
<sequence>
tag and the
<table>
,
<view>
, or
<dao>
tags. The DAO Java classes produced by these tags only serve as
containers to place the Java methods that retrieve the sequence
values.
The
<sequence>
tag attributes are:
Attribute | Description | Required |
---|---|---|
name | The name of the database sequence. | Yes |
java-method-name | The name of the DAO Java method that will retrieve the
sequence value, if different from the default name produced by
HotRod. The default method name takes the form selectSequence<name>() .
|
No |