Sequences are generators that are commonly used to create identity
values or populate persistent fields. The package-level
sequence
element defines a named sequence. It has
no child elements other than possible extension
s,
but uses the following attributes:
name
: The unqualified name of the sequence.
Classes in the same package as the sequence can use
this name as-is; classes outside of this package must refer to
the sequence by its fully-qualified name, which is the
sequence's defining package name + "." + the sequence name.
This attribute is required.
strategy
: The sequence strategy. If not
given, the implementation chooses a suitable default strategy.
The strategy must be one of:
nontransactional
: The sequence is
updated outside of the current transaction. If the
transaction rolls back, the sequence does not roll back.
transactional
: The sequence is
updated within the current transaction. If the
current transaction rolls back, the sequence also
rolls back. Transactional behavior is only guaranteed
for datastore transactions. All sequences may behave
like nontransactional sequences during optimistic
transactions.
contiguous
: Contiguous sequences
guarantee that consecutive values will be monotonically
increasing. All contiguous sequences are transactional.
datastore-sequence
: Names the native database
sequence from which to extract values. This attribute is
optional.
factory-class
: The fully qualified name
of a sequence factory class. This class must have a static
no-arg newInstance
method that returns
a Sequence
instance. The
Sequence
interface is covered in detail in
Chapter 16, Sequence. This attribute is
optional.
Note | |
---|---|
Kodo allows you to use a
plugin string describing one of Kodo's built-in sequence
implementations for the |
Example 15.1. Named Sequences
<?xml version="1.0"?> <orm> <package name="org.mag"> <sequence name="ArticleSeq" datastore-sequence="ART_SEQ"/> ... </package> <package name="org.mag.pub"> <sequence name="AuthorSeq" factory-class="Author$SequenceFactory"/> ... </package> <package name="org.mag.subscribe"> <sequence name="ContractSeq" strategy="transactional"/> ... </package> </orm>