Skip to content

Commit f695bfb

Browse files
committed
Merge branch '6.0'
# Conflicts: # Extensions/Xtensive.Orm.BulkOperations/Internals/BulkDeleteOperation.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/BulkUpdateOperation.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/InsertOperation.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/Operation.cs # Orm/Xtensive.Orm.Tests/Storage/QueryBuilderTest.cs # Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryCommand.cs
2 parents 9c97700 + a52064f commit f695bfb

9 files changed

Lines changed: 77 additions & 29 deletions

File tree

ChangeLog/6.0.3_Z_Final.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[main] Provider for MS SQL Server was branched out into a separate project
22
[main] Events for changes cancelling ported from 5.0.x
3+
[main] QueryCommand now implements IDisposable interface
34
[main] TupleDescriptor no longer implements IList<T>
45
[main] TupleDescriptor.GetCommonPartLength(TupleDescriptor) method was removed
56
[main] TupleDescriptor.IsValueType(int) method was removed

Extensions/Xtensive.Orm.BulkOperations/Internals/BulkDeleteOperation.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-

1+
// Copyright (C) 2019-2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
25
using System;
36
using System.Linq;
47
using System.Threading;
@@ -22,12 +25,12 @@ protected override int ExecuteInternal()
2225
throw new NotImplementedException("Inheritance is not implemented");
2326
}
2427

25-
base.ExecuteInternal();
28+
_ = base.ExecuteInternal();
2629

2730
var request = GetRequest(query);
2831
Bindings = request.ParameterBindings.ToList();
2932

30-
var command = CreateCommand(request);
33+
using var command = CreateCommand(request);
3134
return command.ExecuteNonQuery();
3235
}
3336

@@ -103,4 +106,4 @@ public BulkDeleteOperation(IQueryable<T> query)
103106
this.query = query;
104107
}
105108
}
106-
}
109+
}

Extensions/Xtensive.Orm.BulkOperations/Internals/BulkUpdateOperation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ protected override int ExecuteInternal()
3030
throw new NotImplementedException("Inheritance is not implemented");
3131
}
3232

33-
base.ExecuteInternal();
33+
_ = base.ExecuteInternal();
3434
var request = GetRequest(query);
3535
Bindings = request.ParameterBindings.ToList();
3636

37-
var command = CreateCommand(request);
37+
using var command = CreateCommand(request);
3838
return command.ExecuteNonQuery();
3939
}
4040

@@ -157,4 +157,4 @@ public BulkUpdateOperation(IUpdatable<T> query)
157157
setOperation=new SetOperation<T>(this, descriptors);
158158
}
159159
}
160-
}
160+
}

Extensions/Xtensive.Orm.BulkOperations/Internals/InsertOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override int ExecuteInternal()
2828
}
2929
Bindings = new List<QueryParameterBinding>();
3030

31-
var command = CreateCommand();
31+
using var command = CreateCommand();
3232
return command.ExecuteNonQuery();
3333
}
3434

@@ -119,4 +119,4 @@ private void AddKey(List<SetDescriptor> descriptors)
119119

120120
public Key Key { get; private set; }
121121
}
122-
}
122+
}

Extensions/Xtensive.Orm.BulkOperations/Internals/Operation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ protected Operation(QueryProvider queryProvider)
8888
QueryBuilder = Session.Services.Get<QueryBuilder>();
8989
}
9090
}
91-
}
91+
}

Orm/Xtensive.Orm.Tests/Issues/IssueJira0571_MySqlKeyGenerationProblem.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2014 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2015-2020 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 Kulakov
55
// Created: 2015.02.03
66

@@ -138,7 +138,8 @@ private void CheckSchemaGenerators(Schema schema, string generatorName, Session
138138
var query = GetQuery(generatorTable);
139139
var queryBuilder = GetQueryBuilder(session);
140140
var queryCompilationResult = queryBuilder.CompileQuery(query);
141-
var command = queryBuilder.CreateCommand(queryBuilder.CreateRequest(queryCompilationResult, Enumerable.Empty<Services.QueryParameterBinding>()));
141+
var queryRequest = queryBuilder.CreateRequest(queryCompilationResult, Enumerable.Empty<Services.QueryParameterBinding>());
142+
using var command = queryBuilder.CreateCommand(queryRequest);
142143
var rowCount = command.ExecuteScalar();
143144
Assert.AreEqual(expectedValue, rowCount);
144145
}

Orm/Xtensive.Orm.Tests/Storage/QueryBuilderTest.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public void ModifyQueryTest()
6868
var command = builder.CreateCommand(request);
6969
Assert.That(command, Is.Not.Null);
7070

71-
var result = Convert.ToInt32(command.ExecuteScalar());
72-
Assert.That(result, Is.EqualTo(1));
71+
using (command) {
72+
var result = Convert.ToInt32(command.ExecuteScalar());
73+
Assert.That(result, Is.EqualTo(1));
74+
}
7375

7476
tx.Complete();
7577
}
@@ -89,17 +91,19 @@ public void ComposeQuery()
8991
var compiled = builder.CompileQuery(select);
9092
Assert.That(compiled, Is.Not.Null);
9193

92-
var request = builder.CreateRequest(compiled, new[] {binding});
94+
var request = builder.CreateRequest(compiled, new[] { binding });
9395
Assert.That(request, Is.Not.Null);
9496

9597
var command = builder.CreateCommand(request);
9698
Assert.That(command, Is.Not.Null);
9799

98-
var result = Convert.ToInt32(command.ExecuteScalar());
99-
Assert.That(result, Is.EqualTo(43));
100+
using (command) {
101+
var result = Convert.ToInt32(command.ExecuteScalar());
102+
Assert.That(result, Is.EqualTo(43));
103+
}
100104

101105
tx.Complete();
102106
}
103107
}
104108
}
105-
}
109+
}

Orm/Xtensive.Orm.Tests/Upgrade/SchemaSharing/QueryBuilder/Model.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2017 Xtensive LLC.
1+
// Copyright (C) 2017 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -316,8 +316,7 @@ private object ExecuteScalar(Services.QueryBuilder queryBuilder, ISqlCompileUnit
316316
{
317317
var commandtext = queryBuilder.CompileQuery(query);
318318
var request = queryBuilder.CreateRequest(commandtext, Enumerable.Empty<Services.QueryParameterBinding>());
319-
var command = queryBuilder.CreateCommand(request);
320-
319+
using var command = queryBuilder.CreateCommand(request);
321320
return command.ExecuteScalar();
322321
}
323322

Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryCommand.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// Created by: Denis Krjuchkov
55
// Created: 2012.02.27
66

7+
using System;
78
using System.Data.Common;
9+
using System.Runtime.CompilerServices;
810
using System.Threading;
911
using System.Threading.Tasks;
1012
using Xtensive.Orm.Providers;
@@ -16,23 +18,35 @@ namespace Xtensive.Orm.Services
1618
/// Unlike <see cref="DbCommand"/> this type is aware of <see cref="Session.Events"/>
1719
/// and does all necessary logging of executed SQL.
1820
/// </summary>
19-
public sealed class QueryCommand
21+
public sealed class QueryCommand : IDisposable
2022
{
2123
private readonly StorageDriver driver;
2224
private readonly Session session;
2325
private readonly DbCommand realCommand;
2426

27+
private bool disposed;
28+
2529
/// <summary>
2630
/// Gets SQL query to execute.
2731
/// </summary>
28-
public string CommandText => realCommand.CommandText;
32+
public string CommandText
33+
{
34+
get {
35+
EnsureNotDisposed();
36+
return realCommand.CommandText;
37+
}
38+
}
2939

3040
/// <summary>
3141
/// Executes query and returns <see cref="DbDataReader"/>
3242
/// for retrieving query results.
3343
/// </summary>
3444
/// <returns><see cref="DbDataReader"/> to use.</returns>
35-
public DbDataReader ExecuteReader() => driver.ExecuteReader(session, realCommand);
45+
public DbDataReader ExecuteReader()
46+
{
47+
EnsureNotDisposed();
48+
return driver.ExecuteReader(session, realCommand);
49+
}
3650

3751
/// <summary>
3852
/// Executes query and returns <see cref="DbDataReader"/>
@@ -49,7 +63,11 @@ public Task<DbDataReader> ExecuteReaderAsync(CancellationToken token = default)
4963
/// Executes query and returns number of affected rows.
5064
/// </summary>
5165
/// <returns>Number of affected rows.</returns>
52-
public int ExecuteNonQuery() => driver.ExecuteNonQuery(session, realCommand);
66+
public int ExecuteNonQuery()
67+
{
68+
EnsureNotDisposed();
69+
return driver.ExecuteNonQuery(session, realCommand);
70+
}
5371

5472
/// <summary>
5573
/// Asynchronously executes query and returns number of affected rows.
@@ -65,7 +83,11 @@ public Task<int> ExecuteNonQueryAsync(CancellationToken token = default) =>
6583
/// Executes query and returns scalar result.
6684
/// </summary>
6785
/// <returns>Scalar result of query.</returns>
68-
public object ExecuteScalar() => driver.ExecuteScalar(session, realCommand);
86+
public object ExecuteScalar()
87+
{
88+
EnsureNotDisposed();
89+
return driver.ExecuteScalar(session, realCommand);
90+
}
6991

7092
/// <summary>
7193
/// Asynchronously executes query and returns scalar result.
@@ -77,6 +99,24 @@ public Task<int> ExecuteNonQueryAsync(CancellationToken token = default) =>
7799
public Task<object> ExecuteScalarAsync(CancellationToken token = default) =>
78100
driver.ExecuteScalarAsync(session, realCommand, token);
79101

102+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
103+
private void EnsureNotDisposed()
104+
{
105+
if (disposed) {
106+
throw new ObjectDisposedException(null);
107+
}
108+
}
109+
110+
/// <inheritdoc/>
111+
public void Dispose()
112+
{
113+
if (disposed) {
114+
return;
115+
}
116+
disposed = true;
117+
realCommand?.Dispose();
118+
}
119+
80120
// Constructors
81121

82122
internal QueryCommand(StorageDriver driver, Session session, DbCommand realCommand)
@@ -86,4 +126,4 @@ internal QueryCommand(StorageDriver driver, Session session, DbCommand realComma
86126
this.realCommand = realCommand;
87127
}
88128
}
89-
}
129+
}

0 commit comments

Comments
 (0)