예제 #1
0
        // ReSharper disable once InconsistentNaming
        private static IEnumerable <T> _DefaultIfEmptyShapedQuery <T>(
            QueryContext queryContext,
            ShaperCommandContext shaperCommandContext,
            IShaper <T> shaper)
        {
            var checkedEmpty = false;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var valueBuffer
                     in _Query((RelationalQueryContext)queryContext, shaperCommandContext))
            {
                if (!checkedEmpty)
                {
                    var empty = true;

                    for (var i = 0; i < valueBuffer.Count; i++)
                    {
                        empty &= valueBuffer[i] == null;
                    }

                    if (empty)
                    {
                        yield break;
                    }

                    checkedEmpty = true;
                }

                yield return(shaper.Shape(queryContext, valueBuffer));
            }
        }
예제 #2
0
 private static IAsyncRelatedEntitiesLoader _CreateCollectionRelatedEntitiesLoader(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     int queryIndex,
     Func <ValueBuffer, object> materializer)
 => new CollectionRelatedEntitiesLoader(
     queryContext, shaperCommandContext, queryIndex, materializer);
 private static IAsyncEnumerable <T> _DefaultIfEmptyShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => new DefaultIfEmptyAsyncEnumerable(
     _Query((RelationalQueryContext)queryContext, shaperCommandContext))
 .Select(vb => shaper.Shape(queryContext, vb));
예제 #4
0
 // ReSharper disable once InconsistentNaming
 private static IEnumerable <ValueBuffer> _Query(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext)
 => new QueryingEnumerable <ValueBuffer>(
     (RelationalQueryContext)queryContext,
     shaperCommandContext,
     IdentityShaper.Instance);
 private static IAsyncEnumerable <T> _ShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => new AsyncQueryingEnumerable <T>(
     (RelationalQueryContext)queryContext,
     shaperCommandContext,
     shaper);
 public FastQueryAsyncEnumerator(FastQueryAsyncEnumerable <TEntity> state)
 {
     _relationalQueryContext = state._relationalQueryContext;
     _shaperCommandContext   = state._shaperCommandContext;
     _materializer           = state._materializer;
     _contextType            = state._contextType;
     _logger = state._logger;
 }
 private static IAsyncEnumerable <ValueBuffer> _Query(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     int?queryIndex)
 {
     return(new MySqlAsyncQueryingEnumerable <ValueBuffer>(queryContext as MySqlQueryContext,
                                                           (IAsyncEnumerable <ValueBuffer>)_baseQuery.Invoke(null, new object[] { queryContext, shaperCommandContext, queryIndex })));
 }
예제 #8
0
 private static IAsyncEnumerable <ValueBuffer> _Query(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     int?queryIndex)
 => new AsyncQueryingEnumerable(
     (RelationalQueryContext)queryContext,
     shaperCommandContext,
     queryIndex);
예제 #9
0
 private static IEnumerable <T> _DefaultIfEmptyShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 {
     return(new MySqlQueryingEnumerable <T>(queryContext as MySqlQueryContext,
                                            (IEnumerable <T>)_baseDefaultIfEmptyShapedQuery.MakeGenericMethod(typeof(T))
                                            .Invoke(null, new object[] { queryContext, shaperCommandContext, shaper })));
 }
예제 #10
0
 internal static IAsyncEnumerable <T> _ShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => new AsyncQueryingEnumerable(
     (RelationalQueryContext)queryContext,
     shaperCommandContext,
     queryIndex: null)
 .Select(vb => shaper.Shape(queryContext, vb));         // TODO: Pass shaper to underlying enumerable
예제 #11
0
 internal static IAsyncEnumerable <T> _DefaultIfEmptyShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => new DefaultIfEmptyAsyncEnumerable(
     new AsyncQueryingEnumerable(
         (RelationalQueryContext)queryContext,
         shaperCommandContext,
         queryIndex: null))
 .Select(vb => shaper.Shape(queryContext, vb));
예제 #12
0
 private static IAsyncEnumerable <T> _ShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => AsyncLinqOperatorProvider.
 _Select(new AsyncQueryingEnumerable(
             (RelationalQueryContext)queryContext,
             shaperCommandContext,
             queryIndex: null),
         vb => shaper.Shape(queryContext, vb));     // TODO: Pass shaper to underlying enumerable
예제 #13
0
 private static IEnumerable <T> _ShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper,
     IValueBufferFromBsonShaper valueBufferShaper)
 {
     foreach (var valueBuffer in new QueryingEnumerable((LiteDBQueryContext)queryContext, shaperCommandContext, valueBufferShaper))
     {
         yield return(shaper.Shape(queryContext, valueBuffer));
     }
 }
 private static IAsyncEnumerable <T> _DefaultIfEmptyShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 => AsyncLinqOperatorProvider
 ._Select(
     new DefaultIfEmptyAsyncEnumerable(
         new AsyncQueryingEnumerable(
             (RelationalQueryContext)queryContext,
             shaperCommandContext)),
     vb => shaper.Shape(queryContext, vb));
 // ReSharper disable once InconsistentNaming
 private static IAsyncEnumerable <TEntity> _FastQuery <TEntity>(
     RelationalQueryContext relationalQueryContext,
     ShaperCommandContext shaperCommandContext,
     Func <DbDataReader, DbContext, TEntity> materializer,
     Type contextType,
     IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 => new FastQueryAsyncEnumerable <TEntity>(
     relationalQueryContext,
     shaperCommandContext,
     materializer,
     contextType,
     logger);
예제 #16
0
            public CollectionRelatedEntitiesLoader(
                QueryContext queryContext,
                ShaperCommandContext shaperCommandContext,
                int queryIndex,
                Func <ValueBuffer, object> materializer)
            {
                _includeCollectionIterator
                    = new AsyncIncludeCollectionIterator(
                          _Query(queryContext, shaperCommandContext, queryIndex)
                          .GetEnumerator());

                _materializer = materializer;
            }
 public FastQueryAsyncEnumerable(
     RelationalQueryContext relationalQueryContext,
     ShaperCommandContext shaperCommandContext,
     Func <DbDataReader, DbContext, TEntity> materializer,
     Type contextType,
     IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     _relationalQueryContext = relationalQueryContext;
     _shaperCommandContext   = shaperCommandContext;
     _materializer           = materializer;
     _contextType            = contextType;
     _logger = logger;
 }
 // ReSharper disable once InconsistentNaming
 private static IEnumerable <T> _ShapedQuery <T>(
     QueryContext queryContext,
     ShaperCommandContext shaperCommandContext,
     IShaper <T> shaper)
 {
     // ReSharper disable once LoopCanBeConvertedToQuery
     foreach (var valueBuffer
              in new QueryingEnumerable(
                  (RelationalQueryContext)queryContext,
                  shaperCommandContext))
     {
         yield return(shaper.Shape(queryContext, valueBuffer));
     }
 }
예제 #19
0
        // ReSharper disable once InconsistentNaming
        private static IEnumerable <TEntity> _FastQuery <TEntity>(
            RelationalQueryContext relationalQueryContext,
            ShaperCommandContext shaperCommandContext,
            Func <DbDataReader, DbContext, TEntity> materializer,
            Type contextType,
            IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            relationalQueryContext.Connection.Open();

            RelationalDataReader dataReader;

            try
            {
                var relationalCommand
                    = shaperCommandContext
                      .GetRelationalCommand(relationalQueryContext.ParameterValues, relationalQueryContext);

                dataReader
                    = relationalCommand.ExecuteReader(
                          relationalQueryContext.Connection,
                          relationalQueryContext.ParameterValues,
                          relationalQueryContext.CommandLogger);
            }
            catch
            {
                // If failure happens creating the data reader, then it won't be available to
                // handle closing the connection, so do it explicitly here to preserve ref counting.
                relationalQueryContext.Connection.Close();

                throw;
            }

            var dbDataReader = dataReader.DbDataReader;

            try
            {
                using (dataReader)
                {
                    using (relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) // TODO: IDisposable box?
                    {
                        while (true)
                        {
                            bool hasNext;

                            try
                            {
                                hasNext = dataReader.Read();
                            }
                            catch (Exception exception)
                            {
                                logger.QueryIterationFailed(contextType, exception);

                                throw;
                            }

                            if (hasNext)
                            {
                                yield return(materializer(dbDataReader, relationalQueryContext.Context));
                            }
                            else
                            {
                                yield break;
                            }
                        }
                    }
                }
            }
            finally
            {
                relationalQueryContext.Connection?.Close();
                relationalQueryContext.Dispose();
            }
        }