Skip to content

Commit bd1a93f

Browse files
authored
Proposed improvements before merging into original DO repo (#124)
* Move SqlInsertValuesCollection to Dml.Collections folder * Add rows collection to SqlInsert + mark Values as obsolete * Test for SqlInsert * Correct switch from strict number of conditions to default number of conditions - Return back WellKnown.MaxNumberOfConditions as [Obsolete]; - Add WellKnown.DefaultMaxNumberOfConditions as replacement; - Initialize MultiRowInsertLevel2BatchSize with DefalultMaxNumberOfConditions; * Proper implementation of DomainConfiguration.MaxNumberOfConditions - check if configuration instance is locked and deny changing if it is; - initialized with well-known constant instead of literal value; - added configuration element to have support for this parameter in *.config files * fix * Add test for loading of DomainConfiguration with new property from config files Offtop: tagLocation and other forgotten-to-add properties are tested * Fix wrong translation of values section * DomainConfiguration cloning clones MaxNumberOfConditions * Return original types of properties in IPersistDescriptor Keeps backwards compatibility * Multi-row insert not only for 1-column tuples - adds PersistParameterBinding.RowIndex + ctors to init the value, by default row index is 0. This property will keep track of what row of SqlPersistTask.Tuples is the source of value - CommandFactory uses dedicated algorithms for Tuple and for collection of Tuples. First one keeps original algorithm before any changes, and the second one uses RowIndex to get required row and FieldIndex to find value within row - return original private SqlSessionHandler.Store() method, it works without checking for count of values in tuples. * No use of SqlInsert.Values, SqlInsert.ValueRows - new InsertSection.NewRow removed, no need in it - SqlInsert.Values type returned to original Dictionary, removed internal collection type and. - all usages of SqlInsert.Values * IMultiRecordPersistDescriptor-related changes - the interface properties renamed - added lazy alternative for one-row request with default implementation to IPersistRecord.StoreRequest. This keeps original interface API and have lazy request. TemporaryTableDescriptor uses only lazy properties as well as TemporaryTableManager, original StoreRequest implementaion in TemporaryTableDescriptor returns Lazy<>.Value and hidded. - WellKnown constants renamed accordingly to IMultiRecordPersistDescriptor properties - added summaries for interfaces' properties and WellKnown constants * Rename file containing interfaces * Remove unused code + commited code
1 parent a60cd18 commit bd1a93f

45 files changed

Lines changed: 1037 additions & 635 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Extensions/Xtensive.Orm.BulkOperations/Internals/AddValueContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Linq.Expressions;
23
using Xtensive.Linq;
34
using Xtensive.Orm.Model;
@@ -14,9 +15,9 @@ internal class AddValueContext
1415
public LambdaExpression Lambda { get; set; }
1516
public SetStatement Statement { get; set; }
1617

17-
public FieldInfo Field { get; set; }
18+
public FieldInfo Field => Descriptor.Field;
1819

19-
public bool SubqueryExists { get; set; }
20+
public Dictionary<SqlColumn, SqlExpression> Values { get; set; }
2021

2122
public object EvalLambdaBody() =>
2223
Lambda.Body is ConstantExpression ce

Extensions/Xtensive.Orm.BulkOperations/Internals/BaseSqlVisitor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Xtensive.Sql;
34
using Xtensive.Sql.Ddl;
45
using Xtensive.Sql.Dml;
@@ -318,10 +319,11 @@ public virtual void Visit(SqlInsert node)
318319
{
319320
VisitInternal(node.From);
320321
VisitInternal(node.Into);
321-
foreach (var column in node.Values.Columns) {
322-
VisitInternal(column);
323-
foreach (var value in node.Values.ValuesByColumn(column)) {
324-
VisitInternal(value);
322+
323+
foreach(var row in node.ValueRows) {
324+
foreach(var columnvalue in row.Zip(node.ValueRows.Columns)) {
325+
VisitInternal(columnvalue.Second);
326+
VisitInternal(columnvalue.First);
325327
}
326328
}
327329
}

Extensions/Xtensive.Orm.BulkOperations/Internals/SetOperation.cs

Lines changed: 163 additions & 152 deletions
Large diffs are not rendered by default.

Extensions/Xtensive.Orm.BulkOperations/Internals/SetStatement.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using Xtensive.Sql;
34
using Xtensive.Sql.Dml;
45

@@ -20,9 +21,9 @@ public override SqlTable Table
2021
get { return insert.Into; }
2122
}
2223

23-
public override void AddValue(SqlTableColumn column, SqlExpression value)
24+
public override void AddValues(Dictionary<SqlColumn, SqlExpression> values)
2425
{
25-
insert.Values.Add(column, value);
26+
insert.ValueRows.Add(values);
2627
}
2728
}
2829

@@ -42,30 +43,33 @@ public override SqlTable Table
4243
get { return update.Update; }
4344
}
4445

45-
public override void AddValue(SqlTableColumn column, SqlExpression value)
46+
public override void AddValues(Dictionary<SqlColumn, SqlExpression> values)
4647
{
47-
update.Values.Add(column, value);
48+
if (update.Values.Count!=0) {
49+
throw new InvalidOperationException("Update values have already been initialized");
50+
}
51+
foreach (var keyValue in values) {
52+
update.Values.Add((SqlTableColumn)keyValue.Key, keyValue.Value);
53+
}
4854
}
4955
}
5056

5157
#endregion
5258

5359
private SqlQueryStatement statement;
5460

55-
public static SetStatement Create(SqlQueryStatement statement)
61+
public static SetStatement Create(SqlUpdate updateStatement)
5662
{
57-
SetStatement result;
58-
if (statement is SqlUpdate)
59-
result = new Update();
60-
else if (statement is SqlInsert)
61-
result = new Insert();
62-
else
63-
throw new InvalidOperationException("Statement must be SqlUpdate or SqlInsert");
64-
result.statement = statement;
65-
return result;
63+
return new Update() { statement = updateStatement };
64+
}
65+
66+
public static SetStatement Create(SqlInsert insertStatement)
67+
{
68+
return new Insert() { statement = insertStatement };
6669
}
6770

6871
public abstract SqlTable Table { get; }
69-
public abstract void AddValue(SqlTableColumn column, SqlExpression value);
72+
73+
public abstract void AddValues(Dictionary<SqlColumn, SqlExpression> values);
7074
}
7175
}

Extensions/Xtensive.Orm.BulkOperations/Internals/WellKnownMembers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Xtensive LLC.
1+
// Copyright (C) 2020-2023 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

@@ -16,7 +16,9 @@ internal static class WellKnownMembers
1616
public static readonly Type FuncOfTArgTResultType = typeof(Func<,>);
1717

1818
public static readonly Type IncludeAlgorithmType = typeof(IncludeAlgorithm);
19+
public static readonly Type QueryableType = typeof(Queryable);
1920
public static readonly Type QueryableExtensionsType = typeof(QueryableExtensions);
21+
2022
public const string InMethodName = nameof(QueryableExtensions.In);
2123

2224
public static readonly MethodInfo TranslateQueryMethod =

Orm/Xtensive.Orm.Tests.Framework/TestHelper.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Copyright (C) 2008-2021 Xtensive LLC.
1+
// Copyright (C) 2008-2023 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: Alex Yakunin
55
// Created: 2008.02.09
66

77
using System;
8+
using System.Collections.Generic;
89
using System.Threading;
10+
using Xtensive.Sql.Dml;
911

1012
namespace Xtensive.Orm.Tests
1113
{
@@ -82,5 +84,16 @@ public static DateTime FixDateTimeForProvider(this DateTime origin, StorageProvi
8284
var newTicks = ticks - (ticks % divider.Value);
8385
return new DateTime(newTicks);
8486
}
87+
88+
public static void AddValueRow(this SqlInsert insert, in (SqlColumn column, SqlExpression value) first, params (SqlColumn column, SqlExpression value)[] additional)
89+
{
90+
var additional1 = additional ?? Array.Empty<(SqlColumn,SqlExpression)>();
91+
var row = new Dictionary<SqlColumn, SqlExpression>(1 + additional1.Length);
92+
row.Add(first.column, first.value);
93+
foreach (var keyValue in additional1) {
94+
row.Add(keyValue.column, keyValue.value);
95+
}
96+
insert.ValueRows.Add(row);
97+
}
8598
}
8699
}

Orm/Xtensive.Orm.Tests.Sql/ChinookSchemaCreator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019-2022 Xtensive LLC.
1+
// Copyright (C) 2019-2023 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: Alexey Kulakov
@@ -325,13 +325,14 @@ private static void ExecuteInsert(SqlConnection connection, Table table, Diction
325325
{
326326
var tableRef = SqlDml.TableRef(table);
327327
var insertQuery = SqlDml.Insert(tableRef);
328+
var row = new Dictionary<SqlColumn, SqlExpression>(values.Count);
328329
foreach (var nameValue in values) {
329330
var value = nameValue.Value != null
330331
? (SqlExpression) SqlDml.Literal(nameValue.Value)
331332
: SqlDml.Null;
332-
insertQuery.Values.Add(tableRef[nameValue.Key], value);
333+
row.Add(tableRef[nameValue.Key], value);
333334
}
334-
335+
insertQuery.ValueRows.Add(row);
335336
using var command = connection.CreateCommand(insertQuery);
336337
Console.WriteLine(command.CommandText);
337338
_ = command.ExecuteNonQuery();

Orm/Xtensive.Orm.Tests.Sql/CloneTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2003-2023 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44

55
using NUnit.Framework;
66
using System;
@@ -598,18 +598,19 @@ public void SqlInsertCloneTest()
598598
{
599599
SqlTableRef t = SqlDml.TableRef(table1);
600600
SqlInsert i = SqlDml.Insert(t);
601-
i.Values.SetValueByColumn(t[0], 1);
602-
i.Values.SetValueByColumn(t[1], "Anonym");
601+
i.AddValueRow(( t[0], 1 ), ( t[1], "Anonym" ));
603602
i.Hints.Add(SqlDml.FastFirstRowsHint(10));
604603
SqlInsert iClone = (SqlInsert)i.Clone();
605604

606605
Assert.AreNotEqual(i, iClone);
607606
Assert.AreNotEqual(i.Into, iClone.Into);
608607
Assert.AreEqual(i.NodeType, iClone.NodeType);
609-
Assert.AreEqual(i.Values.Count, iClone.Values.Count);
610-
foreach (var column in i.Values.Columns) {
611-
Assert.IsFalse(iClone.Values.ContainsColumn(column));
612-
Assert.IsFalse(i.Values.ValuesByColumn(column).Any(v => iClone.Values.ContainsValue(v)));
608+
Assert.AreEqual(i.ValueRows.Count, iClone.ValueRows.Count);
609+
Assert.AreEqual(i.ValueRows.Columns.Count, iClone.ValueRows.Columns.Count);
610+
for(var indx = 0; indx < i.ValueRows.Count; indx++) {
611+
var iRow = i.ValueRows[indx];
612+
var iClonedRow = iClone.ValueRows[indx];
613+
Assert.IsFalse(iRow.SequenceEqual(iClonedRow));
613614
}
614615
Assert.AreEqual(i.Hints.Count, iClone.Hints.Count);
615616
}

0 commit comments

Comments
 (0)