Skip to content

Commit 18f04c3

Browse files
committed
PostCompilerConfigurations applied
1 parent 8926202 commit 18f04c3

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

Orm/Xtensive.Orm/Orm/Configuration/Internals/NodeConfigurationExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
@@ -18,12 +18,12 @@ public static string GetActualNameFor(this NodeConfiguration nodeConfiguration,
1818
return nodeConfiguration.SchemaMapping.Apply(schema.GetNameInternal());
1919
}
2020

21-
public static IDictionary<string, string> GetDatabaseMapping(this NodeConfiguration nodeConfiguration)
21+
public static IReadOnlyDictionary<string, string> GetDatabaseMapping(this NodeConfiguration nodeConfiguration)
2222
{
2323
return nodeConfiguration.DatabaseMapping.ToDictionary(key => key.Key, value => value.Value);
2424
}
2525

26-
public static IDictionary<string, string> GetSchemaMapping(this NodeConfiguration nodeConfiguration)
26+
public static IReadOnlyDictionary<string, string> GetSchemaMapping(this NodeConfiguration nodeConfiguration)
2727
{
2828
return nodeConfiguration.SchemaMapping.ToDictionary(key => key.Key, value => value.Value);
2929
}

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/CommandFactory.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Collections.Generic;
99
using System.Reflection;
1010
using Xtensive.Core;
11+
using Xtensive.Orm.Configuration;
1112
using Xtensive.Sql;
1213
using Xtensive.Sql.Compiler;
1314
using Tuple = Xtensive.Tuples.Tuple;
@@ -47,12 +48,18 @@ public virtual IEnumerable<CommandPart> CreatePersistParts(SqlPersistTask task,
4748
ArgumentValidator.EnsureArgumentNotNull(task, "task");
4849
ArgumentValidator.EnsureArgumentNotNullOrEmpty(parameterNamePrefix, "parameterNamePrefix");
4950

51+
var nodeConfiguration = Session.StorageNode.Configuration;
52+
var shareStorageNodesOverNodes = Session.Domain.Configuration.ShareStorageSchemaOverNodes;
53+
5054
var result = new List<CommandPart>();
5155
int parameterIndex = 0;
5256
foreach (var request in task.RequestSequence) {
5357
var tuple = task.Tuple;
5458
var compilationResult = request.GetCompiledStatement();
55-
var configuration = new SqlPostCompilerConfiguration();
59+
var configuration = shareStorageNodesOverNodes
60+
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
61+
: new SqlPostCompilerConfiguration();
62+
5663
var part = new CommandPart();
5764

5865
foreach (var binding in request.ParameterBindings) {
@@ -95,7 +102,14 @@ public virtual CommandPart CreateQueryPart(IQueryRequest request, string paramet
95102

96103
int parameterIndex = 0;
97104
var compilationResult = request.GetCompiledStatement();
98-
var configuration = new SqlPostCompilerConfiguration();
105+
var upgradeContext = Upgrade.UpgradeContext.GetCurrent(Session.Domain.UpgradeContextCookie);
106+
var nodeConfiguration = upgradeContext != null ? upgradeContext.NodeConfiguration : Session.StorageNode.Configuration;
107+
108+
var shareStorageNodesOverNodes = Session.Domain.Configuration.ShareStorageSchemaOverNodes;
109+
var configuration = shareStorageNodesOverNodes
110+
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
111+
: new SqlPostCompilerConfiguration();
112+
;
99113
var result = new CommandPart();
100114

101115
foreach (var binding in request.ParameterBindings) {

Orm/Xtensive.Orm/Orm/Providers/SequenceQueryBuilder.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2012 Xtensive LLC.
1+
// Copyright (C) 2012 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Denis Krjuchkov
@@ -29,6 +29,10 @@ public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, NodeConfigura
2929
? SequenceQueryCompartment.SameSession
3030
: compartment;
3131

32+
var postCompilerConfiguration = (nodeConfiguration != null)
33+
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
34+
: new SqlPostCompilerConfiguration();
35+
3236
var sqlNext = hasSequences
3337
? GetSequenceBasedNextImplementation(generatorNode, increment)
3438
: GetTableBasedNextImplementation(generatorNode);
@@ -37,18 +41,18 @@ public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, NodeConfigura
3741
var batch = sqlNext as SqlBatch;
3842
if (batch == null || hasBatches)
3943
// There are batches or there is single statement, so we can run this as a single request
40-
return new SequenceQuery(Compile(sqlNext, nodeConfiguration).GetCommandText(), actualCompartment);
44+
return new SequenceQuery(Compile(sqlNext, nodeConfiguration).GetCommandText(postCompilerConfiguration), actualCompartment);
4145

4246
// No batches, so we must execute this manually
4347
if (!storesAutoIncrementSettingsInMemory)
4448
return new SequenceQuery(
45-
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(),
46-
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(),
49+
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(postCompilerConfiguration),
50+
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(postCompilerConfiguration),
4751
actualCompartment);
4852
return new SequenceQuery(
49-
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(),
50-
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(),
51-
Compile((ISqlCompileUnit)batch[2], nodeConfiguration).GetCommandText(),
53+
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(postCompilerConfiguration),
54+
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(postCompilerConfiguration),
55+
Compile((ISqlCompileUnit)batch[2], nodeConfiguration).GetCommandText(postCompilerConfiguration),
5256
actualCompartment);
5357
}
5458

@@ -74,9 +78,13 @@ public string BuildCleanUpQuery(SchemaNode generatorNode)
7478

7579
public string BuildCleanUpQuery(SchemaNode generatorNode, NodeConfiguration nodeConfiguration)
7680
{
81+
var postCompilerConfiguration = (nodeConfiguration != null)
82+
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
83+
: new SqlPostCompilerConfiguration();
84+
7785
var table = (Table)generatorNode;
7886
var delete = SqlDml.Delete(SqlDml.TableRef(table));
79-
return Compile(delete, nodeConfiguration).GetCommandText();
87+
return Compile(delete, nodeConfiguration).GetCommandText(postCompilerConfiguration);
8088
}
8189

8290

Orm/Xtensive.Orm/Orm/Providers/SqlExecutor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
using System.Threading.Tasks;
1313
using Xtensive.Core;
1414
using Xtensive.IoC;
15+
using Xtensive.Orm.Configuration;
1516
using Xtensive.Orm.Upgrade;
1617
using Xtensive.Sql;
18+
using Xtensive.Sql.Compiler;
1719

1820
namespace Xtensive.Orm.Providers
1921
{
@@ -248,11 +250,11 @@ private string Compile(ISqlCompileUnit statement)
248250
}
249251

250252
var upgradeContext = UpgradeContext.GetCurrent(session.Domain.UpgradeContextCookie);
251-
if (upgradeContext!=null) {
252-
return driver.Compile(statement, upgradeContext.NodeConfiguration).GetCommandText();
253-
}
253+
var nodeConfiguration = upgradeContext != null ? upgradeContext.NodeConfiguration : session.StorageNode.Configuration;
254254

255-
return driver.Compile(statement, session.StorageNode.Configuration).GetCommandText();
255+
return driver.Compile(statement, nodeConfiguration)
256+
.GetCommandText(
257+
new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping()));
256258
}
257259

258260
private CommandWithDataReader ExecuteReader(DbCommand command, CommandBehavior commandBehavior)

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@ public SqlCompilationResult Compile(ISqlCompileUnit statement)
8484
var options = new SqlCompilerConfiguration {
8585
DatabaseQualifiedObjects = configuration.IsMultidatabase,
8686
CommentLocation = configuration.TagsLocation.ToCommentLocation(),
87+
SharedStorageSchema = false,
8788
};
8889
return underlyingDriver.Compile(statement, options);
8990
}
9091

92+
#pragma warning disable IDE0060 // Remove unused parameter
9193
public SqlCompilationResult Compile(ISqlCompileUnit statement, NodeConfiguration nodeConfiguration)
94+
#pragma warning restore IDE0060 // Remove unused parameter
9295
{
93-
var options = configuration.ShareStorageSchemaOverNodes
94-
? new SqlCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
95-
: new SqlCompilerConfiguration();
96-
options.DatabaseQualifiedObjects = configuration.IsMultidatabase;
97-
options.CommentLocation = configuration.TagsLocation.ToCommentLocation();
96+
var options = new SqlCompilerConfiguration {
97+
SharedStorageSchema = configuration.ShareStorageSchemaOverNodes,
98+
DatabaseQualifiedObjects = configuration.IsMultidatabase,
99+
CommentLocation = configuration.TagsLocation.ToCommentLocation()
100+
};
98101
return underlyingDriver.Compile(statement, options);
99102
}
100103

0 commit comments

Comments
 (0)