private void CreateSequence(Schema schema, StorageSequenceInfo sequenceInfo, string name)
        {
            var sequence   = schema.CreateSequence(name);
            var descriptor = new SequenceDescriptor(sequence, sequenceInfo.Seed, sequenceInfo.Increment)
            {
                MinValue = sequenceInfo.Seed
            };

            sequence.SequenceDescriptor = descriptor;
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        protected override IPathNode VisitSequence(Sequence sequence)
        {
            var sequenceInfo = new StorageSequenceInfo(targetModel, resolver.GetNodeName(sequence))
            {
                Increment = sequence.SequenceDescriptor.Increment.Value,
                // StartValue = sequence.SequenceDescriptor.StartValue.Value,
            };

            return(sequenceInfo);
        }
        /// <summary>
        /// Visits the generator table.
        /// </summary>
        /// <param name="generatorTable">The generator table.</param>
        /// <returns>Visit result.</returns>
        private IPathNode VisitGeneratorTable(Table generatorTable)
        {
            var idColumn   = generatorTable.TableColumns[0];
            var startValue = idColumn.SequenceDescriptor.StartValue;
            var increment  = idColumn.SequenceDescriptor.Increment;
            var type       = ExtractType(idColumn);
            var sequence   =
                new StorageSequenceInfo(targetModel, resolver.GetNodeName(generatorTable))
            {
                Seed      = startValue ?? 0,
                Increment = increment ?? 1,
                Type      = type,
            };

            return(sequence);
        }
        /// <inheritdoc/>
        protected override IPathNode VisitSequence(Sequence sequence)
        {
            var sequenceInfo = new StorageSequenceInfo(targetModel, resolver.GetNodeName(sequence))
            {
                Increment = sequence.SequenceDescriptor.Increment.Value
            };

            if (sequence.SequenceDescriptor.StartValue != null)
            {
                sequenceInfo.Seed = sequence.SequenceDescriptor.StartValue.Value;
            }
            if (sequence.SequenceDescriptor.LastValue != null)
            {
                sequenceInfo.Current = sequence.SequenceDescriptor.LastValue;
            }
            return(sequenceInfo);
        }
        private void CreateGeneratorTable(Schema schema, StorageSequenceInfo sequenceInfo, string name)
        {
            var sequenceTable = schema.CreateTable(name);
            var idColumn      = sequenceTable.CreateColumn(WellKnown.GeneratorColumnName,
                                                           (SqlValueType)sequenceInfo.Type.NativeType);

            idColumn.SequenceDescriptor =
                new SequenceDescriptor(
                    idColumn,
                    sequenceInfo.Current ?? sequenceInfo.Seed,
                    sequenceInfo.Increment);
            sequenceTable.CreatePrimaryKey(string.Format("PK_{0}", sequenceInfo.Name), idColumn);
            if (!provider.Supports(ProviderFeatures.InsertDefaultValues))
            {
                var fakeColumn = sequenceTable.CreateColumn(WellKnown.GeneratorFakeColumnName, driver.MapValueType(typeof(int)));
                fakeColumn.IsNullable = true;
            }
        }
        /// <inheritdoc/>
        protected override IPathNode VisitKeyInfo(KeyInfo keyInfo)
        {
            if (keyInfo.Sequence == null || !keyInfo.IsFirstAmongSimilarKeys)
            {
                return(null);
            }
            var  sequenceInfo = keyInfo.Sequence;
            long increment    = 1;

            if (providerInfo.Supports(ProviderFeatures.ArbitraryIdentityIncrement) || providerInfo.Supports(ProviderFeatures.Sequences))
            {
                increment = sequenceInfo.Increment;
            }
            var sequence = new StorageSequenceInfo(targetModel, resolver.GetNodeName(sequenceInfo))
            {
                Seed      = sequenceInfo.Seed,
                Increment = increment,
                Type      = CreateType(keyInfo.TupleDescriptor[0], null, null, null),
            };

            return(sequence);
        }