|
@@ -1,11 +1,10 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
-using System.Data.Common;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
-using appMpower.Db;
|
|
|
+using appMpower.Data;
|
|
|
using PlatformBenchmarks;
|
|
|
|
|
|
namespace appMpower
|
|
@@ -32,14 +31,14 @@ namespace appMpower
|
|
|
|
|
|
public static async Task<World> LoadSingleQueryRow()
|
|
|
{
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- var (pooledCommand, _) = CreateReadCommand(pooledConnection);
|
|
|
+ var (dbCommand, _) = CreateReadCommand(pooledConnection);
|
|
|
|
|
|
- using (pooledCommand)
|
|
|
+ using (dbCommand)
|
|
|
{
|
|
|
- var world = await ReadSingleRow(pooledCommand);
|
|
|
+ var world = await ReadSingleRow(dbCommand);
|
|
|
|
|
|
return world;
|
|
|
}
|
|
@@ -49,16 +48,16 @@ namespace appMpower
|
|
|
{
|
|
|
var worlds = new World[count];
|
|
|
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- var (pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
+ var (dbCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
|
|
|
- using (pooledCommand)
|
|
|
+ using (dbCommand)
|
|
|
{
|
|
|
for (int i = 0; i < count; i++)
|
|
|
{
|
|
|
- worlds[i] = await ReadSingleRow(pooledCommand);
|
|
|
+ worlds[i] = await ReadSingleRow(dbCommand);
|
|
|
dbDataParameter.Value = _random.Next(1, 10001);
|
|
|
}
|
|
|
}
|
|
@@ -70,14 +69,14 @@ namespace appMpower
|
|
|
{
|
|
|
var fortunes = new List<Fortune>();
|
|
|
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- var pooledCommand = new PooledCommand("SELECT * FROM fortune", pooledConnection);
|
|
|
+ var dbCommand = new DbCommand("SELECT * FROM fortune", pooledConnection);
|
|
|
|
|
|
- using (pooledCommand)
|
|
|
+ using (dbCommand)
|
|
|
{
|
|
|
- var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.SingleResult & CommandBehavior.SequentialAccess);
|
|
|
+ var dataReader = await dbCommand.ExecuteReaderAsync(CommandBehavior.SingleResult & CommandBehavior.SequentialAccess);
|
|
|
|
|
|
while (dataReader.Read())
|
|
|
{
|
|
@@ -107,7 +106,7 @@ namespace appMpower
|
|
|
{
|
|
|
var worlds = new World[count];
|
|
|
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
var (queryCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
@@ -121,7 +120,7 @@ namespace appMpower
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- using var updateCommand = new PooledCommand(PlatformBenchmarks.BatchUpdateString.Query(count), pooledConnection);
|
|
|
+ using var updateCommand = new DbCommand(PlatformBenchmarks.BatchUpdateString.Query(count), pooledConnection);
|
|
|
|
|
|
var ids = PlatformBenchmarks.BatchUpdateString.Ids;
|
|
|
var randoms = PlatformBenchmarks.BatchUpdateString.Randoms;
|
|
@@ -152,20 +151,20 @@ namespace appMpower
|
|
|
return worlds;
|
|
|
}
|
|
|
|
|
|
- private static (PooledCommand pooledCommand, IDbDataParameter dbDataParameter) CreateReadCommand(PooledConnection pooledConnection)
|
|
|
+ private static (DbCommand dbCommand, IDbDataParameter dbDataParameter) CreateReadCommand(DbConnection pooledConnection)
|
|
|
{
|
|
|
#if ADO
|
|
|
- var pooledCommand = new PooledCommand("SELECT * FROM world WHERE id=@Id", pooledConnection);
|
|
|
+ var dbCommand = new DbCommand("SELECT * FROM world WHERE id=@Id", pooledConnection);
|
|
|
#else
|
|
|
- var pooledCommand = new PooledCommand("SELECT * FROM world WHERE id=?", pooledConnection);
|
|
|
+ var dbCommand = new DbCommand("SELECT * FROM world WHERE id=?", pooledConnection);
|
|
|
#endif
|
|
|
|
|
|
- return (pooledCommand, pooledCommand.CreateParameter("Id", DbType.Int32, _random.Next(1, 10001)));
|
|
|
+ return (dbCommand, dbCommand.CreateParameter("Id", DbType.Int32, _random.Next(1, 10001)));
|
|
|
}
|
|
|
|
|
|
- private static async Task<World> ReadSingleRow(PooledCommand pooledCommand)
|
|
|
+ private static async Task<World> ReadSingleRow(DbCommand dbCommand)
|
|
|
{
|
|
|
- var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.SingleRow & CommandBehavior.SequentialAccess);
|
|
|
+ var dataReader = await dbCommand.ExecuteReaderAsync(CommandBehavior.SingleRow & CommandBehavior.SequentialAccess);
|
|
|
|
|
|
dataReader.Read();
|
|
|
|
|
@@ -203,17 +202,17 @@ namespace appMpower
|
|
|
queryString = _queriesMultipleRows[count] = PlatformBenchmarks.StringBuilderCache.GetStringAndRelease(stringBuilder);
|
|
|
}
|
|
|
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- using var pooledCommand = new PooledCommand(queryString, pooledConnection);
|
|
|
+ using var dbCommand = new DbCommand(queryString, pooledConnection);
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
{
|
|
|
- pooledCommand.CreateParameter(ids[i], DbType.Int32, _random.Next(1, 10001));
|
|
|
+ dbCommand.CreateParameter(ids[i], DbType.Int32, _random.Next(1, 10001));
|
|
|
}
|
|
|
|
|
|
- var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.Default & CommandBehavior.SequentialAccess);
|
|
|
+ var dataReader = await dbCommand.ExecuteReaderAsync(CommandBehavior.Default & CommandBehavior.SequentialAccess);
|
|
|
|
|
|
do
|
|
|
{
|
|
@@ -233,9 +232,9 @@ namespace appMpower
|
|
|
return worlds;
|
|
|
}
|
|
|
|
|
|
- public static string ReadColumn(DbDataReader dbDataReader, int column)
|
|
|
+ public static string ReadColumn(IDataReader dataReader, int column)
|
|
|
{
|
|
|
- long size = dbDataReader.GetBytes(column, 0, null, 0, 0); //get the length of data
|
|
|
+ long size = dataReader.GetBytes(column, 0, null, 0, 0); //get the length of data
|
|
|
byte[] values = new byte[size];
|
|
|
|
|
|
int bufferSize = 64;
|
|
@@ -244,7 +243,7 @@ namespace appMpower
|
|
|
|
|
|
while (bytesRead < size)
|
|
|
{
|
|
|
- bytesRead += dbDataReader.GetBytes(column, currentPosition, values, currentPosition, bufferSize);
|
|
|
+ bytesRead += dataReader.GetBytes(column, currentPosition, values, currentPosition, bufferSize);
|
|
|
currentPosition += bufferSize;
|
|
|
}
|
|
|
|
|
@@ -253,12 +252,12 @@ namespace appMpower
|
|
|
|
|
|
public static async Task PopulateCache()
|
|
|
{
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- var (pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
+ var (dbCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
|
|
|
- using (pooledCommand)
|
|
|
+ using (dbCommand)
|
|
|
{
|
|
|
var cacheKeys = _cacheKeys;
|
|
|
var cache = _cache;
|
|
@@ -266,7 +265,7 @@ namespace appMpower
|
|
|
for (var i = 1; i < 10001; i++)
|
|
|
{
|
|
|
dbDataParameter.Value = i;
|
|
|
- cache.Set<CachedWorld>(cacheKeys[i], await ReadSingleRow(pooledCommand));
|
|
|
+ cache.Set<CachedWorld>(cacheKeys[i], await ReadSingleRow(dbCommand));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -299,16 +298,16 @@ namespace appMpower
|
|
|
|
|
|
static async Task<CachedWorld[]> LoadUncachedQueries(int id, int i, int count, CachedWorld[] result)
|
|
|
{
|
|
|
- using var pooledConnection = new PooledConnection(DataProvider.ConnectionString);
|
|
|
+ using var pooledConnection = new DbConnection(DbProviderFactory.ConnectionString);
|
|
|
await pooledConnection.OpenAsync();
|
|
|
|
|
|
- var (pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
+ var (dbCommand, dbDataParameter) = CreateReadCommand(pooledConnection);
|
|
|
|
|
|
- using (pooledCommand)
|
|
|
+ using (dbCommand)
|
|
|
{
|
|
|
Func<ICacheEntry, Task<CachedWorld>> create = async (entry) =>
|
|
|
{
|
|
|
- return await ReadSingleRow(pooledCommand);
|
|
|
+ return await ReadSingleRow(dbCommand);
|
|
|
};
|
|
|
|
|
|
var cacheKeys = _cacheKeys;
|