Beispiel #1
0
        private void HandleAutoIndexChange(string name, AutoIndexDefinitionBase definition)
        {
            var creationOptions = IndexCreationOptions.Create;
            var existingIndex   = GetIndex(name);
            IndexDefinitionCompareDifferences differences = IndexDefinitionCompareDifferences.None;

            if (existingIndex != null)
            {
                creationOptions = GetIndexCreationOptions(definition, existingIndex, out differences);
            }

            if (creationOptions == IndexCreationOptions.Noop)
            {
                Debug.Assert(existingIndex != null);

                return;
            }

            if (creationOptions == IndexCreationOptions.UpdateWithoutUpdatingCompiledIndex || creationOptions == IndexCreationOptions.Update)
            {
                Debug.Assert(existingIndex != null);

                if ((differences & IndexDefinitionCompareDifferences.LockMode) != 0)
                {
                    existingIndex.SetLock(definition.LockMode);
                }

                if ((differences & IndexDefinitionCompareDifferences.Priority) != 0)
                {
                    existingIndex.SetPriority(definition.Priority);
                }

                existingIndex.Update(definition, existingIndex.Configuration);

                return;
            }

            Index index;

            if (definition is AutoMapIndexDefinition)
            {
                index = AutoMapIndex.CreateNew((AutoMapIndexDefinition)definition, _documentDatabase);
            }
            else if (definition is AutoMapReduceIndexDefinition)
            {
                index = AutoMapReduceIndex.CreateNew((AutoMapReduceIndexDefinition)definition, _documentDatabase);
            }
            else
            {
                throw new NotImplementedException($"Unknown index definition type: {definition.GetType().FullName}");
            }

            CreateIndexInternal(index);
        }
        public static IndexType GetAutoIndexType(AutoIndexDefinitionBase definition)
        {
            var indexType = IndexType.None;

            if (definition is AutoMapIndexDefinition)
            {
                indexType = IndexType.AutoMap;
            }

            if (definition is AutoMapReduceIndexDefinition)
            {
                indexType = IndexType.AutoMapReduce;
            }

            if (indexType == IndexType.None)
            {
                throw new RachisApplyException($"Invalid definition type: {definition.GetType()}");
            }

            return(indexType);
        }
        public static PutAutoIndexCommand Create(AutoIndexDefinitionBase definition, string databaseName)
        {
            var indexType = IndexType.None;
            var map       = definition as AutoMapIndexDefinition;

            if (map != null)
            {
                indexType = IndexType.AutoMap;
            }

            var reduce = definition as AutoMapReduceIndexDefinition;

            if (reduce != null)
            {
                indexType = IndexType.AutoMapReduce;
            }

            if (indexType == IndexType.None)
            {
                throw new NotSupportedException("Invalid definition type: " + definition.GetType());
            }

            return(new PutAutoIndexCommand(GetAutoIndexDefinition(definition, indexType), databaseName));
        }