Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions Source/Core/MappedDbQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ internal MappedDbQuery(DbQuery definition, IRowSource<T> source)

public MappedDbQuery<T> SingleResult()
=> new(
Query,
_source,
_options | QueryOptions.SingleResult,
_pool,
_clearOnReturn);
Query, _source, _options | QueryOptions.SingleResult,
_pool, _clearOnReturn);

/// <summary>
/// Cancels the command when a terminal stops before the last row, in every query made from this definition
Expand All @@ -82,11 +79,8 @@ public MappedDbQuery<T> SingleResult()
/// <seealso cref="WithOptions(QueryOptions)"/>
public MappedDbQuery<T> CancelOnEarlyStop()
=> new(
Query,
_source,
_options | QueryOptions.CancelOnEarlyStop,
_pool,
_clearOnReturn);
Query, _source, _options | QueryOptions.CancelOnEarlyStop,
_pool, _clearOnReturn);

/// <summary>
/// Reads the rows with the asynchronous read of the provider, in every query made from this definition
Expand All @@ -96,11 +90,8 @@ public MappedDbQuery<T> CancelOnEarlyStop()
/// <seealso cref="WithOptions(QueryOptions)"/>
public MappedDbQuery<T> AsyncReads()
=> new(
Query,
_source,
_options | QueryOptions.AsyncReads,
_pool,
_clearOnReturn);
Query, _source, _options | QueryOptions.AsyncReads,
_pool, _clearOnReturn);

/// <summary>
/// Asks the reader for sequential access, in every query made from this definition
Expand All @@ -110,11 +101,8 @@ public MappedDbQuery<T> AsyncReads()
/// <seealso cref="WithOptions(QueryOptions)"/>
public MappedDbQuery<T> SequentialAccess()
=> new(
Query,
_source,
_options | QueryOptions.SequentialAccess,
_pool,
_clearOnReturn);
Query, _source, _options | QueryOptions.SequentialAccess,
_pool, _clearOnReturn);

/// <summary>
/// Returns a definition whose switches, in every query made from it, are
Expand All @@ -124,11 +112,8 @@ public MappedDbQuery<T> SequentialAccess()
/// <returns>A definition with exactly these switches.</returns>
public MappedDbQuery<T> WithOptions(QueryOptions options)
=> new(
Query,
_source,
Views.CheckedOptions(options),
_pool,
_clearOnReturn);
Query, _source, Views.CheckedOptions(options),
_pool, _clearOnReturn);

/// <summary>
/// Takes the arrays that hold the rows from <paramref name="pool"/>, in every query made from this definition
Expand Down
24 changes: 5 additions & 19 deletions Source/Core/MappedQuery.Capture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,10 @@ public MappedQueryCore<T> WithCapture(ICaptureSource source)
// first capture, and one run claims them.
CaptureSet captures = CaptureSet.With(
_captures as CaptureSet ?? runner.Captures,
source,
onQuery: true,
runner.IsProcedure);
source, onQuery: true, runner.IsProcedure);
return new(
_command,
_call,
_source,
_skip,
_take,
Options,
Config,
captures);
_command, _call, _source,
_skip, _take, Options, Config, captures);
}

/// <summary>
Expand All @@ -74,14 +66,8 @@ public MappedQueryCore<T> WithCapture(ICaptureSource source)
/// <returns>The query for the stream or the buffer to read.</returns>
MappedQueryCore<T> WithRun(CaptureRun run)
=> new(
_command,
_call,
_source,
_skip,
_take,
Options,
Config,
run);
_command, _call, _source,
_skip, _take, Options, Config, run);

/// <summary>
/// Makes the run of a stream, claimed later by its
Expand Down
120 changes: 26 additions & 94 deletions Source/Core/MappedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,8 @@ CommandBehavior Behavior
/// <returns>A copy of the query with <paramref name="options"/>.</returns>
public MappedQueryCore<T> WithOptions(QueryOptions options)
=> Checked(new(
_command,
_call,
_source,
_skip,
_take,
options,
Config,
_captures));
_command, _call, _source,
_skip, _take, options, Config, _captures));

/// <summary>
/// Returns the query with one more switch set, and the others as they were.
Expand Down Expand Up @@ -334,11 +328,8 @@ public MappedQueryCore<T> WithPool(ArrayPool<T> pool, bool clearOnReturn)

// The pool is the caller's; the sizes and the bin stay what the query had.
return WithConfig(new ChunkConfig<T>(
pool,
clearOnReturn,
Config.Sizes,
Config.Bin,
Config.DeferFromClearedBytes));
pool, clearOnReturn,
Config.Sizes, Config.Bin, Config.DeferFromClearedBytes));
}

/// <summary>
Expand All @@ -349,14 +340,8 @@ public MappedQueryCore<T> WithPool(ArrayPool<T> pool, bool clearOnReturn)
/// <returns>A copy of the query that uses <paramref name="config"/>.</returns>
public MappedQueryCore<T> WithConfig(ChunkConfig<T> config)
=> Checked(new(
_command,
_call,
_source,
_skip,
_take,
Options,
config,
_captures));
_command, _call, _source,
_skip, _take, Options, config, _captures));

/// <summary>Returns the same query over another call.</summary>
/// <exception cref="InvalidOperationException">The query carries a capture,
Expand All @@ -370,14 +355,8 @@ public MappedQueryCore<T> WithCall(DbQueryCall call)
public MappedQueryCore<T> WithSkip(int count)
=> count >= 0
? Checked(new(
_command,
_call,
_source,
_skip + count,
_take,
Options,
Config,
_captures))
_command, _call, _source,
_skip + count, _take, Options, Config, _captures))
: throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative.");

/// <summary>
Expand All @@ -391,14 +370,8 @@ public MappedQueryCore<T> WithSkip(int count)
public MappedQueryCore<T> WithTake(int count)
=> count >= 0
? Checked(new(
_command,
_call,
_source,
_skip,
count,
Options,
Config,
_captures))
_command, _call, _source,
_skip, count, Options, Config, _captures))
: throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative.");

/// <summary>
Expand Down Expand Up @@ -527,11 +500,7 @@ TResult ExecuteReader<TState, TResult>(TState state, Func<IDataReader, TState, T
ValueTask<TResult> ExecuteReaderAsync<TState, TResult>(TState state, Func<IDataReader, TState, ValueTask<TResult>> transform, CommandBehavior behavior, CancellationToken token)
=> Captured() is { } captures
? ((ICaptureRunner)_command!).ExecuteReaderAsync(
captures,
state,
transform,
behavior,
token)
captures, state, transform, behavior, token)
: _call.IsBound
? _call.RunAsync(state, transform, behavior, token)
: Command.ExecuteReaderAsync(state, transform, behavior, token);
Expand Down Expand Up @@ -582,12 +551,8 @@ public void Read(Action<IEnumerable<T>> handler)
static (reader, s) =>
{
s.handler(RowReader.Stream(
s._source,
reader,
s._skip,
s._take,
!s.SingleResult,
s.abandon));
s._source, reader, s._skip, s._take,
!s.SingleResult, s.abandon));
return false;
},
Behavior,
Expand Down Expand Up @@ -628,14 +593,8 @@ static async (reader, s) =>
{
await s.handler(
StreamAsync(
s._source,
reader,
s._skip,
s._take,
s.SingleResult,
s.AsyncReads,
s.abandon,
s.token),
s._source, reader, s._skip, s._take,
s.SingleResult, s.AsyncReads, s.abandon, s.token),
s.token).ConfigureAwait(false);
return false;
},
Expand Down Expand Up @@ -850,24 +809,14 @@ static async (reader, s) =>
if (reader is DbDataReader db)
{
(bool found, T? item) = await RowReader.TryFirstAsync(
s._source,
db,
s._skip,
s._take,
s.AsyncReads,
s.token,
s.abandon).ConfigureAwait(false);
s._source, db, s._skip, s._take,
s.AsyncReads, s.token, s.abandon).ConfigureAwait(false);
return found ? item : default;
}

return RowReader.TryFirst(
s._source,
reader,
s._skip,
s._take,
out T? i,
s.abandon,
s.token)
s._source, reader, s._skip, s._take,
out T? i, s.abandon, s.token)
? i
: default;
},
Expand All @@ -888,24 +837,14 @@ static async (reader, s) =>
if (reader is DbDataReader db)
{
(bool found, T? item) = await RowReader.TrySingleAsync(
s._source,
db,
s._skip,
s._take,
s.AsyncReads,
s.token,
s.abandon).ConfigureAwait(false);
s._source, db, s._skip, s._take,
s.AsyncReads, s.token, s.abandon).ConfigureAwait(false);
return found ? item : default;
}

return RowReader.TrySingle(
s._source,
reader,
s._skip,
s._take,
out T? i,
s.abandon,
s.token)
s._source, reader, s._skip, s._take,
out T? i, s.abandon, s.token)
? i
: default;
},
Expand Down Expand Up @@ -1192,8 +1131,7 @@ public IAsyncEnumerable<T> ToPooledStream(
IAsyncEnumerable<T> rows = Flatten(
new ChunkStream<T>(
run is null ? this : WithRun(run),
Config,
cancellationToken),
Config, cancellationToken),
CancellationToken.None);

// Captured: the claim is at the flattened stream's GetAsyncEnumerator.
Expand Down Expand Up @@ -1259,10 +1197,7 @@ IAsyncEnumerable<T> StreamCore(
return bufferSize == 0
? new DirectStream<T>(this, stallTimeout, cancellationToken)
: new StallStream<T>(
this,
stallTimeout,
bufferSize,
cancellationToken);
this, stallTimeout, bufferSize, cancellationToken);
}

CaptureRun run = StreamRun(captures, cancellationToken);
Expand All @@ -1271,10 +1206,7 @@ IAsyncEnumerable<T> StreamCore(
bufferSize == 0
? new DirectStream<T>(claimed, stallTimeout, cancellationToken)
: new StallStream<T>(
claimed,
stallTimeout,
bufferSize,
cancellationToken),
claimed, stallTimeout, bufferSize, cancellationToken),
run);
}

Expand Down
20 changes: 5 additions & 15 deletions Source/Core/MappedViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ DbQueryCall call
DbQueryUsing bound
=> NewCore(null, bound.ToCall(), source, Single(singleResult)),
_ => NewCore(
command,
default,
source,
command, default, source,
Single(singleResult)
| (AsyncReads(command)
? QueryOptions.AsyncReads
Expand All @@ -367,33 +365,25 @@ internal static MappedQueryCore<T> ReaderCore<T>(
IDataReader reader,
IRowSource<T> source)
=> NewCore(
new ReaderExecutor(reader),
default,
source,
new ReaderExecutor(reader), default, source,
QueryOptions.SingleResult);

internal static MappedQueryCore<T> CommandCore<T>(
IDbCommand command,
IRowSource<T> source)
=> command is SingleResultDbCommand single
? NewCore(
new CommandExecutor(single.Command),
default,
source,
new CommandExecutor(single.Command), default, source,
QueryOptions.SingleResult)
: NewCore(
new CommandExecutor(command),
default,
source,
new CommandExecutor(command), default, source,
QueryOptions.None);

internal static MappedQueryCore<T> TableCore<T>(
DataTable table,
IRowSource<T> source)
=> NewCore(
new TableExecutor(table),
default,
source,
new TableExecutor(table), default, source,
QueryOptions.SingleResult);

/// <summary>
Expand Down