Example #1
0
        private Task <T> load <T>(object id) where T : class
        {
            if (_identityMap.Has <T>(id))
            {
                return(Task.FromResult(_identityMap.Retrieve <T>(id)));
            }

            var mapping = _schema.MappingFor(typeof(T)).ToQueryableDocument();

            return(AddItem(new LoadByIdHandler <T>(_schema.ResolverFor <T>(), mapping, id)));
        }
Example #2
0
        public void Append(Guid stream, params object[] events)
        {
            if (_identityMap.Has <EventStream>(stream))
            {
                _identityMap.Retrieve <EventStream>(stream).AddEvents(events.Select(EventStream.ToEvent));
            }
            else
            {
                var eventStream = new EventStream(stream, events.Select(EventStream.ToEvent).ToArray(), false);

                _session.Store(eventStream);
            }
        }
Example #3
0
        public void AppendEvents(Guid stream, params IEvent[] events)
        {
            if (_identityMap.Has <EventStream>(stream))
            {
                _identityMap.Retrieve <EventStream>(stream).AddEvents(events);
            }
            else
            {
                var eventStream = new EventStream(stream, events);


                _session.Store(eventStream);
            }
        }
Example #4
0
        public T Resolve(IIdentityMap map, IQuerySession session, object id)
        {
            if (map.Has <T>(id))
            {
                return(map.Retrieve <T>(id));
            }

            var cmd = LoaderCommand(id);

            cmd.AddTenancy(session.Tenant);
            cmd.Connection = session.Connection;
            using (var reader = cmd.ExecuteReader())
            {
                return(Fetch(id, reader, map));
            }
        }
Example #5
0
        public async Task <T> ResolveAsync(IIdentityMap map, IQuerySession session, CancellationToken token, object id)
        {
            if (map.Has <T>(id))
            {
                return(map.Retrieve <T>(id));
            }

            var cmd = LoaderCommand(id);

            cmd.AddTenancy(session.Tenant);
            cmd.Connection = session.Connection;

            using (var reader = await cmd.ExecuteReaderAsync(token).ConfigureAwait(false))
            {
                return(await FetchAsync(id, reader, map, token).ConfigureAwait(false));
            }
        }
Example #6
0
        private Task <T> load <T>(object id) where T : class
        {
            if (_identityMap.Has <T>(id))
            {
                return(Task.FromResult(_identityMap.Retrieve <T>(id)));
            }

            var source = new TaskCompletionSource <T>();

            var mapping   = _schema.MappingFor(typeof(T));
            var parameter = _command.AddParameter(id);

            _command.AppendQuery(
                $"select {mapping.SelectFields("d")} from {mapping.TableName} as d where id = :{parameter.ParameterName}");

            var handler = new SingleResultReader <T>(source, _schema.StorageFor(typeof(T)), _identityMap);

            addHandler(handler);

            return(source.Task);
        }