Skip to content

Commit 0f7e65c

Browse files
committed
Small improvements
- summaries; - awaiting fixed - formatting improvements
1 parent 6dc744e commit 0f7e65c

8 files changed

Lines changed: 79 additions & 56 deletions

File tree

Orm/Xtensive.Orm/Orm/Providers/Interfaces/IProviderExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
55
// Created: 2009.10.30
66

Orm/Xtensive.Orm/Orm/Providers/SqlSessionHandler.IProviderExecutor.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2010-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alex Yakunin
55
// Created: 2010.02.09
66

@@ -40,31 +40,35 @@ async Task<IEnumerator<Tuple>> IProviderExecutor.ExecuteTupleReaderAsync(QueryRe
4040
void IProviderExecutor.Store(IPersistDescriptor descriptor, IEnumerable<Tuple> tuples)
4141
{
4242
Prepare();
43-
foreach (var tuple in tuples)
43+
foreach (var tuple in tuples) {
4444
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.StoreRequest, tuple));
45-
using (var context = new CommandProcessorContext())
45+
}
46+
47+
using (var context = new CommandProcessorContext()) {
4648
commandProcessor.ExecuteTasks(context);
49+
}
4750
}
4851

49-
50-
52+
/// <inheritdoc/>
5153
async Task IProviderExecutor.StoreAsync(EnumerationContext enumerationContext,IPersistDescriptor descriptor, IEnumerable<Tuple> tuples, CancellationToken token)
5254
{
53-
await PrepareAsync(token);
55+
await PrepareAsync(token).ConfigureAwait(false);
5456

5557
if (tuples is ExecutableRawProvider rawProvider) {
56-
var enumerator = await rawProvider.GetEnumeratorAsync(enumerationContext, token);
58+
var enumerator = await rawProvider.GetEnumeratorAsync(enumerationContext, token).ConfigureAwait(false);
5759
while(enumerator.MoveNext()) {
5860
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.StoreRequest, enumerator.Current));
5961
}
6062
}
6163
else {
62-
foreach (var tuple in tuples)
64+
foreach (var tuple in tuples) {
6365
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.StoreRequest, tuple));
66+
}
6467
}
6568

66-
using (var context = new CommandProcessorContext())
67-
await commandProcessor.ExecuteTasksAsync(context, token);
69+
using (var context = new CommandProcessorContext()) {
70+
await commandProcessor.ExecuteTasksAsync(context, token).ConfigureAwait(false);
71+
}
6872
}
6973

7074
/// <inheritdoc/>

Orm/Xtensive.Orm/Orm/Providers/SqlSessionHandler.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2008-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Gamzov
55
// Created: 2008.05.20
66

77
using System;
88
using System.Collections.Generic;
9-
using System.Data;
109
using System.Linq;
1110
using System.Threading;
1211
using System.Threading.Tasks;
@@ -148,39 +147,43 @@ private void Prepare()
148147
{
149148
Session.EnsureNotDisposed();
150149
driver.EnsureConnectionIsOpen(Session, connection);
151-
foreach (var script in initializationSqlScripts)
152-
using (var command = connection.CreateCommand(script))
153-
driver.ExecuteNonQuery(Session, command);
150+
foreach (var script in initializationSqlScripts) {
151+
using (var command = connection.CreateCommand(script)) {
152+
_ = driver.ExecuteNonQuery(Session, command);
153+
}
154+
}
155+
154156
initializationSqlScripts.Clear();
155-
if (pendingTransaction==null)
157+
if (pendingTransaction == null)
156158
return;
157159
var transaction = pendingTransaction;
158160
pendingTransaction = null;
159-
if (connection.ActiveTransaction==null) // Handle external transactions
161+
if (connection.ActiveTransaction == null) // Handle external transactions
160162
driver.BeginTransaction(Session, connection, IsolationLevelConverter.Convert(transaction.IsolationLevel));
161163
}
162164

163165
private async Task PrepareAsync(CancellationToken cancellationToken)
164166
{
165167
Session.EnsureNotDisposed();
166-
if (connection.State != ConnectionState.Open)
167-
await driver.OpenConnectionAsync(Session, connection, cancellationToken).ConfigureAwait(false);
168+
await driver.EnsureConnectionIsOpenAsync(Session, connection);
168169

169170
try {
170-
foreach (var initializationSqlScript in initializationSqlScripts)
171-
using (var command = connection.CreateCommand(initializationSqlScript))
172-
await driver.ExecuteNonQueryAsync(Session, command, cancellationToken).ConfigureAwait(false);
171+
foreach (var initializationSqlScript in initializationSqlScripts) {
172+
using (var command = connection.CreateCommand(initializationSqlScript)) {
173+
_ = await driver.ExecuteNonQueryAsync(Session, command, cancellationToken).ConfigureAwait(false);
174+
}
175+
}
173176
}
174177
catch (OperationCanceledException) {
175178
connection.Close();
176179
throw;
177180
}
178181

179-
if (pendingTransaction==null)
182+
if (pendingTransaction == null)
180183
return;
181184
var transaction = pendingTransaction;
182185
pendingTransaction = null;
183-
if (connection.ActiveTransaction==null) // Handle external transactions
186+
if (connection.ActiveTransaction == null) // Handle external transactions
184187
driver.BeginTransaction(Session, connection, IsolationLevelConverter.Convert(transaction.IsolationLevel));
185188
}
186189

Orm/Xtensive.Orm/Orm/Providers/SqlStoreProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2008-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
55
// Created: 2008.09.05
66

@@ -32,6 +32,7 @@ protected override void OnBeforeEnumerate(Rse.Providers.EnumerationContext conte
3232
LockAndStore(context, Source);
3333
}
3434

35+
/// <inheritdoc/>
3536
protected override async Task OnBeforeEnumerateAsync(Rse.Providers.EnumerationContext context, CancellationToken token)
3637
{
3738
await base.OnBeforeEnumerateAsync(context, token);
@@ -40,7 +41,7 @@ protected override async Task OnBeforeEnumerateAsync(Rse.Providers.EnumerationCo
4041

4142
protected override void OnAfterEnumerate(Rse.Providers.EnumerationContext context)
4243
{
43-
ClearAndUnlock(context);
44+
_ = ClearAndUnlock(context);
4445
base.OnAfterEnumerate(context);
4546
}
4647

Orm/Xtensive.Orm/Orm/Providers/SqlTemporaryDataProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
55
// Created: 2009.11.13
66

@@ -43,7 +43,7 @@ protected async Task LockAndStoreAsync(Rse.Providers.EnumerationContext context,
4343
return;
4444
storageContext.SetValue(this, TemporaryTableLockName, tableLock);
4545
var executor = storageContext.Session.Services.Demand<IProviderExecutor>();
46-
await executor.StoreAsync(storageContext, tableDescriptor, data, token);
46+
await executor.StoreAsync(storageContext, tableDescriptor, data, token).ConfigureAwait(false);
4747
}
4848

4949
protected bool ClearAndUnlock(Rse.Providers.EnumerationContext context)

Orm/Xtensive.Orm/Orm/Providers/StorageDriver.Operations.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ public async Task OpenConnectionAsync(Session session, SqlConnection connection,
119119

120120
public void EnsureConnectionIsOpen(Session session, SqlConnection connection)
121121
{
122-
if (connection.State!=ConnectionState.Open)
122+
if (connection.State != ConnectionState.Open) {
123123
OpenConnection(session, connection);
124+
}
125+
}
126+
127+
public async Task EnsureConnectionIsOpenAsync(Session session, SqlConnection connection)
128+
{
129+
if (connection.State != ConnectionState.Open) {
130+
await OpenConnectionAsync(session, connection).ConfigureAwait(false);
131+
}
124132
}
125133

126134
public void CloseConnection(Session session, SqlConnection connection)

Orm/Xtensive.Orm/Orm/Rse/Providers/Executable/ExecutableRawProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2008-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kochetov
55
// Created: 2008.05.08
66

@@ -30,7 +30,7 @@ protected override void OnBeforeEnumerate(EnumerationContext context)
3030
/// <inheritdoc/>
3131
protected override async Task OnBeforeEnumerateAsync(EnumerationContext context, CancellationToken token)
3232
{
33-
await base.OnBeforeEnumerateAsync(context, token);
33+
await base.OnBeforeEnumerateAsync(context, token).ConfigureAwait(false);
3434
context.SetValue(this, CachedSourceName, Origin.CompiledSource.Invoke());
3535
}
3636

Orm/Xtensive.Orm/Orm/Rse/Providers/ExecutableProvider.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2008-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kochetov
55
// Created: 2008.07.07
66

@@ -35,19 +35,24 @@ public abstract class ExecutableProvider : Provider, IEnumerable<Tuple>
3535
protected virtual void OnBeforeEnumerate(EnumerationContext context)
3636
{
3737
foreach (var source in Sources) {
38-
var ep = source as ExecutableProvider;
39-
if (ep!=null)
38+
if (source is ExecutableProvider ep) {
4039
ep.OnBeforeEnumerate(context);
40+
}
4141
}
4242
}
4343

44+
/// <summary>
45+
/// Called when enumerator is created on this provider.
46+
/// </summary>
47+
/// <param name="context">The enumeration context.</param>
48+
/// <param name="token">The cancellation token for operation</param>
4449
protected virtual async Task OnBeforeEnumerateAsync(EnumerationContext context, CancellationToken token)
4550
{
4651
token.ThrowIfCancellationRequested();
4752
foreach (var source in Sources) {
48-
var ep = source as ExecutableProvider;
49-
if (ep != null)
50-
await ep.OnBeforeEnumerateAsync(context, token);
53+
if (source is ExecutableProvider ep) {
54+
await ep.OnBeforeEnumerateAsync(context, token).ConfigureAwait(false);
55+
}
5156
}
5257
}
5358

@@ -125,9 +130,10 @@ public async Task<IEnumerator<Tuple>> GetEnumeratorAsync(EnumerationContext cont
125130
{
126131
const string enumerationMarker = "Enumerated";
127132
var enumerated = context.GetValue<bool>(this, enumerationMarker);
128-
bool onEnumerationExecuted = false;
129-
if (!enumerated)
130-
await OnBeforeEnumerateAsync(context, token);
133+
var onEnumerationExecuted = false;
134+
if (!enumerated) {
135+
await OnBeforeEnumerateAsync(context, token).ConfigureAwait(false);
136+
}
131137
try {
132138
context.SetValue(this, enumerationMarker, true);
133139
var enumerator = (await OnEnumerateAsync(context, token).ConfigureAwait(false))
@@ -141,8 +147,9 @@ public async Task<IEnumerator<Tuple>> GetEnumeratorAsync(EnumerationContext cont
141147
return enumerator;
142148
}
143149
finally {
144-
if (!enumerated && !onEnumerationExecuted)
150+
if (!enumerated && !onEnumerationExecuted) {
145151
OnAfterEnumerate(context);
152+
}
146153
}
147154
}
148155

0 commit comments

Comments
 (0)