Skip to content

Commit 5f3d426

Browse files
committed
No Obsolete constructors or methods usage
+ StorageDriver.Compile(ISqlCompileUnit, NodeConfiguration) marked obsolete
1 parent 56a7c4c commit 5f3d426

File tree

8 files changed

+49
-76
lines changed

8 files changed

+49
-76
lines changed

Orm/Xtensive.Orm/Orm/Providers/Requests/PersistRequest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public void Prepare()
4141
{
4242
if (compiledStatement!=null)
4343
return;
44-
compiledStatement =(NodeConfiguration!=null)
45-
? driver.Compile(CompileUnit, NodeConfiguration)
46-
: driver.Compile(CompileUnit);
44+
compiledStatement = driver.Compile(CompileUnit);
4745
CompileUnit = null;
4846
Statement = null;
4947
}

Orm/Xtensive.Orm/Orm/Providers/Requests/QueryRequest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public void Prepare()
4242
{
4343
if (compiledStatement!=null && accessor!=null)
4444
return;
45-
compiledStatement = (NodeConfiguration!=null)
46-
? driver.Compile(Statement, NodeConfiguration)
47-
: driver.Compile(Statement);
45+
compiledStatement = driver.Compile(Statement);
4846
accessor = driver.GetDataReaderAccessor(TupleDescriptor);
4947
Statement = null;
5048
}

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

Lines changed: 39 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -29,76 +29,51 @@ 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();
32+
var postCompilerConfiguration = GetPostCompilerConfig(nodeConfiguration);
3533

3634
var sqlNext = hasSequences
3735
? GetSequenceBasedNextImplementation(generatorNode, increment)
3836
: GetTableBasedNextImplementation(generatorNode);
3937

40-
var requiresSeparateSession = !hasSequences;
41-
var batch = sqlNext as SqlBatch;
42-
if (batch == null || hasBatches)
38+
if (sqlNext is not SqlBatch batch || hasBatches) {
4339
// There are batches or there is single statement, so we can run this as a single request
44-
return new SequenceQuery(Compile(sqlNext, nodeConfiguration).GetCommandText(postCompilerConfiguration), actualCompartment);
45-
46-
// No batches, so we must execute this manually
47-
if (!storesAutoIncrementSettingsInMemory)
48-
return new SequenceQuery(
49-
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(postCompilerConfiguration),
50-
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(postCompilerConfiguration),
51-
actualCompartment);
52-
return new SequenceQuery(
53-
Compile((ISqlCompileUnit)batch[0], nodeConfiguration).GetCommandText(postCompilerConfiguration),
54-
Compile((ISqlCompileUnit)batch[1], nodeConfiguration).GetCommandText(postCompilerConfiguration),
55-
Compile((ISqlCompileUnit)batch[2], nodeConfiguration).GetCommandText(postCompilerConfiguration),
56-
actualCompartment);
57-
}
58-
59-
public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, NodeConfiguration nodeConfiguration, long increment)
60-
{
61-
return BuildNextValueQuery(generatorNode, nodeConfiguration, increment, false);
40+
return new SequenceQuery(driver.Compile(sqlNext).GetCommandText(postCompilerConfiguration), actualCompartment);
41+
}
42+
else {
43+
// No batches, so we must execute this manually
44+
return !storesAutoIncrementSettingsInMemory
45+
? new SequenceQuery(
46+
driver.Compile((ISqlCompileUnit) batch[0]).GetCommandText(postCompilerConfiguration),
47+
driver.Compile((ISqlCompileUnit) batch[1]).GetCommandText(postCompilerConfiguration),
48+
actualCompartment)
49+
: new SequenceQuery(
50+
driver.Compile((ISqlCompileUnit) batch[0]).GetCommandText(postCompilerConfiguration),
51+
driver.Compile((ISqlCompileUnit) batch[1]).GetCommandText(postCompilerConfiguration),
52+
driver.Compile((ISqlCompileUnit) batch[2]).GetCommandText(postCompilerConfiguration),
53+
actualCompartment);
54+
}
6255
}
6356

64-
public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, long increment, bool forcedSameSessionExecution)
65-
{
66-
return BuildNextValueQuery(generatorNode, null, increment, forcedSameSessionExecution);
67-
}
57+
public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, long increment, bool forcedSameSessionExecution) =>
58+
BuildNextValueQuery(generatorNode, null, increment, forcedSameSessionExecution);
6859

69-
public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, long increment)
70-
{
71-
return BuildNextValueQuery(generatorNode, null, increment);
72-
}
60+
public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, long increment) =>
61+
BuildNextValueQuery(generatorNode, null, increment, false);
7362

74-
public string BuildCleanUpQuery(SchemaNode generatorNode)
75-
{
76-
return BuildCleanUpQuery(generatorNode, null);
77-
}
63+
public string BuildCleanUpQuery(SchemaNode generatorNode) =>
64+
BuildCleanUpQuery(generatorNode, null);
7865

7966
public string BuildCleanUpQuery(SchemaNode generatorNode, NodeConfiguration nodeConfiguration)
8067
{
81-
var postCompilerConfiguration = (nodeConfiguration != null)
82-
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
83-
: new SqlPostCompilerConfiguration();
68+
var postCompilerConfiguration = GetPostCompilerConfig(nodeConfiguration);
8469

85-
var table = (Table)generatorNode;
70+
var table = (Table) generatorNode;
8671
var delete = SqlDml.Delete(SqlDml.TableRef(table));
87-
return Compile(delete, nodeConfiguration).GetCommandText(postCompilerConfiguration);
88-
}
89-
90-
91-
private SqlCompilationResult Compile(ISqlCompileUnit unit, NodeConfiguration nodeConfiguration)
92-
{
93-
if (nodeConfiguration!=null)
94-
return driver.Compile(unit, nodeConfiguration);
95-
return driver.Compile(unit);
72+
return driver.Compile(delete).GetCommandText(postCompilerConfiguration);
9673
}
9774

98-
private ISqlCompileUnit GetSequenceBasedNextImplementation(SchemaNode generatorNode, long increment)
99-
{
100-
return SqlDml.Select(SqlDml.NextValue((Sequence) generatorNode, (int) increment));
101-
}
75+
private ISqlCompileUnit GetSequenceBasedNextImplementation(SchemaNode generatorNode, long increment) =>
76+
SqlDml.Select(SqlDml.NextValue((Sequence) generatorNode, (int) increment));
10277

10378
private ISqlCompileUnit GetTableBasedNextImplementation(SchemaNode generatorNode)
10479
{
@@ -116,20 +91,26 @@ private ISqlCompileUnit GetTableBasedNextImplementation(SchemaNode generatorNode
11691
}
11792

11893
var result = SqlDml.Batch();
119-
if (storesAutoIncrementSettingsInMemory)
94+
if (storesAutoIncrementSettingsInMemory) {
12095
result.Add(delete);
96+
}
12197
result.Add(insert);
12298
result.Add(SqlDml.Select(SqlDml.LastAutoGeneratedId()));
12399
return result;
124100
}
125101

102+
private static SqlPostCompilerConfiguration GetPostCompilerConfig(NodeConfiguration nodeConfiguration) =>
103+
(nodeConfiguration != null)
104+
? new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping())
105+
: new SqlPostCompilerConfiguration();
106+
126107
private static TableColumn GetColumn(Table table, string columnName)
127108
{
128109
var idColumn = table.TableColumns[columnName];
129-
if (idColumn==null)
130-
throw new InvalidOperationException(string.Format(
131-
Strings.ExColumnXIsNotFoundInTableY, columnName, table.Name));
132-
return idColumn;
110+
return idColumn == null
111+
? throw new InvalidOperationException(string.Format(
112+
Strings.ExColumnXIsNotFoundInTableY, columnName, table.Name))
113+
: idColumn;
133114
}
134115

135116
public SequenceQueryBuilder(StorageDriver driver)

Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Index.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private SqlSelect BuildTableQuery(IndexInfo index)
6161
var atRootPolicy = false;
6262

6363
if (table==null) {
64-
table = Mapping[index.ReflectedType.GetRoot()];
64+
table = Mapping[index.ReflectedType.Root];
6565
atRootPolicy = true;
6666
}
6767

@@ -76,7 +76,7 @@ private SqlSelect BuildTableQuery(IndexInfo index)
7676
}
7777
}
7878
else {
79-
var root = index.ReflectedType.GetRoot().AffectedIndexes.First(i => i.IsPrimary);
79+
var root = index.ReflectedType.Root.AffectedIndexes.First(i => i.IsPrimary);
8080
var lookup = root.Columns.ToDictionary(c => c.Field, c => c.Name);
8181
foreach (var c in indexColumns) {
8282
queryColumns.Add(tableRef[lookup[c.Field]]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private string Compile(ISqlCompileUnit statement)
252252
var upgradeContext = UpgradeContext.GetCurrent(session.Domain.UpgradeContextCookie);
253253
var nodeConfiguration = upgradeContext != null ? upgradeContext.NodeConfiguration : session.StorageNode.Configuration;
254254

255-
return driver.Compile(statement, nodeConfiguration)
255+
return driver.Compile(statement)
256256
.GetCommandText(
257257
new SqlPostCompilerConfiguration(nodeConfiguration.GetDatabaseMapping(), nodeConfiguration.GetSchemaMapping()));
258258
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ public SqlCompilationResult Compile(ISqlCompileUnit statement)
8888
return underlyingDriver.Compile(statement, options);
8989
}
9090

91-
#pragma warning disable IDE0060 // Remove unused parameter
91+
[Obsolete]
9292
public SqlCompilationResult Compile(ISqlCompileUnit statement, NodeConfiguration nodeConfiguration)
93-
#pragma warning restore IDE0060 // Remove unused parameter
9493
{
9594
var options = new SqlCompilerConfiguration {
9695
DatabaseQualifiedObjects = configuration.IsMultidatabase,

Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryBuilder.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2012-2020 Xtensive LLC.
1+
// Copyright (C) 2012-2022 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
@@ -60,10 +60,7 @@ public QueryTranslationResult TranslateQuery<TResult>(IQueryable<TResult> query)
6060
public SqlCompilationResult CompileQuery(ISqlCompileUnit query)
6161
{
6262
ArgumentValidator.EnsureArgumentNotNull(query, "query");
63-
var upgradeContext = UpgradeContext.GetCurrent(Session.Domain.UpgradeContextCookie);
64-
if (upgradeContext!=null)
65-
return driver.Compile(query, upgradeContext.NodeConfiguration);
66-
return driver.Compile(query, Session.StorageNode.Configuration);
63+
return driver.Compile(query);
6764
}
6865

6966
/// <summary>

Orm/Xtensive.Orm/Sql/Compiler/SqlCompilerConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public SqlCompilerConfiguration Clone()
6161

6262
public SqlCompilerConfiguration()
6363
{
64-
#pragma warning disable CS0612 // Type or member is obsolete
64+
#pragma warning disable CS0618 // Type or member is obsolete
6565
SchemaMapping = null;
6666
DatabaseMapping = null;
67-
#pragma warning restore CS0612 // Type or member is obsolete
67+
#pragma warning restore CS0618 // Type or member is obsolete
6868
}
6969

7070
[Obsolete]

0 commit comments

Comments
 (0)