Exemple #1
0
 private string GetSequenceName(Type documentType, HiloSettings settings)
 {
     if (!string.IsNullOrEmpty(settings.SequenceName))
     {
         return(settings.SequenceName);
     }
     return(documentType.Name);
 }
Exemple #2
0
 public HiloSequence(ITenant tenant, StoreOptions options, string entityName, HiloSettings settings)
 {
     _tenant     = tenant;
     _options    = options;
     _entityName = entityName;
     CurrentHi   = -1;
     CurrentLo   = 1;
     MaxLo       = settings.MaxLo;
 }
Exemple #3
0
        public HiloSequence(IConnectionFactory factory, StoreOptions options, string entityName, HiloSettings settings)
        {
            _factory = factory;
            _options = options;
            _entityName = entityName;

            CurrentHi = -1;
            CurrentLo = 1;
            MaxLo = settings.MaxLo;
        }
Exemple #4
0
        public HiloSequence(IMartenDatabase database, StoreOptions options, string entityName, HiloSettings settings)
        {
            _database   = database;
            _options    = options;
            _entityName = entityName;
            CurrentHi   = -1;
            CurrentLo   = 1;
            MaxLo       = settings.MaxLo;

            _settings = settings;
        }
        public void default_everything()
        {
            var defaults = new HiloSettings();

            var store = DocumentStore.For(ConnectionSource.ConnectionString);
            var mapping = store.Schema.MappingFor(typeof (IntDoc));

            var idStrategy = mapping.ToIdAssignment<IntDoc>(store.Schema)
                .As<IdAssigner<IntDoc, int>>().Generator
                .ShouldBeOfType<IntHiloGenerator>();



            idStrategy.Sequence.MaxLo.ShouldBe(defaults.MaxLo);
        }
        public void build_assignment_for_long()
        {
            var settings = new HiloSettings();

            var sequence = Substitute.For<ISequence>();
            var sequences = Substitute.For<ISequences>();
            var schema = Substitute.For<IDocumentSchema>();

            schema.Sequences.Returns(sequences);
            sequences.Hilo(typeof(Target), settings).Returns(sequence);

            var generation = new HiloIdGeneration(typeof(Target), settings);


            generation.Build<long>(schema).ShouldBeOfType<LongHiloGenerator>()
                .Sequence.ShouldBeSameAs(sequence);
        }
Exemple #7
0
        public ISequence Hilo(Type documentType, HiloSettings settings)
        {
            if (!_schema.DbObjects.TableExists(Table))
            {
                if (_options.AutoCreateSchemaObjects == AutoCreate.None)
                {
                    throw new InvalidOperationException($"Hilo table is missing, but {nameof(StoreOptions.AutoCreateSchemaObjects)} is {_options.AutoCreateSchemaObjects}");
                }

                var sqlScript = SchemaBuilder.GetSqlScript(Table.Schema, "mt_hilo");
                _logger.SchemaChange(sqlScript);

                _factory.RunSql(sqlScript);
            }

            return(new HiloSequence(_factory, _options, documentType.Name, settings));
        }
        public void can_build_a_generator()
        {
            var settings = new HiloSettings();

            var sequence = Substitute.For<ISequence>();
            var sequences = Substitute.For<ISequences>();
            var schema = Substitute.For<IDocumentSchema>();

            schema.Sequences.Returns(sequences);
            sequences.Hilo(typeof(Target), settings).Returns(sequence);

            var mapping = DocumentMapping.For<Target>();
            var generation = new IdentityKeyGeneration(mapping, settings);


            var generator = generation.Build<string>(schema).ShouldBeOfType<IdentityKeyGenerator>();
            generator
                .Sequence.ShouldBeSameAs(sequence);

            generator.Alias.ShouldBe(mapping.Alias);
        }
 public IdentityKeyGeneration(DocumentMapping mapping, HiloSettings hiloSettings)
 {
     _mapping      = mapping;
     _hiloSettings = hiloSettings ?? new HiloSettings();
 }
Exemple #10
0
 public ISequence Hilo(Type documentType, HiloSettings settings)
 {
     return(_sequences.GetOrAdd(GetSequenceName(documentType, settings),
                                sequence => new HiloSequence(_tenant, _options, sequence, settings)));
 }
Exemple #11
0
 public ISequence Hilo(Type documentType, HiloSettings settings)
 {
     return _sequences.GetOrAdd(documentType, type => new HiloSequence(_factory, _options, documentType.Name, settings));
 }
Exemple #12
0
 public ISequence Hilo(Type documentType, HiloSettings settings)
 {
     return(new HiloSequence(_factory, _options, documentType.Name, settings));
 }
Exemple #13
0
 public HiloIdGeneration(Type documentType, HiloSettings hiloSettings)
 {
     _hiloSettings = hiloSettings;
     DocumentType  = documentType;
 }
Exemple #14
0
        public HiloSequence(IConnectionFactory factory, StoreOptions options, string entityName, HiloSettings settings)
        {
            _factory    = factory;
            _options    = options;
            _entityName = entityName;

            CurrentHi = -1;
            CurrentLo = 1;
            MaxLo     = settings.MaxLo;
        }
Exemple #15
0
 public ISequence Hilo(Type documentType, HiloSettings settings)
 {
     return(_sequences.GetOrAdd(documentType, type => new HiloSequence(_factory, _options, documentType.Name, settings)));
 }
 public ISequence Hilo(Type documentType, HiloSettings settings)
 {
     return new HiloSequence(_factory, _options, documentType.Name, settings);
 }