Class ObjectId

All Implemented Interfaces:
IdSource

public class ObjectId extends AbstractIdSource
An IdSource to create unique object IDs.

Only used if the backend does not support sequences, or if configured explicitly via table:<name>.
The counter is kept in a table with a single row and column id.

The first ID requested within a transaction increments the counter in the database, which locks the row until the end of the transaction. Further IDs of the same transaction are counted in memory only, and the final value is written once at the end of the transaction (via a pre-commit). IDs requested from within a pre-commit are written immediately, since the final update may already have been executed by then. As a consequence, the database serializes the transactions of all sessions allocating IDs from the same table.

The counting state belongs to the transaction (it is kept as a transaction property of the session), so a single instance can safely be shared by all sessions.

Author:
harald
See Also:
  • Constructor Details

    • ObjectId

      public ObjectId(String name)
      Creates an object id.
      Parameters:
      name - the source and table name
  • Method Details

    • get

      public static ObjectId 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.
    • createStatementKey

      protected StatementKey createStatementKey(StatementId statementId)
      Creates the statement key.
      The key includes the table name, since id sources on different tables must not share their statements.
      Parameters:
      statementId - the statement id
      Returns:
      the statement key