Skip to content

Commit

Permalink
Begin all transaction asyncronasley
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Nov 14, 2023
1 parent c3c962f commit fd9f614
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion samples/YesSql.Bench/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static async Task MainAsync(string[] args)
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel);
var builder = new SchemaBuilder(configuration, transaction);

await builder.CreateMapIndexTableAsync<UserByName>(c => c
Expand Down
2 changes: 1 addition & 1 deletion samples/YesSql.Samples.FullText/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task Main(string[] args)
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(store.Configuration, transaction);

await builder.CreateReduceIndexTableAsync<ArticleByWord>(table => table
Expand Down
2 changes: 1 addition & 1 deletion samples/YesSql.Samples.Hi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static async Task MainAsync(string[] args)
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(store.Configuration, transaction);

await builder.CreateMapIndexTableAsync<BlogPostByAuthor>(table => table
Expand Down
4 changes: 2 additions & 2 deletions samples/YesSql.Samples.Performance/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private async Task InitializeAsync()
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction();
await using var transaction = await connection.BeginTransactionAsync();
var builder = new SchemaBuilder(configuration, transaction);

await builder.DropTableAsync("UserByName");
Expand All @@ -52,7 +52,7 @@ private async Task InitializeAsync()
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction();
await using var transaction = await connection.BeginTransactionAsync();
var builder = new SchemaBuilder(configuration, transaction);

await builder.CreateMapIndexTableAsync<UserByName>(table => table
Expand Down
2 changes: 1 addition & 1 deletion samples/YesSql.Samples.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
await using var connection = store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(store.Configuration.IsolationLevel);
var schemaBuilder = new SchemaBuilder(store.Configuration, transaction);

await schemaBuilder.CreateMapIndexTableAsync<BlogPostIndex>(table => table
Expand Down
6 changes: 3 additions & 3 deletions src/YesSql.Core/Services/DbBlockIdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private async Task LeaseRangeAsync(Range range)
// Ensure we overwrite the value that has been read by this
// instance in case another client is trying to lease a range
// at the same time
await using (var transaction = connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
await using (var transaction = await connection.BeginTransactionAsync(System.Data.IsolationLevel.ReadCommitted))
{
try
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public async Task InitializeCollectionAsync(IConfiguration configuration, string
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using (var transaction = connection.BeginTransaction(configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel))
{
// Does the record already exist?
var selectCommand = transaction.Connection.CreateCommand();
Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task InitializeCollectionAsync(IConfiguration configuration, string
// Try to create a new record. If it fails, retry reading the record.
try
{
await using var transaction = connection.BeginTransaction(configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel);
// To prevent concurrency issues when creating this record (it must be unique)
// we generate a random collection name, then update it safely

Expand Down
2 changes: 1 addition & 1 deletion src/YesSql.Core/Services/DefaultIdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task InitializeCollectionAsync(IConfiguration configuration, string
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel);
var tableName = configuration.TableNameConvention.GetDocumentTable(collection);

var sql = "SELECT MAX(" + _dialect.QuoteForColumnName("Id") + ") FROM " + _dialect.QuoteForTableName(configuration.TablePrefix + tableName, configuration.Schema);
Expand Down
6 changes: 3 additions & 3 deletions src/YesSql.Core/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task InitializeAsync()
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(Configuration.IsolationLevel);

var builder = new SchemaBuilder(Configuration, transaction);

Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task InitializeCollectionAsync(string collection)
catch
{
await result.CloseAsync();
await using var migrationTransaction = connection.BeginTransaction();
await using var migrationTransaction = await connection.BeginTransactionAsync();
var migrationBuilder = new SchemaBuilder(Configuration, migrationTransaction);

try
Expand All @@ -166,7 +166,7 @@ await migrationBuilder.AlterTableAsync(documentTable, table => table
}
catch
{
await using var transaction = connection.BeginTransaction();
await using var transaction = await connection.BeginTransactionAsync();
var builder = new SchemaBuilder(Configuration, transaction);

try
Expand Down
16 changes: 8 additions & 8 deletions test/YesSql.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected virtual async Task CleanDatabaseAsync(IConfiguration configuration, bo
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel);
var builder = new SchemaBuilder(configuration, transaction, throwOnError);

await builder.DropReduceIndexTableAsync<ArticlesByDay>();
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task CreateTablesAsync(IConfiguration configuration)
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(configuration.IsolationLevel);
var builder = new SchemaBuilder(configuration, transaction);

await builder.CreateReduceIndexTableAsync<ArticlesByDay>(column => column
Expand Down Expand Up @@ -5211,7 +5211,7 @@ public virtual async Task ShouldRenameColumn()

try
{
await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);

var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -5224,7 +5224,7 @@ public virtual async Task ShouldRenameColumn()
// Do nothing if the table can't be dropped
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -5243,7 +5243,7 @@ await builder.CreateTableAsync(table, column => column
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var sqlSelect = string.Format("SELECT {0} FROM {1}",
_store.Configuration.SqlDialect.QuoteForColumnName(column1),
Expand All @@ -5257,7 +5257,7 @@ await builder.CreateTableAsync(table, column => column
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -5268,7 +5268,7 @@ await builder.AlterTableAsync(table, column => column
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var sqlSelect = string.Format("SELECT {0} FROM {1}",
_store.Configuration.SqlDialect.QuoteForColumnName(column2),
Expand Down Expand Up @@ -5508,7 +5508,7 @@ public async Task ShouldCreateAndIndexPropertyWithMaximumKeyLengths()
{
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand Down
18 changes: 9 additions & 9 deletions test/YesSql.Tests/MySqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task ThrowsWhenIndexKeyLengthExceeded()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -99,7 +99,7 @@ public async Task ShouldCreatePropertyIndexWithSpecifiedLength()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -125,7 +125,7 @@ public async Task ThrowsWhenIndexKeysWithBitsLengthExceeded()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -150,7 +150,7 @@ public async Task ThrowsWhenIndexKeysLengthExceeded()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -173,7 +173,7 @@ public async Task ShouldCreatePropertyIndexWithMaxKey()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -197,7 +197,7 @@ public async Task ShouldCreateIndexPropertyWithMaxKeys()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder.DropMapIndexTableAsync<PropertyIndex>();
Expand All @@ -223,7 +223,7 @@ public async Task ShouldCreateIndexPropertyWithMaxBitKeys()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel);
await using var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel);
var builder = new SchemaBuilder(_store.Configuration, transaction);

await builder
Expand Down Expand Up @@ -252,7 +252,7 @@ public async Task ShouldCreateHashedIndexKeyName()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -267,7 +267,7 @@ await builder.CreateReduceIndexTableAsync<PersonsByNameCol>(column => column
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand Down
8 changes: 4 additions & 4 deletions test/YesSql.Tests/PostgreSqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task ShouldIndexPropertyKeys()
{
await connection.OpenAsync();

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -54,7 +54,7 @@ public async Task ShouldIndexPropertyKeys()
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);
await builder
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task ShouldCreateHashedIndexKeyName()
await using var connection = _store.Configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand All @@ -110,7 +110,7 @@ await builder.CreateReduceIndexTableAsync<PersonsByNameCol>(column => column
await transaction.CommitAsync();
}

await using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel))
await using (var transaction = await connection.BeginTransactionAsync(_store.Configuration.IsolationLevel))
{
var builder = new SchemaBuilder(_store.Configuration, transaction);

Expand Down
Loading

0 comments on commit fd9f614

Please sign in to comment.