org.h2.schema

## Class Sequence

- java.lang.Object
- - org.h2.engine.DbObjectBase
  - - org.h2.schema.SchemaObjectBase
    - - org.h2.schema.Sequence

All Implemented Interfaces:
  DbObject, SchemaObject

    public class Sequence
    extends SchemaObjectBase

A sequence is created using the statement CREATE SEQUENCE

### Field Summary

Fields
`static int` `DEFAULT_CACHE_SIZE` The default cache size for sequences.

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

`comment, database, trace`

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

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

### Constructor Summary

Constructors
Constructor and Description
`Sequence(Schema schema, int id, java.lang.String name, long startValue, long increment)` Creates a new sequence for an auto-increment column.
`Sequence(Schema schema, int id, java.lang.String name, java.lang.Long startValue, java.lang.Long increment, java.lang.Long cacheSize, java.lang.Long minValue, java.lang.Long maxValue, boolean cycle, boolean belongsToTable)` Creates a new sequence.

### Method Summary

Methods
`void` `checkRename()` Check if this object can be renamed.
`void` `close()` Flush the current value to disk and close this object.
`void` `flush(Session session)` Flush the current value, including the margin, to disk.
`void` `flushWithoutMargin()` Flush the current value to disk.
`boolean` `getBelongsToTable()`
`long` `getCacheSize()`
`java.lang.String` `getCreateSQL()` Build a SQL statement to re-create this object.
`java.lang.String` `getCreateSQLForCopy(Table table, java.lang.String quotedName)` Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
`long` `getCurrentValue()`
`boolean` `getCycle()`
`static long` `getDefaultMaxValue(java.lang.Long startValue, long increment)` Calculates default max value.
`static long` `getDefaultMinValue(java.lang.Long startValue, long increment)` Calculates default min value.
`java.lang.String` `getDropSQL()` Build a SQL statement to drop this object.
`long` `getIncrement()`
`long` `getMaxValue()`
`long` `getMinValue()`
`long` `getNext(Session session)` Get the next value for this sequence.
`int` `getType()` Get the object type.
`void` `modify(java.lang.Long startValue, java.lang.Long minValue, java.lang.Long maxValue, java.lang.Long increment)` Allows the start value, increment, min value and max value to be updated atomically, including atomic validation.
`void` `removeChildrenAndResources(Session session)` Remove all dependent objects and free all resources (files, blocks in files) of this object.
`void` `setBelongsToTable(boolean b)`
`void` `setCacheSize(long cacheSize)`
`void` `setCycle(boolean cycle)`

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

`getSchema, getSQL, getSQL, isHidden`

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

`getChildren, getComment, 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.engine.DbObject

`getChildren, getComment, getDatabase, getId, getName, isTemporary, rename, setComment, setTemporary`

### Field Detail

#### DEFAULT_CACHE_SIZE

    public static final int DEFAULT_CACHE_SIZE

The default cache size for sequences.

See Also:
  Constant Field Values

### Constructor Detail

#### Sequence

    public Sequence(Schema schema,
            int id,
            java.lang.String name,
            long startValue,
            long increment)

Creates a new sequence for an auto-increment column.

Parameters:
  `schema` - the schema
  `id` - the object id
  `name` - the sequence name
  `startValue` - the first value to return
  `increment` - the increment count

#### Sequence

    public Sequence(Schema schema,
            int id,
            java.lang.String name,
            java.lang.Long startValue,
            java.lang.Long increment,
            java.lang.Long cacheSize,
            java.lang.Long minValue,
            java.lang.Long maxValue,
            boolean cycle,
            boolean belongsToTable)

Creates a new sequence.

Parameters:
  `schema` - the schema
  `id` - the object id
  `name` - the sequence name
  `startValue` - the first value to return
  `increment` - the increment count
  `cacheSize` - the number of entries to pre-fetch
  `minValue` - the minimum value
  `maxValue` - the maximum value
  `cycle` - whether to jump back to the min value if needed
  `belongsToTable` - whether this sequence belongs to a table (for auto-increment columns)

### Method Detail

#### modify

    public void modify(java.lang.Long startValue,
              java.lang.Long minValue,
              java.lang.Long maxValue,
              java.lang.Long increment)

Allows the start value, increment, min value and max value 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:
  `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)

#### getDefaultMinValue

    public static long getDefaultMinValue(java.lang.Long startValue,
                          long increment)

Calculates default min value.

Parameters:
  `startValue` - the start value of the sequence.
  `increment` - the increment of the sequence value.
Returns:
  min value.

#### getDefaultMaxValue

    public static long getDefaultMaxValue(java.lang.Long startValue,
                          long increment)

Calculates default max value.

Parameters:
  `startValue` - the start value of the sequence.
  `increment` - the increment of the sequence value.
Returns:
  min value.

#### getBelongsToTable

    public boolean getBelongsToTable()

#### getIncrement

    public long getIncrement()

#### getMinValue

    public long getMinValue()

#### getMaxValue

    public long getMaxValue()

#### getCycle

    public boolean getCycle()

#### setCycle

    public void setCycle(boolean cycle)

#### getDropSQL

    public java.lang.String getDropSQL()

Description copied from class: `DbObjectBase`
Build a SQL statement to drop this object.

Specified by:
  `getDropSQL` in interface `DbObject`
Specified by:
  `getDropSQL` in class `DbObjectBase`
Returns:
  the SQL statement

#### getCreateSQLForCopy

    public java.lang.String getCreateSQLForCopy(Table table,
                                       java.lang.String quotedName)

Description copied from interface: `DbObject`
Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table

Parameters:
  `table` - the new table
  `quotedName` - the quoted name
Returns:
  the SQL statement

#### getCreateSQL

    public java.lang.String getCreateSQL()

Description copied from class: `DbObjectBase`
Build a SQL statement to re-create this object.

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

#### getNext

    public long getNext(Session session)

Get the next value for this sequence.

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

#### flushWithoutMargin

    public void flushWithoutMargin()

Flush the current value to disk.

#### flush

    public void flush(Session 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 interface: `DbObject`
Get the object type.

Returns:
  the object type

#### removeChildrenAndResources

    public void removeChildrenAndResources(Session session)

Description copied from class: `DbObjectBase`
Remove all dependent objects and free all resources (files, blocks in files) of this object.

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

#### checkRename

    public void checkRename()

Description copied from class: `DbObjectBase`
Check if this object can be renamed. System objects may not be renamed.

Specified by:
  `checkRename` in interface `DbObject`
Specified by:
  `checkRename` in class `DbObjectBase`

#### getCurrentValue

    public long getCurrentValue()

#### setBelongsToTable

    public void setBelongsToTable(boolean b)

#### setCacheSize

    public void setCacheSize(long cacheSize)

#### getCacheSize

    public long getCacheSize()