You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using Connected.Data.Storage;
|
|
|
|
|
using Connected.Entities.Storage;
|
|
|
|
|
|
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
|
|
|
|
|
|
|
|
internal sealed class TableReader<T> : TableCommand, IStorageReader<T>
|
|
|
|
|
{
|
|
|
|
|
public TableReader(IStorageOperation operation, IStorageConnection connection)
|
|
|
|
|
: base(operation, connection)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ImmutableList<T>?> Query()
|
|
|
|
|
{
|
|
|
|
|
if (Connection is null)
|
|
|
|
|
return default;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Connection.Query<T>(this);
|
|
|
|
|
|
|
|
|
|
if (Connection.Behavior == StorageConnectionMode.Isolated)
|
|
|
|
|
await Connection.Commit();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (Connection.Behavior == StorageConnectionMode.Isolated)
|
|
|
|
|
{
|
|
|
|
|
await Connection.Close();
|
|
|
|
|
await Connection.DisposeAsync();
|
|
|
|
|
|
|
|
|
|
Connection = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<T?> Select()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Connection is null)
|
|
|
|
|
return default;
|
|
|
|
|
|
|
|
|
|
var result = await Connection.Select<T>(this);
|
|
|
|
|
|
|
|
|
|
if (Connection.Behavior == StorageConnectionMode.Isolated)
|
|
|
|
|
await Connection.Commit();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (Connection.Behavior == StorageConnectionMode.Isolated)
|
|
|
|
|
{
|
|
|
|
|
await Connection.Close();
|
|
|
|
|
await Connection.DisposeAsync();
|
|
|
|
|
|
|
|
|
|
Connection = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IDataReader> OpenReader()
|
|
|
|
|
{
|
|
|
|
|
if (Connection is null)
|
|
|
|
|
return default;
|
|
|
|
|
|
|
|
|
|
return await Connection.OpenReader(this);
|
|
|
|
|
}
|
|
|
|
|
}
|