Interface SequenceSupport

All Known Implementing Classes:
ANSISequenceSupport, DB2SequenceSupport, NextvalSequenceSupport

@SPI({USE,IMPLEMENT,SUPPLY}) public interface SequenceSupport

Defines database sequence value expressions and lifecycle DDL for a Dialect.

Implement every database-specific difference as one stable, thread-safe strategy. The default methods provide ordinary single-statement create, drop, next-value, and restart grammar. Override the multi-statement methods only when one logical operation requires more than one SQL command.

An increment size of zero is invalid. Preserve the optional sequence-options fragment exactly once, and use null nowhere as a capability signal; databases without sequences must use SequenceSupports.none().

Since:
8.0
See Also:
  • Method Details

    • supportsSequences

      default boolean supportsSequences()
      Report whether this strategy represents a database with sequences.
      Returns:
      true when sequences are supported
    • supportsPooledSequences

      default boolean supportsPooledSequences()
      Report whether sequence creation accepts explicit initial and increment values.
      Returns:
      true when pooled sequence definitions are supported
      See Also:
    • getSelectSequenceNextValString

      String getSelectSequenceNextValString(String sequenceName) throws MappingException
      Render the expression which obtains the next value inside another SQL statement. Do not include a surrounding select statement.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the next-value expression
      Throws:
      MappingException - when the operation is unsupported
    • getSelectSequencePreviousValString

      default String getSelectSequencePreviousValString(String sequenceName) throws MappingException
      Render the expression which obtains the previous value inside another SQL statement. Override this method only when the database exposes such an expression.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the previous-value expression
      Throws:
      MappingException - when the operation is unsupported
    • getSequenceNextValString

      default String getSequenceNextValString(String sequenceName) throws MappingException
      Render a stand-alone statement which obtains the next sequence value.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the next-value statement
      Throws:
      MappingException - when the operation is unsupported
    • getSequencePreviousValString

      default String getSequencePreviousValString(String sequenceName) throws MappingException
      Render a stand-alone statement which obtains the previous sequence value.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the previous-value statement
      Throws:
      MappingException - when the operation is unsupported
    • getFromDual

      default String getFromDual()
      Return the optional relation fragment appended to default stand-alone value-selection statements, including any required leading whitespace.
    • getSequenceNextValString

      default String getSequenceNextValString(String sequenceName, int increment) throws MappingException
      Render a stand-alone next-value statement for databases whose selection syntax depends on the configured increment.
      Parameters:
      sequenceName - the qualified sequence name
      increment - the configured increment
      Returns:
      the next-value statement
      Throws:
      MappingException - when the operation is unsupported
    • getCreateSequenceStrings

      default String[] getCreateSequenceStrings(String sequenceName, int initialValue, int incrementSize, String options) throws MappingException
      Render every command required to create a pooled sequence, appending a non-empty options fragment exactly once to the final default command. Override this method when creation requires multiple commands.
      Parameters:
      sequenceName - the qualified sequence name
      initialValue - the initial sequence value
      incrementSize - the nonzero sequence increment
      options - the optional trailing SQL fragment
      Returns:
      the ordered sequence-creation commands
      Throws:
      MappingException - when the operation is unsupported or the increment is zero
    • getCreateSequenceStrings

      default String[] getCreateSequenceStrings(String sequenceName, int initialValue, int incrementSize) throws MappingException
      Render every command required to create a pooled sequence without an options fragment.
      Parameters:
      sequenceName - the qualified sequence name
      initialValue - the initial sequence value
      incrementSize - the nonzero sequence increment
      Returns:
      the ordered sequence-creation commands
      Throws:
      MappingException - when the operation is unsupported or the increment is zero
    • getCreateSequenceString

      default String getCreateSequenceString(String sequenceName) throws MappingException
      Render the single command which creates a sequence with database-default allocation. Override the multi-command form instead when one logical creation requires multiple commands.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the sequence-creation command
      Throws:
      MappingException - when the operation is unsupported
    • getCreateSequenceString

      default String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) throws MappingException
      Render the single command which creates a sequence with explicit allocation. Reject an increment of zero and include any required sign-sensitive starting bound returned by startingValue(int, int).
      Parameters:
      sequenceName - the qualified sequence name
      initialValue - the initial sequence value
      incrementSize - the nonzero sequence increment
      Returns:
      the sequence-creation command
      Throws:
      MappingException - when the operation is unsupported or the increment is zero
    • getDropSequenceStrings

      default String[] getDropSequenceStrings(String sequenceName) throws MappingException
      Render every command required to drop a sequence.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the ordered sequence-drop commands
      Throws:
      MappingException - when the operation is unsupported
    • getDropSequenceString

      default String getDropSequenceString(String sequenceName) throws MappingException
      Render the single command which drops a sequence. Override the multi-command form instead when one logical drop requires several commands.
      Parameters:
      sequenceName - the qualified sequence name
      Returns:
      the sequence-drop command
      Throws:
      MappingException - when the operation is unsupported
    • getRestartSequenceString

      default String getRestartSequenceString(String sequenceName, long startWith)
      Render the DDL command which restarts a sequence at a specified value.
      Parameters:
      sequenceName - the qualified sequence name
      startWith - the value returned by the next sequence access
      Returns:
      the sequence-restart command
    • sometimesNeedsStartingValue

      default boolean sometimesNeedsStartingValue()
      Report whether creation must state minvalue or maxvalue when the initial value and increment direction cross zero.
    • startingValue

      default String startingValue(int initialValue, int incrementSize)
      Render the sign-sensitive starting bound required by this strategy. Return an empty fragment when no explicit bound is needed.
      Parameters:
      initialValue - the initial sequence value
      incrementSize - the sequence increment
      Returns:
      a fragment including its own leading whitespace, or an empty string