Package org.h2.schema

# Class Sequence

java.lang.Object
org.h2.engine.DbObject
org.h2.schema.SchemaObject
org.h2.schema.Sequence

All Implemented Interfaces:
  `HasSQL`

public final class Sequence extends SchemaObject
A sequence is created using the statement CREATE SEQUENCE

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`Sequence.Cycle`
CYCLE clause and sequence state.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_CACHE_SIZE`
The default cache size for sequences.

### Fields inherited from class org.h2.engine.DbObject

`AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER`

### Fields inherited from interface org.h2.util.HasSQL

`ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS`

## Constructor Summary

Constructors
Constructor
Description
`Sequence(SessionLocal session, Schema schema, int id, String name, SequenceOptions options, boolean belongsToTable)`
Creates a new sequence.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Flush the current value to disk and close this object.
`void`
`flush(SessionLocal session)`
Flush the current value, including the margin, to disk.
`void`
`flushWithoutMargin()`
Flush the current value to disk.
`long`
`getBaseValue()`
`boolean`
`getBelongsToTable()`
`long`
`getCacheSize()`
`String`
`getCreateSQL()`
Construct the CREATE ...
`long`
`getCurrentValue()`
`Sequence.Cycle`
`getCycle()`
`TypeInfo`
`getDataType()`
`static long`
`getDefaultMaxValue(Long startValue, long increment, long[] bounds)`
Calculates default max value.
`static long`
`getDefaultMinValue(Long startValue, long increment, long[] bounds)`
Calculates default min value.
`String`
`getDropSQL()`
Construct a DROP ...
`int`
`getEffectivePrecision()`
`long`
`getIncrement()`
`long`
`getMaxValue()`
`long`
`getMinValue()`
`Value`
`getNext(SessionLocal session)`
Get the next value for this sequence.
`StringBuilder`
`getSequenceOptionsSQL(StringBuilder builder)`
Append the options part of the SQL statement to create the sequence.
`long`
`getStartValue()`
`int`
`getType()`
Get the object type.
`void`
`modify(Long baseValue, Long startValue, Long minValue, Long maxValue, Long increment, Sequence.Cycle cycle, Long cacheSize)`
Allows the base value, start value, min value, max value, increment and cache size to be updated atomically, including atomic validation.
`void`
`removeChildrenAndResources(SessionLocal session)`
Delete all dependent children objects and resources of this object.
`void`
`setBelongsToTable(boolean b)`

### Methods inherited from class org.h2.schema.SchemaObject

`getSchema, getSQL, getSQL`

### Methods inherited from class org.h2.engine.DbObject

`checkRename, getChildren, getComment, getCreateSQLForCopy, getCreateSQLForMeta, getDatabase, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toString`

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

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

### Methods inherited from interface org.h2.util.HasSQL

`getTraceSQL`

## Field Details

### DEFAULT_CACHE_SIZE

public static final int DEFAULT_CACHE_SIZE
The default cache size for sequences.

See Also:
  - Constant Field Values

## Constructor Details

### Sequence

public Sequence(SessionLocal session, Schema schema, int id, String name, SequenceOptions options, boolean belongsToTable)
Creates a new sequence.

Parameters:
  `session` - the session
  `schema` - the schema
  `id` - the object id
  `name` - the sequence name
  `options` - the sequence options
  `belongsToTable` - whether this sequence belongs to a table (for generated columns)

## Method Details

### modify

public void modify(Long baseValue, Long startValue, Long minValue, Long maxValue, Long increment, Sequence.Cycle cycle, Long cacheSize)
Allows the base value, start value, min value, max value, increment and cache size to be updated atomically, including atomic validation. Useful because setting these attributes one after the other could otherwise result in an invalid sequence state (e.g. min value > max value, start value < min value, etc).

Parameters:
  `baseValue` - the base value (`null` if restart is not requested)
  `startValue` - the new start value (`null` if no change)
  `minValue` - the new min value (`null` if no change)
  `maxValue` - the new max value (`null` if no change)
  `increment` - the new increment (`null` if no change)
  `cycle` - the new cycle value, or `null` if no change
  `cacheSize` - the new cache size (`null` if no change)

### getDefaultMinValue

public static long getDefaultMinValue(Long startValue, long increment, long[] bounds)
Calculates default min value.

Parameters:
  `startValue` - the start value of the sequence.
  `increment` - the increment of the sequence value.
  `bounds` - min and max bounds of data type of the sequence
Returns:
  min value.

### getDefaultMaxValue

public static long getDefaultMaxValue(Long startValue, long increment, long[] bounds)
Calculates default max value.

Parameters:
  `startValue` - the start value of the sequence.
  `increment` - the increment of the sequence value.
  `bounds` - min and max bounds of data type of the sequence
Returns:
  min value.

### getBelongsToTable

public boolean getBelongsToTable()

### getDataType

public TypeInfo getDataType()

### getEffectivePrecision

public int getEffectivePrecision()

### getIncrement

public long getIncrement()

### getStartValue

public long getStartValue()

### getMinValue

public long getMinValue()

### getMaxValue

public long getMaxValue()

### getCycle

public Sequence.Cycle getCycle()

### getDropSQL

public String getDropSQL()
Description copied from class: `DbObject`
Construct a DROP ... SQL statement for this object.

Overrides:
  `getDropSQL` in class `DbObject`
Returns:
  the SQL statement

### getCreateSQL

public String getCreateSQL()
Description copied from class: `DbObject`
Construct the CREATE ... SQL statement for this object.

Specified by:
  `getCreateSQL` in class `DbObject`
Returns:
  the SQL statement

### getSequenceOptionsSQL

public StringBuilder getSequenceOptionsSQL(StringBuilder builder)
Append the options part of the SQL statement to create the sequence.

Parameters:
  `builder` - the builder
Returns:
  the builder

### getNext

public Value getNext(SessionLocal session)
Get the next value for this sequence. Should not be called directly, use `SessionLocal.getNextValueFor(Sequence, org.h2.command.Prepared)` instead.

Parameters:
  `session` - the session
Returns:
  the next value

### flushWithoutMargin

public void flushWithoutMargin()
Flush the current value to disk.

### flush

public void flush(SessionLocal session)
Flush the current value, including the margin, to disk.

Parameters:
  `session` - the session

### close

public void close()
Flush the current value to disk and close this object.

### getType

public int getType()
Description copied from class: `DbObject`
Get the object type.

Specified by:
  `getType` in class `DbObject`
Returns:
  the object type

### removeChildrenAndResources

public void removeChildrenAndResources(SessionLocal session)
Description copied from class: `DbObject`
Delete all dependent children objects and resources of this object.

Specified by:
  `removeChildrenAndResources` in class `DbObject`
Parameters:
  `session` - the session

### getBaseValue

public long getBaseValue()

### getCurrentValue

public long getCurrentValue()

### setBelongsToTable

public void setBelongsToTable(boolean b)

### getCacheSize

public long getCacheSize()