Sequence (Oracle - Berkeley DB Java API)
Date: 2020-06-01

Package com.sleepycat.db

## Class Sequence

- java.lang.Object
- - com.sleepycat.db.Sequence

-     public class Sequence
      extends java.lang.Object

  A Sequence handle is used to manipulate a sequence record in a database. Sequence handles are opened using the `Database.openSequence` method.

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` | Close a sequence.
    `long` | `get​(Transaction txn, int delta)` | Return the next available element in the sequence and changes the sequence value by `delta`.
    `Database` | `getDatabase()` | Return the Database handle associated with this sequence.
    `DatabaseEntry` | `getKey()` | Return the DatabaseEntry used to open this sequence.
    `SequenceStats` | `getStats​(StatsConfig config)` | Return statistical information about the sequence.
    `int` | `printStats​(StatsConfig config)` | Print statistical information about the sequence to a specified output channel (see the setMsgfile() method for more information), or passed to an application callback function (see the setMsgcall() method for more information).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### close

          public void close()
                     throws DatabaseException

      Close a sequence. Any unused cached values are lost.

      The sequence handle may not be used again after this method has been called, regardless of the method's success or failure.

      Throws:
        `DatabaseException` - if a failure occurs.

    - #### get

          public long get​(Transaction txn,
                          int delta)
                   throws DatabaseException

      Return the next available element in the sequence and changes the sequence value by `delta`. The value of `delta` must be greater than zero. If there are enough cached values in the sequence handle then they will be returned. Otherwise the next value will be fetched from the database and incremented (decremented) by enough to cover the `delta` and the next batch of cached values.

      The `txn` handle must be null if the sequence handle was opened with a non-zero cache size.

      For maximum concurrency, a non-zero cache size should be specified prior to opening the sequence handle, the `txn` handle should be `null`, and `SequenceConfig.setAutoCommitNoSync` should be called to disable log flushes.

      Parameters:
        `txn` - For a transactional database, an explicit transaction may be specified, or null may be specified to use auto-commit. For a non-transactional database, null must be specified.

        `delta` - the amount by which to increment or decrement the sequence

      Returns:
        the next available element in the sequence
      Throws:
        `DatabaseException` - if a failure occurs.

    - #### getDatabase

          public Database getDatabase()
                               throws DatabaseException

      Return the Database handle associated with this sequence.

      Returns:
        The Database handle associated with this sequence.
      Throws:
        `DatabaseException` - if a failure occurs.

    - #### getKey

          public DatabaseEntry getKey()
                               throws DatabaseException

      Return the DatabaseEntry used to open this sequence.

      Returns:
        The DatabaseEntry used to open this sequence.
      Throws:
        `DatabaseException` - if a failure occurs.

    - #### getStats

          public SequenceStats getStats​(StatsConfig config)
                                 throws DatabaseException

      Return statistical information about the sequence.

      In the presence of multiple threads or processes accessing an active sequence, the information returned by this method may be out-of-date.

      The getStats method cannot be transaction-protected. For this reason, it should be called in a thread of control that has no open cursors or active transactions.

      Parameters:
        `config` - The statistics returned; if null, default statistics are returned.

      Returns:
        Sequence statistics.
      Throws:
        `DatabaseException` - if a failure occurs.

    - #### printStats

          public int printStats​(StatsConfig config)
                         throws DatabaseException

      Print statistical information about the sequence to a specified output channel (see the setMsgfile() method for more information), or passed to an application callback function (see the setMsgcall() method for more information).

      Parameters:
        `config` - The statistics returned; if null, default statistics are returned.

      Returns:
        A non-zero error value on failure and 0 on success.
      Throws:
        `DatabaseException` - if a failure occurs.

Copyright (c) 1996, 2020 Oracle and/or its affiliates. All rights reserved.