private SqlNumber NextValue(ObjectName name)
{
lock (this) {
var sequence = (Sequence)GetSequence(name);
if (sequence.SequenceInfo.Type == SequenceType.Native)
// Native generator
return Transaction.NextTableId(name);
// Custom sequence generator
var currentVal = sequence.CurrentValue;
// Increment the current value.
sequence.IncrementCurrentValue();
// Have we reached the current cached point?
if (currentVal == sequence.LastValue) {
// Increment the generator
for (int i = 0; i < sequence.SequenceInfo.Cache; ++i) {
sequence.IncrementLastValue();
}
// Update the state
UpdateSequenceState(sequence);
}
return sequence.CurrentValue;
}
}