예제 #1
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            int index = 0;
            var order = _inserts.Keys.Union(_updates.Keys)
                        .TopologicalSort(GetTypeDependencies)
                        .ToDictionary(x => x, x => index++);

            _inserts.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _inserts[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            _updates.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _updates[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            _deletes.Keys.Each(type =>
            {
                var storage = _schema.StorageFor(type);
                var mapping = _schema.MappingFor(type).ToQueryableDocument();

                _deletes[type].Each(id => id.Configure(_schema.Parser, storage, mapping, batch));
            });

            writeEvents(batch);

            foreach (var patch in _patches)
            {
                patch.RegisterUpdate(batch);
            }

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _schema.UpsertFor(group.Key);

                group.Each(c =>
                {
                    upsert.RegisterUpdate(batch, c.Document, c.Json);
                });
            });

            return(changes);
        }
예제 #2
0
        public bool Persist(UpdateBatch batch, IDocumentSchema schema)
        {
            var upsert = schema.UpsertFor(Document.GetType());

            upsert.RegisterUpdate(batch, Document);

            return(true);
        }
예제 #3
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            int index = 0;
            var order = _inserts.Keys.Union(_updates.Keys)
                        .TopologicalSort(GetTypeDependencies)
                        .ToDictionary(x => x, x => index++);

            _inserts.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _inserts[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            _updates.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _updates[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            writeEvents(batch);


            batch.Add(_operations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _schema.UpsertFor(group.Key);

                group.Each(c =>
                {
                    upsert.RegisterUpdate(batch, c.Document, c.Json);
                });
            });

            return(changes);
        }
예제 #4
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            var types = _operations.Select(x => x.Key).TopologicalSort(GetTypeDependencies);

            foreach (var type in types)
            {
                if (!_operations.ContainsKey(type))
                {
                    continue;
                }

                foreach (var operation in _operations[type])
                {
                    // No Virginia, I do not approve of this but I'm pulling all my hair
                    // out as is trying to make this work
                    if (operation is Upsert)
                    {
                        operation.As <Upsert>().Persist(batch, _schema);
                    }
                    else
                    {
                        batch.Add(operation);
                    }
                }
            }

            writeEvents(batch);

            batch.Add(_ancillaryOperations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _schema.UpsertFor(group.Key);

                group.Each(c => { upsert.RegisterUpdate(batch, c.Document, c.Json); });
            });

            return(changes);
        }