Exemplo n.º 1
0
        public void RegisterUpdate(string tenantIdOverride, UpdateStyle updateStyle, UpdateBatch batch, object entity, string json)
        {
            var newVersion     = CombGuidIdGeneration.NewGuid();
            var currentVersion = batch.Versions.Version <T>(Identity(entity));

            ICallback           callback           = null;
            IExceptionTransform exceptionTransform = null;
            var sprocName = determineDbObjectName(updateStyle, batch);

            var tenantId = tenantIdOverride ?? batch.TenantId;

            if (_mapping.UseOptimisticConcurrency && batch.Concurrency == ConcurrencyChecks.Enabled)
            {
                callback = new OptimisticConcurrencyCallback <T>(Identity(entity), batch.Versions, newVersion,
                                                                 currentVersion);
            }

            if (!_mapping.UseOptimisticConcurrency && updateStyle == UpdateStyle.Update)
            {
                callback = new UpdateDocumentCallback <T>(Identity(entity));
            }

            if (updateStyle == UpdateStyle.Insert)
            {
                exceptionTransform = new InsertExceptionTransform <T>(Identity(entity), _mapping.Table.Name);
            }


            var call = batch.Sproc(sprocName, callback, exceptionTransform);

            _sprocWriter(call, (T)entity, batch, _mapping, currentVersion, newVersion, tenantId);
        }
Exemplo n.º 2
0
        private SprocCall toAppendSprocCall(UpdateBatch batch, EventStream stream, string streamTypeName, Guid[] ids, string[] eventTypes, string[] dotnetTypes)
        {
            if (_graph.StreamIdentity == StreamIdentity.AsGuid)
            {
                return(batch.Sproc(AppendEventFunction, new EventStreamVersioningCallback(stream))
                       .Param("stream", stream.Id)
                       .Param("stream_type", streamTypeName)
                       .Param(TenantIdArgument.ArgName, batch.TenantId)
                       .Param("event_ids", ids)
                       .Param("event_types", eventTypes)
                       .Param("dotnet_types", dotnetTypes));
            }

            return(batch.Sproc(AppendEventFunction, new EventStreamVersioningCallback(stream))
                   .Param("stream", stream.Key)
                   .Param("stream_type", streamTypeName)
                   .Param(TenantIdArgument.ArgName, batch.TenantId)
                   .Param("event_ids", ids)
                   .Param("event_types", eventTypes)
                   .Param("dotnet_types", dotnetTypes));
        }
Exemplo n.º 3
0
        public void RegisterUpdate(UpdateBatch batch, object entity)
        {
            var stream = entity.As <EventStream>();

            var streamTypeName = stream.AggregateType == null ? null : _graph.AggregateAliasFor(stream.AggregateType);

            var eventTypes = stream.Events.Select(x => _graph.EventMappingFor(x.Data.GetType()).EventTypeName).ToArray();
            var bodies     = stream.Events.Select(x => batch.Serializer.ToJson(x.Data)).ToArray();
            var ids        = stream.Events.Select(x => x.Id).ToArray();

            batch.Sproc(AppendEventFunction)
            .Param("stream", stream.Id)
            .Param("stream_type", streamTypeName)
            .Param("event_ids", ids)
            .Param("event_types", eventTypes)
            .JsonBodies("bodies", bodies);
        }
Exemplo n.º 4
0
        public void RegisterUpdate(UpdateBatch batch, object entity)
        {
            var stream = entity.As <Stream <T> >();

            stream.Events.Each(@event =>
            {
                // TODO -- what if this doesn't exist? Get it lazily?
                var mapping = EventMappingFor(@event.GetType());

                batch.Sproc("mt_append_event")
                .Param("stream", stream.Id)
                .Param("stream_type", StreamTypeName)
                .Param("event_id", @event.Id)
                .Param("event_type", mapping.EventTypeName)
                .JsonEntity("body", @event);
            });
        }
Exemplo n.º 5
0
        public void RegisterUpdate(UpdateBatch batch, object entity)
        {
            var stream = entity.As <EventStream>();

            var streamTypeName = stream.AggregateType == null ? null : _graph.AggregateFor(stream.AggregateType).Alias;

            stream.Events.Each(@event =>
            {
                var mapping = _graph.EventMappingFor(@event.GetType());

                batch.Sproc("mt_append_event")
                .Param("stream", stream.Id)
                .Param("stream_type", streamTypeName)
                .Param("event_id", @event.Id)
                .Param("event_type", mapping.EventTypeName)
                .JsonEntity("body", @event);
            });
        }
Exemplo n.º 6
0
        public void RegisterUpdate(UpdateBatch batch, object entity)
        {
            var stream = entity.As <EventStream>();

            var streamTypeName = stream.AggregateType == null ? null : _graph.AggregateAliasFor(stream.AggregateType);

            var events     = stream.Events.ToArray();
            var eventTypes = events.Select(x => _graph.EventMappingFor(x.Data.GetType()).EventTypeName).ToArray();
            var ids        = events.Select(x => x.Id).ToArray();

            var sprocCall = batch.Sproc(AppendEventFunction, new EventStreamVersioningCallback(stream))
                            .Param("stream", stream.Id)
                            .Param("stream_type", streamTypeName)
                            .Param("event_ids", ids)
                            .Param("event_types", eventTypes);

            AddJsonBodies(batch, sprocCall, events);
        }
Exemplo n.º 7
0
        public void RegisterUpdate(UpdateBatch batch, object entity, string json)
        {
            var newVersion     = CombGuidIdGeneration.NewGuid();
            var currentVersion = batch.Versions.Version <T>(Identity(entity));

            ICallback callback = null;

            if (_mapping.UseOptimisticConcurrency)
            {
                callback = new OptimisticConcurrencyCallback <T>(Identity(entity), batch.Versions, newVersion, currentVersion);
            }


            var call = batch.Sproc(_upsertName, callback);



            _sprocWriter(call, (T)entity, batch, _mapping, currentVersion, newVersion);
        }
Exemplo n.º 8
0
        public void RegisterUpdate(UpdateBatch batch, object entity, string json)
        {
            var document = (Marten.Testing.Examples.Trade)entity;

            batch.Sproc("mt_upsert_trade").Param(document.Id, NpgsqlDbType.Integer).JsonBody(json).Param(document.Value, NpgsqlDbType.Double);
        }
Exemplo n.º 9
0
        public void RegisterUpdate(UpdateBatch batch, object entity, string json)
        {
            var call = batch.Sproc(_upsertName);

            _sprocWriter(call, (T)entity, json, _mapping, _mapping.AliasFor(entity.GetType()));
        }