Skip to content

Commit 727e697

Browse files
committed
No Session.SelectStorageNode() usage + formatting
1 parent 3eed4d9 commit 727e697

File tree

2 files changed

+69
-42
lines changed

2 files changed

+69
-42
lines changed

Orm/Xtensive.Orm.Tests/Storage/Multinode/DynamicTypeIdTest.cs

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public async Task MainAsyncTest()
147147
BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity2)).Dispose();
148148
BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1)).Dispose();
149149

150-
using (var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2))) {
150+
var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2));
151+
152+
await using (domain) {
151153
var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate };
152154
nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema);
153155
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
@@ -218,15 +220,17 @@ public async Task SelectAbstractClassDescendantsAsyncTest()
218220
InitializeSchemas();
219221

220222
BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(Entity3)).Dispose();
221-
using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity3), typeof(Entity4)))
223+
var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity3), typeof(Entity4));
224+
225+
using (domain)
222226
using (var session = domain.OpenSession())
223227
using (var transaction = session.OpenTransaction()) {
224-
for (int i = 0; i < 10; i++) {
225-
new Entity3 {
228+
for (var i = 0; i < 10; i++) {
229+
_ = new Entity3 {
226230
Name = "1 before test " + i,
227231
StringValue = "1 before test " + i
228232
};
229-
new Entity4 {
233+
_ = new Entity4 {
230234
Name = "1 before test " + i,
231235
IntValue = i
232236
};
@@ -235,23 +239,27 @@ public async Task SelectAbstractClassDescendantsAsyncTest()
235239
}
236240

237241
BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity4)).Dispose();
238-
using (var domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity4), typeof(Entity3)))
242+
domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity4), typeof(Entity3));
243+
244+
using (domain)
239245
using (var session = domain.OpenSession())
240246
using (var transaction = session.OpenTransaction()) {
241-
for (int i = 0; i < 10; i++) {
242-
new Entity3 {
247+
for (var i = 0; i < 10; i++) {
248+
_ = new Entity3 {
243249
Name = "2 before test " + i,
244250
StringValue = "1 before test " + i
245251
};
246-
new Entity4 {
252+
_ = new Entity4 {
247253
Name = "2 before test " + i,
248254
IntValue = i
249255
};
250256
}
251257
transaction.Complete();
252258
}
253259

254-
using (var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity3), typeof(Entity4))) {
260+
domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity3), typeof(Entity4));
261+
262+
await using (domain) {
255263
var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate };
256264
nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema);
257265
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
@@ -327,16 +335,18 @@ public async Task SelectInterfaceImplementationsAsyncTest()
327335
InitializeSchemas();
328336

329337
BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(SomeInterfaceImpl1)).Dispose();
330-
using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2)))
338+
var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2));
339+
340+
using (domain)
331341
using (var session = domain.OpenSession())
332342
using (var transaction = session.OpenTransaction()) {
333-
for (int i = 0; i < 10; i++) {
334-
new SomeInterfaceImpl1 {
343+
for (var i = 0; i < 10; i++) {
344+
_ = new SomeInterfaceImpl1 {
335345
Name = "1 before test " + i,
336346
StringValue = "1 before test " + i,
337347
GuidValue = Guid.NewGuid()
338348
};
339-
new SomeInterfaceImpl2 {
349+
_ = new SomeInterfaceImpl2 {
340350
Name = "1 before test " + i,
341351
IntValue = i,
342352
GuidValue = Guid.NewGuid()
@@ -346,16 +356,18 @@ public async Task SelectInterfaceImplementationsAsyncTest()
346356
}
347357

348358
BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(SomeInterfaceImpl2)).Dispose();
349-
using (var domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2)))
359+
domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2));
360+
361+
using (domain)
350362
using (var session = domain.OpenSession())
351363
using (var transaction = session.OpenTransaction()) {
352-
for (int i = 0; i < 10; i++) {
353-
new SomeInterfaceImpl1 {
364+
for (var i = 0; i < 10; i++) {
365+
_ = new SomeInterfaceImpl1 {
354366
Name = "2 before test " + i,
355367
StringValue = "1 before test " + i,
356368
GuidValue = Guid.NewGuid()
357369
};
358-
new SomeInterfaceImpl2 {
370+
_ = new SomeInterfaceImpl2 {
359371
Name = "2 before test " + i,
360372
IntValue = i,
361373
GuidValue = Guid.NewGuid()
@@ -364,7 +376,9 @@ public async Task SelectInterfaceImplementationsAsyncTest()
364376
transaction.Complete();
365377
}
366378

367-
using (var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2))) {
379+
domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(SomeInterfaceImpl1), typeof(SomeInterfaceImpl2));
380+
381+
await using (domain) {
368382
var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate };
369383
nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema);
370384
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
@@ -435,15 +449,17 @@ public async Task SelectNonAbstractDescendantAsyncTest()
435449
InitializeSchemas();
436450

437451
BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(Entity1)).Dispose();
438-
using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2)))
452+
var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2));
453+
454+
using (domain)
439455
using (var session = domain.OpenSession())
440456
using (var transaction = session.OpenTransaction()) {
441-
for (int i = 0; i < 10; i++) {
442-
new Entity1 {
457+
for (var i = 0; i < 10; i++) {
458+
_ = new Entity1 {
443459
Name = "1 before test " + i,
444460
StringValue = "1 before test " + i
445461
};
446-
new Entity2 {
462+
_ = new Entity2 {
447463
Name = "1 before test " + i,
448464
IntValue = i
449465
};
@@ -452,23 +468,27 @@ public async Task SelectNonAbstractDescendantAsyncTest()
452468
}
453469

454470
BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity2)).Dispose();
455-
using (var domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1)))
471+
domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1));
472+
473+
using (domain)
456474
using (var session = domain.OpenSession())
457475
using (var transaction = session.OpenTransaction()) {
458-
for (int i = 0; i < 10; i++) {
459-
new Entity1 {
476+
for (var i = 0; i < 10; i++) {
477+
_ = new Entity1 {
460478
Name = "2 before test " + i,
461479
StringValue = "1 before test " + i
462480
};
463-
new Entity2 {
481+
_ = new Entity2 {
464482
Name = "2 before test " + i,
465483
IntValue = i
466484
};
467485
}
468486
transaction.Complete();
469487
}
470488

471-
using (var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2))) {
489+
domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2));
490+
491+
await using (domain) {
472492
var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate };
473493
nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema);
474494
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
@@ -518,7 +538,6 @@ public void TypeIdExtractionTest()
518538
_ = domain.StorageNodeManager.AddNode(nodeConfiguration);
519539
var selectedNode = domain.StorageNodeManager.GetNode(nodeConfiguration.NodeId);
520540
using (var session = selectedNode.OpenSession()) {
521-
session.SelectStorageNode(AlternativeSchema);
522541
var types = new[] { typeof(BaseEntity), typeof(Entity1), typeof(Entity2) };
523542
foreach (var type in types) {
524543
Assert.That(session.StorageNode.TypeIdRegistry[domain.Model.Types[type]], Is.EqualTo(alternativeSchemaMap[type]));
@@ -538,30 +557,36 @@ public async Task TypeIdExtractionAsyncTest()
538557
var alternativeSchemaMap = new Dictionary<Type, int>();
539558

540559
BuildDomain(DefaultSchema, DomainUpgradeMode.Recreate, typeof(Entity1)).Dispose();
541-
using (var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2))) {
560+
var domain = BuildDomain(DefaultSchema, DomainUpgradeMode.PerformSafely, typeof(Entity1), typeof(Entity2));
561+
562+
using (domain) {
542563
defaultSchemaMap = domain.Model.Types.ToDictionary(el => el.UnderlyingType, el => el.TypeId);
543564
}
544565

545566
BuildDomain(AlternativeSchema, DomainUpgradeMode.Recreate, typeof(Entity2)).Dispose();
546-
using (var domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1))) {
567+
domain = BuildDomain(AlternativeSchema, DomainUpgradeMode.PerformSafely, typeof(Entity2), typeof(Entity1));
568+
569+
using (domain) {
547570
alternativeSchemaMap = domain.Model.Types.ToDictionary(el => el.UnderlyingType, el => el.TypeId);
548571
}
549572

550-
using (var domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2))) {
573+
domain = await BuildDomainAsync(DefaultSchema, DomainUpgradeMode.Validate, typeof(Entity1), typeof(Entity2));
574+
575+
await using (domain) {
551576
var nodeConfiguration = new NodeConfiguration(AlternativeSchema) { UpgradeMode = DomainUpgradeMode.Validate };
552577
nodeConfiguration.SchemaMapping.Add(DefaultSchema, AlternativeSchema);
553-
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
578+
554579

555580
using (var session = domain.OpenSession()) {
556-
session.SelectStorageNode(WellKnown.DefaultNodeId);
557581
var types = new[] { typeof(BaseEntity), typeof(Entity1), typeof(Entity2) };
558582
foreach (var type in types) {
559583
Assert.That(session.StorageNode.TypeIdRegistry[domain.Model.Types[type]], Is.EqualTo(defaultSchemaMap[type]));
560584
}
561585
}
562586

563-
using (var session = domain.OpenSession()) {
564-
session.SelectStorageNode(AlternativeSchema);
587+
_ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
588+
var selectedNode = domain.StorageNodeManager.GetNode(nodeConfiguration.NodeId);
589+
using (var session = selectedNode.OpenSession()) {
565590
var types = new[] { typeof(BaseEntity), typeof(Entity1), typeof(Entity2) };
566591
foreach (var type in types) {
567592
Assert.That(session.StorageNode.TypeIdRegistry[domain.Model.Types[type]], Is.EqualTo(alternativeSchemaMap[type]));

Orm/Xtensive.Orm/Orm/Session.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,20 @@ internal void EnsureNotDisposed()
238238
internal void AttachToScope(SessionScope sessionScope)
239239
{
240240
sessionScope.Session = this;
241-
disposableSet.Add(sessionScope);
241+
_ = disposableSet.Add(sessionScope);
242242
}
243243

244244
internal EnumerationContext CreateEnumerationContext(ParameterContext parameterContext)
245245
{
246246
Persist(PersistReason.Query);
247-
ProcessUserDefinedDelayedQueries(true);
247+
_ = ProcessUserDefinedDelayedQueries(true);
248248
return new Providers.EnumerationContext(this, parameterContext, GetEnumerationContextOptions());
249249
}
250250

251251
internal async Task<EnumerationContext> CreateEnumerationContextAsync(ParameterContext parameterContext, CancellationToken token)
252252
{
253253
await PersistAsync(PersistReason.Other, token).ConfigureAwait(false);
254-
await ProcessUserDefinedDelayedQueriesAsync(token).ConfigureAwait(false);
254+
_ = await ProcessUserDefinedDelayedQueriesAsync(token).ConfigureAwait(false);
255255
return new Providers.EnumerationContext(this, parameterContext, GetEnumerationContextOptions());
256256
}
257257

@@ -430,9 +430,11 @@ VersionSet IVersionSetProvider.CreateVersionSet(IEnumerable<Key> keys)
430430
using (var tx = OpenAutoTransaction()) {
431431
var entities = Query.Many<Entity>(keys);
432432
var result = new VersionSet();
433-
foreach (var entity in entities)
434-
if (entity!=null)
435-
result.Add(entity, false);
433+
foreach (var entity in entities) {
434+
if (entity != null) {
435+
_ = result.Add(entity, false);
436+
}
437+
}
436438
tx.Complete();
437439
return result;
438440
}

0 commit comments

Comments
 (0)