Package org.apache.torque.oid

# Interface IdGenerator

All Known Implementing Classes:
  `AbstractIdGenerator`, `AutoIncrementIdGenerator`, `IDBroker`, `SequenceIdGenerator`

public interface IdGenerator
Interface to be implemented by id generators. It is possible that some implementations might not require all the arguments, for example MySQL will not require a keyInfo Object, while the IDBroker implementation does not require a Connection as it only rarely needs one and retrieves a connection from the Connection pool service only when needed.

Version:
  $Id: IdGenerator.java 1850586 2019-01-06 18:46:35Z tv $
Author:
  John D. McNally

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BigDecimal`
  `getIdAsBigDecimal(Connection connection, Object keyInfo)`
  Returns an id as a BigDecimal.
  `int`
  `getIdAsInt(Connection connection, Object keyInfo)`
  Returns an id as a primitive int.
  `long`
  `getIdAsLong(Connection connection, Object keyInfo)`
  Returns an id as a primitive long.
  `String`
  `getIdAsString(Connection connection, Object keyInfo)`
  Returns an id as a String.
  `boolean`
  `isConnectionRequired()`
  A flag to determine whether a Connection is required to generate an id.
  `boolean`
  `isGetGeneratedKeysSupported()`
  A flag to determine whether Statement#getGeneratedKeys() should be used.
  `boolean`
  `isPostInsert()`
  A flag to determine the timing of the id generation
  `boolean`
  `isPriorToInsert()`
  A flag to determine the timing of the id generation

- ## Method Details

  - ### getIdAsInt

    int getIdAsInt(Connection connection, Object keyInfo) throws TorqueException
    Returns an id as a primitive int. If you use numeric identifiers, it's suggested that `getIdAsLong(Connection, Object)` be used instead (due to the limited range of this method).
    Parameters:
      `connection` - The database connection to use.
      `keyInfo` - an Object that contains additional info.
    Returns:
      The id as integer.
    Throws:
      `TorqueException` - if a Database error occurs.

  - ### getIdAsLong

    long getIdAsLong(Connection connection, Object keyInfo) throws TorqueException
    Returns an id as a primitive long.
    Parameters:
      `connection` - The database connection to use.
      `keyInfo` - an Object that contains additional info.
    Returns:
      The id as long.
    Throws:
      `TorqueException` - if a Database error occurs.

  - ### getIdAsBigDecimal

    BigDecimal getIdAsBigDecimal(Connection connection, Object keyInfo) throws TorqueException
    Returns an id as a BigDecimal.
    Parameters:
      `connection` - The database connection to use.
      `keyInfo` - an Object that contains additional info.
    Returns:
      The id as BigDecimal.
    Throws:
      `TorqueException` - if a Database error occurs.

  - ### getIdAsString

    String getIdAsString(Connection connection, Object keyInfo) throws TorqueException
    Returns an id as a String.
    Parameters:
      `connection` - The database connection to use.
      `keyInfo` - an Object that contains additional info.
    Returns:
      The id as String.
    Throws:
      `TorqueException` - if a Database error occurs.

  - ### isPriorToInsert

    boolean isPriorToInsert()
    A flag to determine the timing of the id generation
    Returns:
      a `boolean` value

  - ### isPostInsert

    boolean isPostInsert()
    A flag to determine the timing of the id generation
    Returns:
      Whether id is availble post-`insert`.

  - ### isConnectionRequired

    boolean isConnectionRequired()
    A flag to determine whether a Connection is required to generate an id.
    Returns:
      a `boolean` value

  - ### isGetGeneratedKeysSupported

    boolean isGetGeneratedKeysSupported()
    A flag to determine whether Statement#getGeneratedKeys() should be used.
    Returns:
      a `boolean` value