Skip Headers

# Using the Platform Default Sequence

Previous

Next

After you configure your login with a platform (see "Configuring a Relational Database Platform at the Session Level"), you can use the default sequence that the platform provides.

If you associate a descriptor with an unspecified sequence, the TopLink runtime will create an instance of `DefaultSequence` to provide sequencing for that descriptor. For more information, see "Configuring the Platform Default Sequence".

You can access the default platform sequence directly as Example: Accessing the Platform Default Sequence shows. For example, by default, a `DatabasePlatform` creates a table sequence using the default table and column names (see "Table Sequencing").

Accessing the Platform Default Sequence

    // assume that dbLogin owns a DatabasePlatform
    TableSequence tableSeq2 = ((TableSequence)dbLogin.getDefaultSequence()).clone();
    tableSeq2.setName("EMP_SEQ");
    tableSeq2.setPreallocationSize(75);
    dbLogin.addSequence(tableSeq2);

To avoid having to clone the platform default sequence, you can use the `DefaultSequence` class–a wrapper for the platform default sequence–as Example: Using the DefaultSequence Class shows. The new sequence named `EMP_SEQ` will be of the same type as the platform default sequence.

Using the DefaultSequence Class

    login.addSequence(
        new DefaultSequence("EMP_SEQ", 75)
    );

You can override the default platform sequence as Example: Overriding the Platform Default Sequence shows. In this example, `dbLogin` owns a `DatabasePlatform` that provides a default sequence of type `TableSequence`. After setting the default sequence to type `UnaryTableSequence`, when you use the `DefaultSequence` class, it will access the new default sequence type. In this example, the sequence named `EMP_SEQ` will be of type `UnaryTableSequence` and have a preallocation size of 75.

Overriding the Platform Default Sequence

    // assume that dbLogin owns a DatabasePlatform
    Sequence unaryTableSequence = new UnaryTableSequence();
    unaryTableSequence.setPreallocationSize(40);
    dbLogin.setDefaultSequence(unaryTableSequence);
    dbLogin.addSequence(
        new DefaultSequence("EMP_SEQ", 75) // UnaryTableSequence
    );