Top Description Inners Fields Constructors Methods
org.h2.schema

public final Class Sequence

extends SchemaObject
Class Inheritance
Imports
org.h2.api.ErrorCode, org.h2.command.ddl.SequenceOptions, org.h2.engine.DbObject, .SessionLocal, org.h2.message.DbException, .Trace, org.h2.value.TypeInfo, .Value, .ValueBigint

A sequence is created using the statement CREATE SEQUENCE

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Sequence.Cycle

CYCLE clause and sequence state.

Field Summary

Modifier and TypeField and Description
private long
private boolean
private long
private Sequence.Cycle
private TypeInfo
public static final int
DEFAULT_CACHE_SIZE

The default cache size for sequences.

private long
private long
private long
private long
private long
private boolean

Constructor Summary

AccessConstructor and Description
public
Sequence(SessionLocal
the session
session
,
Schema
the schema
schema
,
int
the object id
id
,
String
the sequence name
name
,
SequenceOptions
the sequence options
options
,
boolean
whether this sequence belongs to a table (for generated columns)
belongsToTable
)

Creates a new sequence.

Method Summary

Modifier and TypeMethod and Description
private long

Returns:

the prospective or adjusted cache size
checkOptions
(long
the prospective base value
baseValue
,
long
the prospective start value
startValue
,
long
the prospective min value
minValue
,
long
the prospective max value
maxValue
,
long
the prospective increment
increment
,
long
the prospective cache size
cacheSize
,
boolean
whether cache size may be adjusted, cache size 0 is adjusted unconditionally to 1
mayAdjustCacheSize
)

Validates the specified prospective base value, start value, min value, max value, increment, and cache size relative to each other, since each of their respective validities are contingent on the values of the other parameters.

public void
close()

Flush the current value to disk and close this object.

private boolean
decrement(long oldBase, long newBase)

public void
flush(SessionLocal
the session
session
)

Flush the current value, including the margin, to disk.

private void
public void
flushWithoutMargin()

Flush the current value to disk.

public synchronized long
public boolean
public long
public String
getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ...

public synchronized long
public Sequence.Cycle
public TypeInfo
public static long

Returns:

min value.
getDefaultMaxValue
(Long
the start value of the sequence.
startValue
,
long
the increment of the sequence value.
increment
,
long[]
min and max bounds of data type of the sequence
bounds
)

Calculates default max value.

public static long

Returns:

min value.
getDefaultMinValue
(Long
the start value of the sequence.
startValue
,
long
the increment of the sequence value.
increment
,
long[]
min and max bounds of data type of the sequence
bounds
)

Calculates default min value.

public String
getDropSQL()

Overrides org.h2.engine.DbObject.getDropSQL.

Construct a DROP ...

public int
public long
private static long
getMaxCacheSize(long range, long increment)

public long
public long
public Value

Returns:

the next value
getNext
(SessionLocal
the session
session
)

Get the next value for this sequence.

public synchronized StringBuilder

Returns:

the builder
getSequenceOptionsSQL
(StringBuilder
the builder
builder
)

Append the options part of the SQL statement to create the sequence.

private StringBuilder
getSequenceOptionsSQL(StringBuilder builder, long value)

public long
public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

private boolean
increment(long oldBase, long newBase)

public synchronized void
modify(Long
the base value (null if restart is not requested)
baseValue
,
Long
the new start value (null if no change)
startValue
,
Long
the new min value (null if no change)
minValue
,
Long
the new max value (null if no change)
maxValue
,
Long
the new increment (null if no change)
increment
,
Sequence.Cycle
the new cycle value, or null if no change
cycle
,
Long
the new cache size (null if no change)
cacheSize
)

Allows the base value, start value, min value, max value, increment and cache size to be updated atomically, including atomic validation.

public void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

public void
setBelongsToTable(boolean b)

Inherited from org.h2.schema.SchemaObject:
getSchemagetSQLgetSQL

Field Detail

baseValueback to summary
private long baseValue
belongsToTableback to summary
private boolean belongsToTable
cacheSizeback to summary
private long cacheSize
cycleback to summary
private Sequence.Cycle cycle
dataTypeback to summary
private TypeInfo dataType
DEFAULT_CACHE_SIZEback to summary
public static final int DEFAULT_CACHE_SIZE

The default cache size for sequences.

incrementback to summary
private long increment
marginback to summary
private long margin
maxValueback to summary
private long maxValue
minValueback to summary
private long minValue
startValueback to summary
private long startValue
writeWithMarginback to summary
private boolean writeWithMargin

Constructor Detail

Sequenceback to summary
public Sequence(SessionLocal session, Schema schema, int id, String name, SequenceOptions options, boolean belongsToTable)

Creates a new sequence.

Parameters
session:SessionLocal

the session

schema:Schema

the schema

id:int

the object id

name:String

the sequence name

options:SequenceOptions

the sequence options

belongsToTable:boolean

whether this sequence belongs to a table (for generated columns)

Method Detail

checkOptionsback to summary
private long checkOptions(long baseValue, long startValue, long minValue, long maxValue, long increment, long cacheSize, boolean mayAdjustCacheSize)

Validates the specified prospective base value, start value, min value, max value, increment, and cache size relative to each other, since each of their respective validities are contingent on the values of the other parameters.

Parameters
baseValue:long

the prospective base value

startValue:long

the prospective start value

minValue:long

the prospective min value

maxValue:long

the prospective max value

increment:long

the prospective increment

cacheSize:long

the prospective cache size

mayAdjustCacheSize:boolean

whether cache size may be adjusted, cache size 0 is adjusted unconditionally to 1

Returns:long

the prospective or adjusted cache size

closeback to summary
public void close()

Flush the current value to disk and close this object.

decrementback to summary
private boolean decrement(long oldBase, long newBase)
flushback to summary
public void flush(SessionLocal session)

Flush the current value, including the margin, to disk.

Parameters
session:SessionLocal

the session

flushInternalback to summary
private void flushInternal(SessionLocal session)
flushWithoutMarginback to summary
public void flushWithoutMargin()

Flush the current value to disk.

getBaseValueback to summary
public synchronized long getBaseValue()
getBelongsToTableback to summary
public boolean getBelongsToTable()
getCacheSizeback to summary
public long getCacheSize()
getCreateSQLback to summary
public String getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Doc from org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getCurrentValueback to summary
public synchronized long getCurrentValue()
getCycleback to summary
public Sequence.Cycle getCycle()
getDataTypeback to summary
public TypeInfo getDataType()
getDefaultMaxValueback to summary
public static long getDefaultMaxValue(Long startValue, long increment, long[] bounds)

Calculates default max value.

Parameters
startValue:Long

the start value of the sequence.

increment:long

the increment of the sequence value.

bounds:long[]

min and max bounds of data type of the sequence

Returns:long

min value.

getDefaultMinValueback to summary
public static long getDefaultMinValue(Long startValue, long increment, long[] bounds)

Calculates default min value.

Parameters
startValue:Long

the start value of the sequence.

increment:long

the increment of the sequence value.

bounds:long[]

min and max bounds of data type of the sequence

Returns:long

min value.

getDropSQLback to summary
public String getDropSQL()

Overrides org.h2.engine.DbObject.getDropSQL.

Doc from org.h2.engine.DbObject.getDropSQL.

Construct a DROP ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getEffectivePrecisionback to summary
public int getEffectivePrecision()
getIncrementback to summary
public long getIncrement()
getMaxCacheSizeback to summary
private static long getMaxCacheSize(long range, long increment)
getMaxValueback to summary
public long getMaxValue()
getMinValueback to summary
public long getMinValue()
getNextback to summary
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:SessionLocal

the session

Returns:Value

the next value

getSequenceOptionsSQLback to summary
public synchronized StringBuilder getSequenceOptionsSQL(StringBuilder builder)

Append the options part of the SQL statement to create the sequence.

Parameters
builder:StringBuilder

the builder

Returns:StringBuilder

the builder

getSequenceOptionsSQLback to summary
private StringBuilder getSequenceOptionsSQL(StringBuilder builder, long value)
getStartValueback to summary
public long getStartValue()
getTypeback to summary
public int getType()

Implements abstract org.h2.engine.DbObject.getType.

Doc from org.h2.engine.DbObject.getType.

Get the object type.

Returns:int

the object type

Annotations
@Override
incrementback to summary
private boolean increment(long oldBase, long newBase)
modifyback to summary
public synchronized 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:Long

the base value (null if restart is not requested)

startValue:Long

the new start value (null if no change)

minValue:Long

the new min value (null if no change)

maxValue:Long

the new max value (null if no change)

increment:Long

the new increment (null if no change)

cycle:Sequence.Cycle

the new cycle value, or null if no change

cacheSize:Long

the new cache size (null if no change)

removeChildrenAndResourcesback to summary
public void removeChildrenAndResources(SessionLocal session)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Doc from org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

Parameters
session:SessionLocal

the session

Annotations
@Override
setBelongsToTableback to summary
public void setBelongsToTable(boolean b)
org.h2.schema back to summary

public final Enum Sequence.Cycle

extends Enum<Sequence.Cycle>
Class Inheritance

CYCLE clause and sequence state.

Field Summary

Modifier and TypeField and Description
public static final Sequence.Cycle
CYCLE

Sequence is cycled.

public static final Sequence.Cycle
EXHAUSTED

Sequence is not cycled and was already exhausted.

public static final Sequence.Cycle
NO_CYCLE

Sequence is not cycled and isn't exhausted yet.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if sequence is cycled, false if sequence is not cycled
isCycle
()

Return whether sequence is cycled.

public static Sequence.Cycle
public static Sequence.Cycle[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CYCLEback to summary
public static final Sequence.Cycle CYCLE

Sequence is cycled.

EXHAUSTEDback to summary
public static final Sequence.Cycle EXHAUSTED

Sequence is not cycled and was already exhausted.

NO_CYCLEback to summary
public static final Sequence.Cycle NO_CYCLE

Sequence is not cycled and isn't exhausted yet.

Constructor Detail

Cycleback to summary
private Cycle()

Method Detail

isCycleback to summary
public boolean isCycle()

Return whether sequence is cycled.

Returns:boolean

true if sequence is cycled, false if sequence is not cycled

valueOfback to summary
public static Sequence.Cycle valueOf(String name)
valuesback to summary
public static Sequence.Cycle[] values()