Skip to content

Commit a687b08

Browse files
committed
5.0.18->5.0.19-Beta changes port
1 parent 010c208 commit a687b08

29 files changed

+1392
-227
lines changed

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/Connection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ internal class Connection : SqlConnection
1818
{
1919
private const string DefaultCheckConnectionQuery = "SELECT TOP(0) 0;";
2020

21+
private readonly bool checkConnectionIsAlive;
22+
2123
private SqlServerConnection underlyingConnection;
2224
private SqlTransaction activeTransaction;
23-
private bool checkConnectionIsAlive;
2425

2526
/// <inheritdoc/>
2627
public override DbConnection UnderlyingConnection { get { return underlyingConnection; } }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected override SqlDriver CreateDriver(string connectionString, SqlDriverConf
105105
isAzure = IsAzure(connection);
106106
}
107107
else if (forcedServerVersion.Equals("azure", StringComparison.OrdinalIgnoreCase)) {
108-
versionString = "10.0.0.0";
108+
versionString = "12.0.0.0";
109109
isAzure = true;
110110
}
111111
else {

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/InternalHelpers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ internal static class InternalHelpers
2020
public static bool ShouldRetryOn(Exception ex)
2121
{
2222
ArgumentValidator.EnsureArgumentNotNull(ex, "ex");
23-
SqlException sqlException = ex as SqlException;
24-
if (sqlException != null) {
23+
if (ex is SqlException sqlException) {
2524
foreach (SqlError err in sqlException.Errors) {
2625
switch (err.Number) {
2726
// SQL Error Code: 49920

Orm/Xtensive.Orm.Tests.Core/Helpers/StringExtensionsTest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void IndentTest()
5252
[Test]
5353
public void LikeExtensionTest()
5454
{
55-
Assert.Throws<ArgumentException>(() => {
55+
_ = Assert.Throws<ArgumentException>(() => {
5656
Assert.AreEqual("uewryewsf".Like("%sf"), true);
5757
Assert.AreEqual("s__asdf".Like("_%asdf"), true);
5858
Assert.AreEqual("dsfEEEE".Like("dsf%"), true);
@@ -68,5 +68,16 @@ public void LikeExtensionTest()
6868
Assert.AreEqual("aRRRRa%".Like("a%a%%", '%'), true);
6969
});
7070
}
71+
72+
[Test]
73+
public void TrimRoundBracketsSymetricallyTest()
74+
{
75+
Assert.That("(abc)".StripRoundBrackets(), Is.EqualTo("abc"));
76+
Assert.That("abc".StripRoundBrackets(), Is.EqualTo("abc"));
77+
Assert.That("((((Convert(abc)))))".StripRoundBrackets(), Is.EqualTo("Convert(abc)"));
78+
Assert.That("(Convert(abc))".StripRoundBrackets(), Is.EqualTo("Convert(abc)"));
79+
Assert.That("((((abc))".StripRoundBrackets(), Is.EqualTo("((abc"));
80+
Assert.That("((abc))))".StripRoundBrackets(), Is.EqualTo("abc))"));
81+
}
7182
}
7283
}
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
// Copyright (C) 2018 Xtensive LLC.
2+
// All rights reserved.
3+
// For conditions of distribution and use, see license.
4+
// Created by: Alexey Kulakov
5+
// Created: 2018.10.01
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Diagnostics;
10+
using System.Linq;
11+
using System.Reflection;
12+
using NUnit.Framework;
13+
using Xtensive.Collections;
14+
using Xtensive.Core;
15+
using Xtensive.IoC;
16+
using Xtensive.Orm.Building;
17+
using Xtensive.Orm.Building.Builders;
18+
using Xtensive.Orm.Building.Definitions;
19+
using Xtensive.Orm.Configuration;
20+
using Xtensive.Orm.Providers;
21+
using Xtensive.Orm.Upgrade;
22+
using Xtensive.Reflection;
23+
using Xtensive.Sql;
24+
25+
namespace Xtensive.Orm.Tests.Model
26+
{
27+
[TestFixture]
28+
public abstract class ModelBuildingTest
29+
{
30+
private const string ErrorInTestFixtureSetup = "Error in TestFixtureSetUp:\r\n{0}";
31+
32+
protected bool shouldBuildRealDomain = false;
33+
34+
[OneTimeSetUp]
35+
public void TestFixureSetUp()
36+
{
37+
try {
38+
CheckRequirements();
39+
PopulateData();
40+
}
41+
catch (IgnoreException) {
42+
throw;
43+
}
44+
catch (Exception e) {
45+
Debug.WriteLine(ErrorInTestFixtureSetup, e);
46+
throw;
47+
}
48+
}
49+
50+
protected virtual void CheckRequirements()
51+
{
52+
}
53+
54+
protected virtual void PopulateData()
55+
{
56+
}
57+
58+
protected void TestInvoker(DomainConfiguration domainConfiguration, Action<Domain> domainValidationAction)
59+
=> TestInvoker(domainConfiguration, domainValidationAction, null);
60+
61+
protected void TestInvoker(DomainConfiguration domainConfiguration, Action<DomainModelDef> domainDefValidationAction)
62+
=> TestInvoker(domainConfiguration, null, domainDefValidationAction);
63+
64+
protected void TestInvoker(DomainConfiguration domainConfiguration, Action<Domain> domainValidationAction, Action<DomainModelDef> domainDefsValidationAction)
65+
{
66+
domainConfiguration.Types.Register(typeof(ModelDefCapturer));
67+
68+
var upgradeContext = new UpgradeContext(domainConfiguration);
69+
70+
if (shouldBuildRealDomain) {
71+
using (var domain = Domain.Build(domainConfiguration)) {
72+
var modelDef = domain.Extensions.Get<DomainModelDef>();
73+
if (domainDefsValidationAction != null && modelDef != null) {
74+
domainDefsValidationAction.Invoke(modelDef);
75+
}
76+
77+
if (domainValidationAction != null) {
78+
domainValidationAction.Invoke(domain);
79+
}
80+
}
81+
}
82+
else {
83+
using (upgradeContext.Activate())
84+
using (upgradeContext.Services) {
85+
BuildServices(upgradeContext);
86+
var domain = CreateDomainBuilder(upgradeContext).Invoke();
87+
var modelDef = domain.Extensions.Get<DomainModelDef>();
88+
if (domainDefsValidationAction != null && modelDef != null)
89+
domainDefsValidationAction.Invoke(modelDef);
90+
if (domainValidationAction != null)
91+
domainValidationAction.Invoke(domain);
92+
}
93+
}
94+
}
95+
96+
private Func<Domain> CreateDomainBuilder(UpgradeContext context)
97+
{
98+
var buildingConfiguration = BuildBuilderConfiguration(context);
99+
100+
Func<DomainBuilderConfiguration, Domain> builder = DomainBuilder.Run;
101+
return builder.Bind(buildingConfiguration);
102+
}
103+
104+
private DomainBuilderConfiguration BuildBuilderConfiguration(UpgradeContext context)
105+
{
106+
var configuration = new DomainBuilderConfiguration {
107+
DomainConfiguration = context.Configuration,
108+
Stage = context.Stage,
109+
Services = context.Services,
110+
ModelFilter = new StageModelFilter(context.UpgradeHandlers, UpgradeStage.Final),
111+
UpgradeContextCookie = context.Cookie,
112+
RecycledDefinitions = context.RecycledDefinitions,
113+
DefaultSchemaInfo = null
114+
};
115+
116+
return configuration;
117+
}
118+
119+
private void BuildServices(UpgradeContext context)
120+
{
121+
var services = context.Services;
122+
var configuration = context.Configuration;
123+
124+
services.Configuration = configuration;
125+
services.IndexFilterCompiler = new PartialIndexFilterCompiler();
126+
127+
var descriptor = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider);
128+
var driverFactory = (SqlDriverFactory) Activator.CreateInstance(descriptor.DriverFactory);
129+
var handlerFactory = (HandlerFactory) Activator.CreateInstance(descriptor.HandlerFactory);
130+
var driver = StorageDriver.Create(driverFactory, configuration);
131+
services.HandlerFactory = handlerFactory;
132+
services.StorageDriver = driver;
133+
services.NameBuilder = new NameBuilder(configuration, driver.ProviderInfo);
134+
BuildExternalServices(services, context);
135+
136+
services.Lock();
137+
138+
context.TypeIdProvider = new TypeIdProvider(context);
139+
}
140+
141+
private void BuildExternalServices(UpgradeServiceAccessor serviceAccessor, UpgradeContext context)
142+
{
143+
var configuration = context.Configuration;
144+
var standardRegistrations = new[] {
145+
new ServiceRegistration(typeof(DomainConfiguration), context.Configuration),
146+
new ServiceRegistration(typeof(UpgradeContext), context)
147+
};
148+
149+
var modules = configuration.Types.Modules
150+
.Select(type => new ServiceRegistration(typeof(IModule), type, false));
151+
var handlers = configuration.Types.UpgradeHandlers
152+
.Select(type => new ServiceRegistration(typeof(IUpgradeHandler), type, false));
153+
154+
var registrations = standardRegistrations.Concat(modules).Concat(handlers);
155+
var serviceContainer = new ServiceContainer(registrations);
156+
serviceAccessor.RegisterResource(serviceContainer);
157+
158+
BuildModules(serviceAccessor, serviceContainer);
159+
BuildUpgradeHandlers(serviceAccessor, serviceContainer);
160+
}
161+
162+
private static void BuildModules(UpgradeServiceAccessor serviceAccessor, IServiceContainer serviceContainer)
163+
=> serviceAccessor.Modules = new ReadOnlyList<IModule>(serviceContainer.GetAll<IModule>().ToList());
164+
165+
private static void BuildUpgradeHandlers(UpgradeServiceAccessor serviceAccessor, IServiceContainer serviceContainer)
166+
{
167+
// Getting user handlers
168+
var userHandlers =
169+
from handler in serviceContainer.GetAll<IUpgradeHandler>()
170+
let assembly = handler.Assembly ?? handler.GetType().Assembly
171+
where handler.IsEnabled
172+
group handler by assembly;
173+
174+
// Adding user handlers
175+
var handlers = new Dictionary<Assembly, IUpgradeHandler>();
176+
foreach (var group in userHandlers) {
177+
var candidates = group.ToList();
178+
if (candidates.Count > 1) {
179+
throw new DomainBuilderException(
180+
string.Format(Strings.ExMoreThanOneEnabledXIsProvidedForAssemblyY, typeof(IUpgradeHandler).GetShortName(), @group.Key));
181+
}
182+
handlers.Add(group.Key, candidates[0]);
183+
}
184+
185+
// Adding default handlers
186+
var assembliesWithUserHandlers = handlers.Select(pair => pair.Key);
187+
var assembliesWithoutUserHandler =
188+
serviceAccessor.Configuration.Types.PersistentTypes
189+
.Select(type => type.Assembly)
190+
.Distinct()
191+
.Except(assembliesWithUserHandlers);
192+
193+
foreach (var assembly in assembliesWithoutUserHandler) {
194+
var handler = new UpgradeHandler(assembly);
195+
handlers.Add(assembly, handler);
196+
}
197+
198+
// Building a list of handlers sorted by dependencies of their assemblies
199+
var dependencies = handlers.Keys.ToDictionary(
200+
assembly => assembly,
201+
assembly => new HashSet<string>(assembly.GetReferencedAssemblies().Select(assemblyName => assemblyName.ToString())));
202+
var sortedHandlers = handlers
203+
.SortTopologically((a0, a1) => dependencies[a1.Key].Contains(a0.Key.GetName().ToString()))
204+
.Select(pair => pair.Value);
205+
206+
// Storing the result
207+
serviceAccessor.UpgradeHandlers =
208+
new ReadOnlyDictionary<Assembly, IUpgradeHandler>(handlers);
209+
serviceAccessor.OrderedUpgradeHandlers =
210+
new ReadOnlyList<IUpgradeHandler>(sortedHandlers.ToList());
211+
}
212+
213+
public sealed class ModelDefCapturer : IModule
214+
{
215+
public void OnBuilt(Domain domain)
216+
{
217+
}
218+
219+
public void OnDefinitionsBuilt(BuildingContext context, DomainModelDef model)
220+
{
221+
var domain = context.Domain;
222+
domain.Extensions.Set(model);
223+
}
224+
}
225+
}
226+
}

Orm/Xtensive.Orm.Tests/App.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
44
<section name="Xtensive.Orm" type="Xtensive.Orm.Configuration.Elements.ConfigurationSection, Xtensive.Orm"/>
@@ -172,10 +172,12 @@
172172
<rule namespace="Xtensive.Orm.Tests.Model.VariousKeyGeneratorsByOneKeyEqualityIdentifierTestModel2" database="other"/>
173173
</mappingRules>
174174
</domain>
175-
176175
<domain name="SharedStorageSchemaNone" connectionUrl="sqlserver://localhost/" />
177176
<domain name="SharedStorageSchemaOn" connectionUrl="sqlserver://localhost/" shareStorageSchemaOverNodes="true"/>
178177
<domain name="SharedStorageSchemaOff" connectionUrl="sqlserver://localhost/" shareStorageSchemaOverNodes="false"/>
178+
<domain name="EnableConnectionIsAliveNone" connectionUrl="sqlserver://localhost/" />
179+
<domain name="EnableConnectionIsAliveTrue" connectionUrl="sqlserver://localhost/" ensureConnectionIsAlive="true"/>
180+
<domain name="EnableConnectionIsAliveFalse" connectionUrl="sqlserver://localhost/" ensureConnectionIsAlive="false"/>
179181
<domain name="ChangeTrackingTest1"
180182
connectionUrl="sqlserver://localhost/"
181183
fullTextChangeTrackingMode="Off"></domain>

Orm/Xtensive.Orm.Tests/Configuration/AppConfigTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ private static void ValidateNamingCovention(NamingConvention expected, NamingCon
285285
Assert.That(actual.NamingRules, Is.EqualTo(expected.NamingRules));
286286
}
287287

288-
289288
[Test]
290289
public void ShareStorageSchemaOverNodesTest()
291290
{

0 commit comments

Comments
 (0)