Deveel.Data.Sql.Sequences.SequenceManager.CreateCustomSequence C# (CSharp) Method

CreateCustomSequence() private method

private CreateCustomSequence ( ObjectName sequenceName, SequenceInfo sequenceInfo ) : Sequence
sequenceName ObjectName
sequenceInfo SequenceInfo
return Sequence
        private Sequence CreateCustomSequence(ObjectName sequenceName, SequenceInfo sequenceInfo)
        {
            // The SEQUENCE and SEQUENCE_INFO table
            var seq = Transaction.GetMutableTable(SequenceTableName);
            var seqi = Transaction.GetMutableTable(SequenceInfoTableName);

            var list = seqi.SelectRowsEqual(2, Field.VarChar(sequenceName.Name), 1, Field.VarChar(sequenceName.Parent.FullName));
            if (list.Any())
                throw new Exception(String.Format("Sequence generator with name '{0}' already exists.", sequenceName));

            // Generate a unique id for the sequence info table
            var uniqueId = Transaction.NextTableId(SequenceInfoTableName);

            // Insert the new row
            var dataRow = seqi.NewRow();
            dataRow.SetValue(0, Field.Number(uniqueId));
            dataRow.SetValue(1, Field.VarChar(sequenceName.Parent.FullName));
            dataRow.SetValue(2, Field.VarChar(sequenceName.Name));
            dataRow.SetValue(3, Field.BigInt(2));
            seqi.AddRow(dataRow);

            // Insert into the SEQUENCE table.
            dataRow = seq.NewRow();
            dataRow.SetValue(0, Field.Number(uniqueId));
            dataRow.SetValue(1, Field.Number(sequenceInfo.StartValue));
            dataRow.SetValue(2, Field.Number(sequenceInfo.Increment));
            dataRow.SetValue(3, Field.Number(sequenceInfo.MinValue));
            dataRow.SetValue(4, Field.Number(sequenceInfo.MaxValue));
            dataRow.SetValue(5, Field.Number(sequenceInfo.StartValue));
            dataRow.SetValue(6, Field.BigInt(sequenceInfo.Cache));
            dataRow.SetValue(7, Field.Boolean(sequenceInfo.Cycle));
            seq.AddRow(dataRow);

            return new Sequence(this, uniqueId, sequenceInfo);
        }