Esempio n. 1
0
        public Fetcher(IDocumentStore store, DaemonSettings settings, AsyncOptions options, IDaemonLogger logger, IDaemonErrorHandler errorHandler, IEnumerable <Type> eventTypes)
        {
            _settings     = settings;
            _options      = options;
            _logger       = logger;
            _errorHandler = errorHandler;
            State         = FetcherState.Waiting;

            // TODO -- this will have to change
            _tenant = store.Tenancy.Default;

            _streamIdentity = store.Events.StreamIdentity;

            _selector = store.Events.StreamIdentity == StreamIdentity.AsGuid
                ? (IEventSelector) new EventSelector(store.Events, store.Advanced.Serializer)
                : new StringIdentifiedEventSelector(store.Events, store.Advanced.Serializer);

            EventTypeNames = eventTypes.Select(x => store.Events.EventMappingFor(x).Alias).ToArray();

            var fields = _selector.SelectFields().Join(", ");

            _sql =
                $@"
select seq_id from {_selector.Events.DatabaseSchemaName}.mt_events where seq_id > :last and seq_id <= :limit and extract(epoch from age(transaction_timestamp(), {_selector.Events.DatabaseSchemaName}.mt_events.timestamp)) >= :buffer order by seq_id;
select {fields} from {_selector.Events.DatabaseSchemaName}.mt_events where seq_id > :last and seq_id <= :limit and type = ANY(:types) and extract(epoch from age(transaction_timestamp(), {_selector.Events.DatabaseSchemaName}.mt_events.timestamp)) >= :buffer order by seq_id;
select min(seq_id) from {_selector.Events.DatabaseSchemaName}.mt_events where seq_id > :limit and type = ANY(:types) and extract(epoch from age(transaction_timestamp(), {_selector.Events.DatabaseSchemaName}.mt_events.timestamp)) >= :buffer;
select max(seq_id) from {_selector.Events.DatabaseSchemaName}.mt_events where seq_id >= :limit and extract(epoch from age(transaction_timestamp(), {_selector.Events.DatabaseSchemaName}.mt_events.timestamp)) >= :buffer
".Replace(" as d", "");
        }
Esempio n. 2
0
        public EventQueryHandler(IEventSelector selector, TIdentity streamId, int version = 0, DateTime?timestamp = null, TenancyStyle tenancyStyle = TenancyStyle.Single, string tenantId = null)
        {
            if (timestamp != null && timestamp.Value.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentOutOfRangeException(nameof(timestamp), "This method only accepts UTC dates");
            }

            if (_tenancyStyle == TenancyStyle.Conjoined && tenantId == null)
            {
                throw new ArgumentNullException(nameof(tenantId), $"{nameof(tenantId)} cannot be null for {TenancyStyle.Conjoined}");
            }

            _selector     = selector;
            _streamId     = streamId;
            _version      = version;
            _timestamp    = timestamp;
            _tenancyStyle = tenancyStyle;
            _tenantId     = tenantId;
        }
Esempio n. 3
0
        public EventDocumentStorage(EventGraph graph, EventQueryMapping mapping, ISerializer serializer)
        {
            _graph   = graph;
            _mapping = mapping;

            FromObject = _mapping.Table.QualifiedName;
            Fields     = mapping;

            if (graph.StreamIdentity == StreamIdentity.AsGuid)
            {
                IdType    = typeof(Guid);
                _selector = new EventSelector(graph, serializer);
            }
            else
            {
                IdType    = typeof(string);
                _selector = new StringIdentifiedEventSelector(graph, serializer);
            }
        }
Esempio n. 4
0
        public EventStore(DocumentSessionBase session, DocumentStore store, ITenant tenant)
        {
            _session = session;
            _store   = store;

            _tenant = tenant;

            // TODO -- we can make much more of this lazy
            StreamIdentity = _store.Events.StreamIdentity;

            if (StreamIdentity == StreamIdentity.AsGuid)
            {
                _selector = new EventSelector(_store.Events, _store.Serializer);
            }
            else
            {
                _selector = new StringIdentifiedEventSelector(_store.Events, _store.Serializer);
            }
        }