Skip to content

Commit ccb73e3

Browse files
committed
Merge branch '6.0' into master
# Conflicts: # Orm/Xtensive.Orm.Firebird/Sql.Drivers.Firebird/DriverFactory.cs # Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/DriverFactory.cs # Orm/Xtensive.Orm.Oracle/Sql.Drivers.Oracle/DriverFactory.cs # Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/DriverFactory.cs # Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/Connection.cs # Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/DriverFactory.cs # Orm/Xtensive.Orm.Sqlite/Sql.Drivers.Sqlite/DriverFactory.cs # Orm/Xtensive.Orm.Tests.Framework/Xtensive.Orm.Tests.Framework.csproj # Orm/Xtensive.Orm.Tests.Sql/DriverFactoryTest.cs # Orm/Xtensive.Orm.Tests/Storage/ConnectionAccessorTest.cs # Orm/Xtensive.Orm/Orm/Configuration/DomainTypeRegistry.cs # Orm/Xtensive.Orm/Orm/ConnectionErrorEventData.cs # Orm/Xtensive.Orm/Orm/ConnectionEventData.cs # Orm/Xtensive.Orm/Orm/ConnectionInitEventData.cs # Orm/Xtensive.Orm/Orm/Interfaces/DbConnectionAccessor.cs # Orm/Xtensive.Orm/Orm/Interfaces/IDbConnectionAccessor.cs # Orm/Xtensive.Orm/Orm/Internals/CompiledQueryRunner.cs # Orm/Xtensive.Orm/Orm/Providers/StorageDriver.cs # Orm/Xtensive.Orm/Sql/DbConnectionAccessorExtension.cs # Orm/Xtensive.Orm/Sql/SqlConnection.cs # Orm/Xtensive.Orm/Sql/SqlExtensions.cs # Orm/Xtensive.Orm/Sql/SqlHelper.cs # Orm/Xtensive.Orm/Xtensive.Orm.csproj # Publish/NuGetPublish.csproj # Version.props
2 parents 61508e2 + 9d3e71c commit ccb73e3

File tree

14 files changed

+211
-43
lines changed

14 files changed

+211
-43
lines changed

ChangeLog/6.0.7_Z_Final.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[main] Fixed issue of actual NULL constant being treated as a caching value
2+
[main] Fixed rare case of infinite loop on batching commands
3+
[main] Improved VS compatibility by not processing design-time builds
4+
[main] Introduced IDbConnectionAccessor that gives access to certain stages of connection opening

Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/DriverFactory.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ protected override async Task<SqlDriver> CreateDriverAsync(
103103
return CreateDriverInstance(connectionString, version, defaultSchema);
104104
}
105105
}
106-
107106
private static SqlDriver CreateDriverInstance(string connectionString, Version version, DefaultSchemaInfo defaultSchema)
108107
{
109108
var coreServerInfo = new CoreServerInfo {
@@ -191,5 +190,28 @@ await SqlHelper.NotifyConnectionInitializingAsync(acessors,
191190
}
192191
}
193192
}
193+
194+
private void OpenConnectionFast(MySqlConnection connection, SqlDriverConfiguration configuration)
195+
{
196+
connection.Open();
197+
SqlHelper.ExecuteInitializationSql(connection, configuration);
198+
}
199+
200+
private void OpenConnectionWithNotification(MySqlConnection connection, SqlDriverConfiguration configuration)
201+
{
202+
var accessors = configuration.DbConnectionAccessors;
203+
SqlHelper.NotifyConnectionOpening(accessors, connection);
204+
try {
205+
connection.Open();
206+
if (!string.IsNullOrEmpty(configuration.ConnectionInitializationSql))
207+
SqlHelper.NotifyConnectionInitializing(accessors, connection, configuration.ConnectionInitializationSql);
208+
SqlHelper.ExecuteInitializationSql(connection, configuration);
209+
SqlHelper.NotifyConnectionOpened(accessors, connection);
210+
}
211+
catch (Exception ex) {
212+
SqlHelper.NotifyConnectionOpeningFailed(accessors, connection, ex);
213+
throw;
214+
}
215+
}
194216
}
195-
}
217+
}

Orm/Xtensive.Orm.Oracle/Sql.Drivers.Oracle/DriverFactory.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,28 @@ await SqlHelper.NotifyConnectionInitializingAsync(accessors,
184184
}
185185
}
186186
}
187+
188+
private void OpenConnectionFast(OracleConnection connection, SqlDriverConfiguration configuration)
189+
{
190+
connection.Open();
191+
SqlHelper.ExecuteInitializationSql(connection, configuration);
192+
}
193+
194+
private void OpenConnectionWithNotification(OracleConnection connection, SqlDriverConfiguration configuration)
195+
{
196+
var accessors = configuration.DbConnectionAccessors;
197+
SqlHelper.NotifyConnectionOpening(accessors, connection);
198+
try {
199+
connection.Open();
200+
if (!string.IsNullOrEmpty(configuration.ConnectionInitializationSql))
201+
SqlHelper.NotifyConnectionInitializing(accessors, connection, configuration.ConnectionInitializationSql);
202+
SqlHelper.ExecuteInitializationSql(connection, configuration);
203+
SqlHelper.NotifyConnectionOpened(accessors, connection);
204+
}
205+
catch (Exception ex) {
206+
SqlHelper.NotifyConnectionOpeningFailed(accessors, connection, ex);
207+
throw;
208+
}
209+
}
187210
}
188-
}
211+
}

Orm/Xtensive.Orm.Sqlite/Sql.Drivers.Sqlite/DriverFactory.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,28 @@ await SqlHelper.NotifyConnectionInitializingAsync(accessors,
165165
}
166166
}
167167
}
168+
169+
private void OpenConnectionFast(SQLiteConnection connection, SqlDriverConfiguration configuration)
170+
{
171+
connection.Open();
172+
SqlHelper.ExecuteInitializationSql(connection, configuration);
173+
}
174+
175+
private void OpenConnectionWithNotification(SQLiteConnection connection, SqlDriverConfiguration configuration)
176+
{
177+
var accessors = configuration.DbConnectionAccessors;
178+
SqlHelper.NotifyConnectionOpening(accessors, connection);
179+
try {
180+
connection.Open();
181+
if (!string.IsNullOrEmpty(configuration.ConnectionInitializationSql))
182+
SqlHelper.NotifyConnectionInitializing(accessors, connection, configuration.ConnectionInitializationSql);
183+
SqlHelper.ExecuteInitializationSql(connection, configuration);
184+
SqlHelper.NotifyConnectionOpened(accessors, connection);
185+
}
186+
catch (Exception ex) {
187+
SqlHelper.NotifyConnectionOpeningFailed(accessors, connection, ex);
188+
throw;
189+
}
190+
}
168191
}
169-
}
192+
}

Orm/Xtensive.Orm.Tests.Framework/Xtensive.Orm.Tests.Framework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3939
</None>
4040
</ItemGroup>
41-
</Project>
41+
</Project>

Orm/Xtensive.Orm.Tests.Sql/DriverFactoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,4 @@ private static string InitQueryPerProvider(string currentProvider)
375375
}
376376
}
377377
}
378-
}
378+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (C) 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.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using NUnit.Framework;
10+
using Xtensive.Orm.Configuration;
11+
using Xtensive.Orm.Tests.Issues.IssueGithub0150_ClosureProblemModel;
12+
13+
namespace Xtensive.Orm.Tests.Issues.IssueGithub0150_ClosureProblemModel
14+
{
15+
[HierarchyRoot]
16+
public class TestOperation : Entity
17+
{
18+
[Key, Field]
19+
public long ID { get; private set; }
20+
21+
[Field]
22+
[Association(OnOwnerRemove = OnRemoveAction.Clear, OnTargetRemove = OnRemoveAction.Deny, PairTo = "Operation")]
23+
public EntitySet<TestWorkOrder> WorkOrders { get; private set; }
24+
25+
public string GetErpOrderReference()
26+
{
27+
var erpReferences = Session.Query.Execute(q => q.All<TestWorkOrder>()
28+
.Where(w => w.Operation == this)
29+
.Select(w => w.Str));
30+
31+
var result = string.Join(" / ", erpReferences.ToArray());
32+
return result;
33+
}
34+
35+
public TestOperation(TestWorkOrder wo)
36+
{
37+
if (wo == null)
38+
throw new ArgumentNullException(nameof(wo));
39+
_ = WorkOrders.Add(wo);
40+
}
41+
}
42+
43+
[HierarchyRoot]
44+
public class TestWorkOrder : Entity
45+
{
46+
[Key, Field]
47+
public long ID { get; private set; }
48+
49+
[Field]
50+
public TestOperation Operation { get; private set; }
51+
52+
[Field]
53+
public string Str { get; set; }
54+
}
55+
}
56+
57+
namespace Xtensive.Orm.Tests.Issues
58+
{
59+
public class IssueGithub0149_ParameterReplacerHandlesNullConstsIncorrectly : AutoBuildTest
60+
{
61+
protected override DomainConfiguration BuildConfiguration()
62+
{
63+
var config = base.BuildConfiguration();
64+
config.Types.Register(typeof(TestWorkOrder));
65+
config.Types.Register(typeof(TestOperation));
66+
return config;
67+
}
68+
69+
[Test]
70+
public void MainTest()
71+
{
72+
using(var session = Domain.OpenSession())
73+
using(var tx = session.OpenTransaction()) {
74+
var wo = new TestWorkOrder {
75+
Str = "A"
76+
};
77+
var op = new TestOperation(wo);
78+
var erpOrder = op.GetErpOrderReference();
79+
Assert.AreEqual(wo.Str, erpOrder);
80+
}
81+
}
82+
}
83+
}

Orm/Xtensive.Orm.Tests/Storage/ConnectionAccessorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public DummyEntity(Session session)
133133
namespace Xtensive.Orm.Tests.Storage
134134
{
135135
[TestFixture]
136-
public class ConnectionAccessorTest
136+
public sealed class ConnectionAccessorTest
137137
{
138138
[Test]
139139
public void DomainRegistryTest()
@@ -206,7 +206,7 @@ public void SessionConnectionAccessorsTest()
206206
using (var session = domain.OpenSession()) {
207207
var nativeHandler = (SqlSessionHandler) session.Handler;
208208
var extension = nativeHandler.Connection.Extensions.Get<DbConnectionAccessorExtension>();
209-
var accessorInstance = (MyConnectionAccessor)extension.Accessors.First();
209+
var accessorInstance = (MyConnectionAccessor) extension.Accessors.First();
210210
Assert.That(accessorInstance.ConnectionOpeningCounter, Is.Not.EqualTo(0));
211211
Assert.That(accessorInstance.ConnectionOpenedCounter, Is.Not.EqualTo(0));
212212
first = accessorInstance.UniqueInstanceIdentifier;

Orm/Xtensive.Orm/Orm/Configuration/DomainTypeRegistry.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ public static bool IsConnectionAccessor(Type type)
246246
return iDbConnectionAccessorType.IsAssignableFrom(type) && iDbConnectionAccessorType != type;
247247
}
248248

249+
/// <summary>
250+
/// Determines whether the <paramref name="type"/> is
251+
/// a database connection accessor.
252+
/// </summary>
253+
/// <param name="type">The type to check.</param>
254+
/// <returns>Check result.</returns>
255+
public static bool IsDbConnectionAccessor(Type type)
256+
{
257+
if (type.IsAbstract) {
258+
return false;
259+
}
260+
261+
return iDbConnectionAccessorType.IsAssignableFrom(type) && iDbConnectionAccessorType != type;
262+
}
263+
249264
#endregion
250265

251266
#region ICloneable members

Orm/Xtensive.Orm/Orm/Internals/CompiledQueryRunner.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,35 @@ private void AllocateParameterAndReplacer()
160160
var valueMemberInfo = parameterType.GetProperty(nameof(Parameter<object>.Value), closureType);
161161
queryParameter = (Parameter) System.Activator.CreateInstance(parameterType, "pClosure");
162162
queryParameterReplacer = new ExtendedExpressionReplacer(expression => {
163-
if (expression.NodeType != ExpressionType.Constant) {
164-
return null;
165-
}
166-
167-
if (expression.Type.IsClosure()) {
168-
if (expression.Type==closureType) {
169-
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
170-
}
171-
172-
throw new NotSupportedException(string.Format(
173-
Strings.ExExpressionDefinedOutsideOfCachingQueryClosure, expression));
174-
}
175-
176-
if (closureType.DeclaringType==null) {
177-
if (expression.Type==closureType) {
178-
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
163+
if (expression.NodeType == ExpressionType.Constant) {
164+
if ((expression as ConstantExpression).Value == null) {
165+
return null;
179166
}
180-
}
181-
else {
182-
if (expression.Type==closureType) {
183-
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
167+
if (expression.Type.IsClosure()) {
168+
if (expression.Type == closureType) {
169+
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
170+
}
171+
else {
172+
throw new NotSupportedException(string.Format(
173+
Strings.ExExpressionDefinedOutsideOfCachingQueryClosure, expression));
174+
}
184175
}
185176

186-
if (expression.Type==closureType.DeclaringType) {
187-
var memberInfo = closureType.TryGetFieldInfoFromClosure(expression.Type);
188-
if (memberInfo!=null) {
189-
return Expression.MakeMemberAccess(
190-
Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo),
191-
memberInfo);
177+
if (closureType.DeclaringType == null) {
178+
if (expression.Type == closureType)
179+
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
180+
}
181+
else {
182+
if (expression.Type == closureType)
183+
return Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo);
184+
if (expression.Type == closureType.DeclaringType) {
185+
var memberInfo = closureType.TryGetFieldInfoFromClosure(expression.Type);
186+
if (memberInfo != null)
187+
return Expression.MakeMemberAccess(
188+
Expression.MakeMemberAccess(Expression.Constant(queryParameter, parameterType), valueMemberInfo),
189+
memberInfo);
192190
}
193191
}
194-
195192
}
196193
return null;
197194
});

0 commit comments

Comments
 (0)