SQLExceptionCode.MAXVALUE_MUST_BE_CONSTANT);
final long minValue =
evalExpression(sequence, context, minValueNode.accept(expressionCompiler),
SQLExceptionCode.MINVALUE_MUST_BE_CONSTANT);
if (minValue>maxValue) {
TableName sequenceName = sequence.getSequenceName();
throw SequenceUtil.getException(sequenceName.getSchemaName(),
sequenceName.getTableName(),
SQLExceptionCode.MINVALUE_MUST_BE_LESS_THAN_OR_EQUAL_TO_MAXVALUE);
}
long startsWithValue;
if (startsWithNode == null) {
startsWithValue = incrementBy > 0 ? minValue : maxValue;
} else {
startsWithValue =
evalExpression(sequence, context, startsWithNode.accept(expressionCompiler),
SQLExceptionCode.START_WITH_MUST_BE_CONSTANT);
if (startsWithValue < minValue || startsWithValue > maxValue) {
TableName sequenceName = sequence.getSequenceName();
throw SequenceUtil.getException(sequenceName.getSchemaName(),
sequenceName.getTableName(),
SQLExceptionCode.STARTS_WITH_MUST_BE_BETWEEN_MIN_MAX_VALUE);
}
}
final long startsWith = startsWithValue;
long cacheSizeValue;
if (cacheNode == null) {
cacheSizeValue =
connection
.getQueryServices()
.getProps()
.getLong(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB,
QueryServicesOptions.DEFAULT_SEQUENCE_CACHE_SIZE);
}
else {
cacheSizeValue =
evalExpression(sequence, context, cacheNode.accept(expressionCompiler),
SQLExceptionCode.CACHE_MUST_BE_NON_NEGATIVE_CONSTANT);
if (cacheSizeValue < 0) {
TableName sequenceName = sequence.getSequenceName();
throw SequenceUtil.getException(sequenceName.getSchemaName(),
sequenceName.getTableName(),
SQLExceptionCode.CACHE_MUST_BE_NON_NEGATIVE_CONSTANT);
}
}
final long cacheSize = Math.max(1L, cacheSizeValue);