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
A sequence is created using the statement
CREATE SEQUENCE
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate booleanprivate longprivate Sequence.Cycleprivate TypeInfostatic final intThe default cache size for sequences.private longprivate longprivate longprivate longprivate longprivate booleanFields 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, USERFields 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
ConstructorsConstructorDescriptionSequence(SessionLocal session, Schema schema, int id, String name, SequenceOptions options, boolean belongsToTable) Creates a new sequence. -
Method Summary
Modifier and TypeMethodDescriptionprivate longcheckOptions(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.voidclose()Flush the current value to disk and close this object.private booleandecrement(long oldBase, long newBase) voidflush(SessionLocal session) Flush the current value, including the margin, to disk.private voidflushInternal(SessionLocal session) voidFlush the current value to disk.longbooleanlongConstruct the CREATE ...getCreateSQLForCopy(Table table, 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 tablelonggetCycle()static longgetDefaultMaxValue(Long startValue, long increment, long[] bounds) Calculates default max value.static longgetDefaultMinValue(Long startValue, long increment, long[] bounds) Calculates default min value.Construct a DROP ...intlongprivate static longgetMaxCacheSize(long range, long increment) longlonggetNext(SessionLocal session) Get the next value for this sequence.getSequenceOptionsSQL(StringBuilder builder) Append the options part of the SQL statement to create the sequence.private StringBuildergetSequenceOptionsSQL(StringBuilder builder, long value) longintgetType()Get the object type.private booleanincrement(long oldBase, long newBase) voidmodify(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.voidremoveChildrenAndResources(SessionLocal session) Delete all dependent children objects and resources of this object.voidsetBelongsToTable(boolean b) Methods inherited from class org.h2.schema.SchemaObject
getSchema, getSQL, getSQL, isHiddenMethods inherited from class org.h2.engine.DbObject
checkRename, getChildren, getComment, getCreateSQLForMeta, getDatabase, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
Field Details
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZEThe default cache size for sequences.- See Also:
-
baseValue
private long baseValue -
margin
private long margin -
dataType
-
increment
private long increment -
cacheSize
private long cacheSize -
startValue
private long startValue -
minValue
private long minValue -
maxValue
private long maxValue -
cycle
-
belongsToTable
private boolean belongsToTable -
writeWithMargin
private boolean writeWithMargin
-
-
Constructor Details
-
Sequence
public Sequence(SessionLocal session, Schema schema, int id, String name, SequenceOptions options, boolean belongsToTable) Creates a new sequence.- Parameters:
session- the sessionschema- the schemaid- the object idname- the sequence nameoptions- the sequence optionsbelongsToTable- 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 (nullif restart is not requested)startValue- the new start value (nullif no change)minValue- the new min value (nullif no change)maxValue- the new max value (nullif no change)increment- the new increment (nullif no change)cycle- the new cycle value, ornullif no changecacheSize- the new cache size (nullif no change)
-
checkOptions
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- the prospective base valuestartValue- the prospective start valueminValue- the prospective min valuemaxValue- the prospective max valueincrement- the prospective incrementcacheSize- the prospective cache sizemayAdjustCacheSize- whether cache size may be adjusted, cache size 0 is adjusted unconditionally to 1- Returns:
- the prospective or adjusted cache size
-
getMaxCacheSize
private static long getMaxCacheSize(long range, long increment) -
getDefaultMinValue
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
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
-
getEffectivePrecision
public int getEffectivePrecision() -
getIncrement
public long getIncrement() -
getStartValue
public long getStartValue() -
getMinValue
public long getMinValue() -
getMaxValue
public long getMaxValue() -
getCycle
-
getDropSQL
Description copied from class:DbObjectConstruct a DROP ... SQL statement for this object.- Overrides:
getDropSQLin classDbObject- Returns:
- the SQL statement
-
getCreateSQLForCopy
Description copied from class:DbObjectBuild 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- Specified by:
getCreateSQLForCopyin classDbObject- Parameters:
table- the new tablequotedName- the quoted name- Returns:
- the SQL statement
-
getCreateSQL
Description copied from class:DbObjectConstruct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQLin classDbObject- Returns:
- the SQL statement
-
getSequenceOptionsSQL
Append the options part of the SQL statement to create the sequence.- Parameters:
builder- the builder- Returns:
- the builder
-
getSequenceOptionsSQL
-
getNext
Get the next value for this sequence. Should not be called directly, useSessionLocal.getNextValueFor(Sequence, org.h2.command.Prepared)instead.- Parameters:
session- the session- Returns:
- the next value
-
increment
private boolean increment(long oldBase, long newBase) -
decrement
private boolean decrement(long oldBase, long newBase) -
flushWithoutMargin
public void flushWithoutMargin()Flush the current value to disk. -
flush
Flush the current value, including the margin, to disk.- Parameters:
session- the session
-
flushInternal
-
close
public void close()Flush the current value to disk and close this object. -
getType
public int getType()Description copied from class:DbObjectGet the object type. -
removeChildrenAndResources
Description copied from class:DbObjectDelete all dependent children objects and resources of this object.- Specified by:
removeChildrenAndResourcesin classDbObject- Parameters:
session- the session
-
getBaseValue
public long getBaseValue() -
getCurrentValue
public long getCurrentValue() -
setBelongsToTable
public void setBelongsToTable(boolean b) -
getCacheSize
public long getCacheSize()
-