Class ObjectSequenceId

java.lang.Object
org.tentackle.dbms.AbstractIdSource
org.tentackle.dbms.ObjectSequenceId
All Implemented Interfaces:
IdSource

public class ObjectSequenceId extends AbstractIdSource
An IdSource to create unique object IDs from a database sequence.

To reduce the number of roundtrips, the sequence is multiplied by a sequence-multiplier and a counter just incremented within that range.

There is one instance per sequence name, shared by all sessions. The range taken from the sequence is kept per database, i.e., per backend identity, so an application connected to several databases never hands out ids reserved in the sequence of another database.

The creation of the sequence is backend-specific. For example, Postgres expects:

CREATE SEQUENCE object_sequence_id;
Author:
harald
See Also:
  • Field Details

    • DEFAULT_NAME

      public static final String DEFAULT_NAME
      Default name of the object sequence id.
      See Also:
    • GLOBAL_MULTIPLIER

      public static final int GLOBAL_MULTIPLIER
      Default global multiplier to allow application-specific offsets.
      See Also:
    • SEQUENCE_MULTIPLIER

      public static final int SEQUENCE_MULTIPLIER
      Default sequence multiplier.
      See Also:
  • Method Details

    • get

      public static ObjectSequenceId get(String name, int sequenceMultiplier, int globalMultiplier)
      Gets a sequence id source.
      ID sources are unique by name.
      Parameters:
      name - the unique sequence name
      sequenceMultiplier - the sequence multiplier
      globalMultiplier - the global multiplier
      Returns:
      the ID source
    • get

      public static ObjectSequenceId get(String name)
      Gets a sequence id source.
      ID sources are unique by name.
      Parameters:
      name - the unique sequence name
      Returns:
      the ID source
    • isLockFree

      public boolean isLockFree()
      Description copied from interface: IdSource
      Returns whether retrieving an id is a lock-free operation.
      Returns:
      true if lock-free
    • nextId

      public long nextId(Db db)
      Description copied from interface: IdSource
      Gets the next unique ID.
      Parameters:
      db - the current session
      Returns:
      a free ID.