Example #1
0
        public IQuery <T> ExecuteQuery <T>(ICompiledQuery <T> compiledQuery, string collection = null) where T : class
        {
            if (compiledQuery == null)
            {
                throw new ArgumentNullException(nameof(compiledQuery));
            }

            var compiledQueryType = compiledQuery.GetType();

            var discriminator = NullableThumbprintFactory.GetNullableThumbprint(compiledQuery);

            if (!_store.CompiledQueries.TryGetValue(discriminator, out var queryState))
            {
                lock (_store.CompiledQueries)
                {
                    if (!_store.CompiledQueries.TryGetValue(discriminator, out queryState))
                    {
                        var localQuery   = ((IQuery) new DefaultQuery(this, _tablePrefix, collection)).For <T>(false);
                        var defaultQuery = (DefaultQuery.Query <T>)compiledQuery.Query().Compile().Invoke(localQuery);
                        queryState = defaultQuery._query._queryState;

                        _store.CompiledQueries[discriminator] = queryState;
                    }
                }
            }

            queryState = queryState.Clone();

            IQuery newQuery = new DefaultQuery(this, queryState, compiledQuery);

            return(newQuery.For <T>(false));
        }
Example #2
0
        public IQuery <T> ExecuteQuery <T>(ICompiledQuery <T> compiledQuery) where T : class
        {
            if (compiledQuery == null)
            {
                throw new ArgumentNullException(nameof(compiledQuery));
            }

            var compiledQueryType = compiledQuery.GetType();

            if (!_store.CompiledQueries.TryGetValue(compiledQueryType, out var queryState))
            {
                var localQuery   = ((IQuery) new DefaultQuery(_connection, _transaction, this, _tablePrefix)).For <T>(false);
                var defaultQuery = (DefaultQuery.Query <T>)compiledQuery.Query().Compile().Invoke(localQuery);
                queryState = defaultQuery._query._queryState;

                // Don't use Add as two thread could concurrently reach this point.
                // We don't mind losing some values as the next call will restore it if it's not cached.
                _store.CompiledQueries = _store.CompiledQueries.SetItem(compiledQueryType, queryState);
            }

            queryState = queryState.Clone();

            IQuery newQuery = new DefaultQuery(_connection, _transaction, this, _tablePrefix, queryState, compiledQuery);

            return(newQuery.For <T>(false));
        }
Example #3
0
        public IQuery <T> ExecuteQuery <T>(ICompiledQuery <T> compiledQuery) where T : class
        {
            if (compiledQuery == null)
            {
                throw new ArgumentNullException(nameof(compiledQuery));
            }

            var queryState = _store.CompiledQueries.GetOrAdd(compiledQuery.GetType(), t =>
            {
                var localQuery   = ((IQuery) new DefaultQuery(_connection, _transaction, this, _tablePrefix)).For <T>(false);
                var defaultQuery = (DefaultQuery.Query <T>)compiledQuery.Query().Compile().Invoke(localQuery);

                return(defaultQuery._query._queryState);
            });

            queryState = queryState.Clone();

            IQuery newQuery = new DefaultQuery(_connection, _transaction, this, _tablePrefix, queryState, compiledQuery);

            return(newQuery.For <T>(false));
        }