Exemple #1
0
        public string PutTransform(string name, TransformerDefinition definition)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            name = name.Trim();

            var existingDefinition = IndexDefinitionStorage.GetTransformerDefinition(name);

            if (existingDefinition != null)
            {
                switch (existingDefinition.LockMode)
                {
                case TransformerLockMode.Unlock:
                    if (existingDefinition.Equals(definition))
                    {
                        return(name);                        // no op for the same transformer
                    }
                    break;

                case TransformerLockMode.LockedIgnore:
                    Log.Info("Transformer {0} not saved because it was lock (with ignore)", name);
                    return(name);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var generator = IndexDefinitionStorage.CompileTransform(definition);

            if (existingDefinition != null)
            {
                IndexDefinitionStorage.RemoveTransformer(existingDefinition.TransfomerId);
            }

            TransactionalStorage.Batch(accessor =>
            {
                definition.TransfomerId = (int)Database.Documents.GetNextIdentityValueWithoutOverwritingOnExistingDocuments("TransformerId", accessor);
            });

            IndexDefinitionStorage.CreateAndPersistTransform(definition, generator);
            IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);

            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification()
            {
                Name = name,
                Type = TransformerChangeTypes.TransformerAdded,
            }));

            return(name);
        }
 public void DeleteTransform(string name)
 {
     IndexDefinitionStorage.RemoveTransformer(name);
     TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification
     {
         Name = name,
         Type = TransformerChangeTypes.TransformerRemoved
     }));
 }
Exemple #3
0
        public bool DeleteTransform(string name, int?deletedTransformerVersion)
        {
            var transformer = GetTransformerDefinition(name);

            if (transformer == null)
            {
                return(false);
            }

            var currentTransformerVersion = transformer.TransformerVersion;

            if (deletedTransformerVersion != null &&
                currentTransformerVersion != null &&
                currentTransformerVersion > deletedTransformerVersion)
            {
                // the transformer version is larger than the deleted one
                // got an old delete from an outdated node
                return(false);
            }

            if (IndexDefinitionStorage.RemoveTransformer(name) == false)
            {
                return(false);
            }

            var version = currentTransformerVersion ?? 0;

            if (deletedTransformerVersion != null)
            {
                version = Math.Max(version, deletedTransformerVersion.Value);
            }

            TransactionalStorage.Batch(actions =>
            {
                var metadata = new RavenJObject
                {
                    { IndexDefinitionStorage.TransformerVersionKey, version }
                };
                actions.Lists.Set(Constants.RavenDeletedTransformersVersions, name, metadata, UuidType.Transformers);
            });

            //raise notification only if the transformer was actually removed
            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification
            {
                Name    = name,
                Type    = TransformerChangeTypes.TransformerRemoved,
                Version = version
            }));

            return(true);
        }
        public bool DeleteTransform(string name)
        {
            if (!IndexDefinitionStorage.RemoveTransformer(name))
            {
                return(false);
            }

            //raise notification only if the transformer was actually removed
            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification
            {
                Name = name,
                Type = TransformerChangeTypes.TransformerRemoved
            }));

            return(true);
        }
        public string PutTransform(string name, TransformerDefinition definition)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            name = name.Trim();

            var existingDefinition = IndexDefinitionStorage.GetTransformerDefinition(name);

            if (existingDefinition != null && existingDefinition.Equals(definition))
            {
                return(name); // no op for the same transformer
            }
            var generator = IndexDefinitionStorage.CompileTransform(definition);

            if (existingDefinition != null)
            {
                IndexDefinitionStorage.RemoveTransformer(existingDefinition.TransfomerId);
            }

            TransactionalStorage.Batch(accessor =>
            {
                definition.TransfomerId = (int)Database.Documents.GetNextIdentityValueWithoutOverwritingOnExistingDocuments("TransformerId", accessor);
            });

            IndexDefinitionStorage.CreateAndPersistTransform(definition, generator);
            IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);

            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification()
            {
                Name = name,
                Type = TransformerChangeTypes.TransformerAdded,
            }));

            return(name);
        }
        public string PutTransform(string name, TransformerDefinition definition, bool isReplication = false)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            name = name.Trim();

            var existingDefinition = IndexDefinitionStorage.GetTransformerDefinition(name);

            if (existingDefinition != null)
            {
                var newTransformerVersion     = definition.TransformerVersion;
                var currentTransformerVersion = existingDefinition.TransformerVersion;

                // whether we update the transformer definition or not,
                // we need to update the transformer version
                existingDefinition.TransformerVersion = definition.TransformerVersion =
                    Math.Max(currentTransformerVersion ?? 0, newTransformerVersion ?? 0);

                switch (isReplication)
                {
                case true:
                    if (newTransformerVersion != null && currentTransformerVersion != null &&
                        newTransformerVersion <= currentTransformerVersion)
                    {
                        //this new transformer is an older version of the current one
                        return(null);
                    }

                    // we need to update the lock mode only if it was updated by another server
                    existingDefinition.LockMode = definition.LockMode;
                    break;

                default:
                    switch (existingDefinition.LockMode)
                    {
                    case TransformerLockMode.Unlock:
                        if (existingDefinition.Equals(definition))
                        {
                            return(name);        // no op for the same transformer
                        }
                        definition.TransformerVersion++;

                        break;

                    case TransformerLockMode.LockedIgnore:
                        Log.Info("Transformer {0} not saved because it was lock (with ignore)", name);
                        return(name);

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    break;
                }
            }
            else if (isReplication == false)
            {
                // we're creating a new transformer,
                // we need to take the transformer version of the deleted transformer (if exists)
                definition.TransformerVersion = GetDeletedTransformerId(definition.Name);
                definition.TransformerVersion = (definition.TransformerVersion ?? 0) + 1;
            }

            if (definition.TransformerVersion == null)
            {
                definition.TransformerVersion = 0;
            }

            var generator = IndexDefinitionStorage.CompileTransform(definition);

            if (existingDefinition != null)
            {
                IndexDefinitionStorage.RemoveTransformer(existingDefinition.TransfomerId);
            }

            var temporary = definition.Temporary;

            if (temporary)
            {
                definition.TransfomerId = Database.Transformers.GetNextTemporaryTransformerIndex();
                IndexDefinitionStorage.CreateTransform(definition, generator);
                IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);
            }
            else
            {
                TransactionalStorage.Batch(accessor =>
                {
                    definition.TransfomerId = (int)Database.Documents.GetNextIdentityValueWithoutOverwritingOnExistingDocuments("TransformerId", accessor);
                });

                IndexDefinitionStorage.CreateTransform(definition, generator);
                IndexDefinitionStorage.PersistTransform(definition);
                IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);

                TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification()
                {
                    Name    = name,
                    Type    = TransformerChangeTypes.TransformerAdded,
                    Version = definition.TransformerVersion
                }));
            }

            return(name);
        }