Skip to content

Commit ad0110f

Browse files
committed
Merge branch 'avoid-merge-before-fix-problems' into master-domain-build-imp
# Conflicts: # Orm/Xtensive.Orm.Tests.Framework/DomainModelExtensions.cs # Orm/Xtensive.Orm.Tests/Storage/Prefetch/PrefetchTestHelper.cs # Orm/Xtensive.Orm/Collections/Interfaces/IFilterable.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ClassTable.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ClusteredIndexes.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ConcreteTable.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.FullText.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.SingleTable.cs # Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs # Orm/Xtensive.Orm/Orm/Building/Builders/ModelBuilder.cs # Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingValidator.cs # Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs # Orm/Xtensive.Orm/Orm/Internals/Prefetch/PrefetchManager.cs # Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs # Orm/Xtensive.Orm/Orm/Model/ColumnInfoCollection.cs # Orm/Xtensive.Orm/Orm/Model/FieldInfoCollection.cs # Orm/Xtensive.Orm/Orm/Model/HierarchyInfo.cs # Orm/Xtensive.Orm/Orm/Model/IndexInfoCollection.cs # Orm/Xtensive.Orm/Orm/Model/TypeInfo.cs # Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs # Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs
2 parents 9734d03 + 20b3f6e commit ad0110f

25 files changed

+613
-438
lines changed

Orm/Xtensive.Orm.Tests.Framework/DomainModelExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public static void DumpAncestor(this TypeInfo target, int indent)
9292
public static void DumpDescendants(this TypeInfo target, int indent)
9393
{
9494
WriteLine(indent, "Descendants:");
95-
var direct = target.Descendants;
96-
foreach (TypeInfo descendant in target.RecursiveDescendants) {
95+
var direct = target.DirectDescendants;
96+
foreach (TypeInfo descendant in target.AllDescendants) {
9797
if (direct.Contains(descendant))
9898
WriteLine(indent + 1, descendant.Name + " (direct)");
9999
else
@@ -104,8 +104,8 @@ public static void DumpDescendants(this TypeInfo target, int indent)
104104
public static void DumpInterfaces(this TypeInfo target, int indent)
105105
{
106106
WriteLine(indent, "Interfaces:");
107-
var direct = target.Interfaces;
108-
foreach (TypeInfo @interface in target.RecursiveInterfaces) {
107+
var direct = target.DirectInterfaces;
108+
foreach (TypeInfo @interface in target.AllInterfaces) {
109109
if (direct.Contains(@interface))
110110
WriteLine(indent + 1, @interface.Name + " (direct)");
111111
else
@@ -116,8 +116,8 @@ public static void DumpInterfaces(this TypeInfo target, int indent)
116116
public static void DumpImplementors(this TypeInfo target, int indent)
117117
{
118118
WriteLine(indent, "Implementors:");
119-
var direct = target.Implementors;
120-
foreach (TypeInfo implementor in target.RecursiveImplementors) {
119+
var direct = target.DirectImplementors;
120+
foreach (TypeInfo implementor in target.AllImplementors) {
121121
if (direct.Contains(implementor))
122122
WriteLine(indent + 1, implementor.Name + " (direct)");
123123
else
@@ -166,7 +166,7 @@ public static void Dump(this TypeInfo target, int indent)
166166
WriteLine(indent, "Ancestor: " + target.Ancestor.Name);
167167
}
168168
else if (target.IsInterface) {
169-
WriteLine(indent, "Implementors: " + target.Implementors.Select(t => t.Name).ToCommaDelimitedString());
169+
WriteLine(indent, "Implementors: " + target.DirectImplementors.Select(t => t.Name).ToCommaDelimitedString());
170170
}
171171

172172
target.DumpMappingName(indent);

Orm/Xtensive.Orm.Tests/Storage/Prefetch/PrefetchTestHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public static void AssertOnlySpecifiedColumnsAreLoaded(Key key, TypeInfo type, S
4141
{
4242
var state = session.EntityStateCache[key, true];
4343
var realType = state.Key.TypeInfo;
44-
Assert.IsTrue(realType.Equals(type)
45-
|| realType.Ancestors.Contains(type)
46-
|| (type.IsInterface && realType.RecursiveInterfaces.Contains(type)));
44+
Assert.IsTrue(realType.Equals(type)
45+
|| realType.Ancestors.Contains(type)
46+
|| (type.IsInterface && realType.AllInterfaces.Contains(type)));
4747
var tuple = state.Tuple;
4848
Assert.IsNotNull(tuple);
4949
foreach (var field in type.Fields) {

Orm/Xtensive.Orm/Collections/Interfaces/IFilterable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public interface IFilterable<TFilter, TItem>
2020
/// Finds the items from initial collection according to specified filter <paramref name="criteria"/>.
2121
/// </summary>
2222
/// <param name="criteria">The object to filter initial collection with.</param>
23-
/// <returns><see cref="ICollection{TItem}"/> object.</returns>
23+
/// <returns><see cref="IEnumerable{TItem}"/> object.</returns>
2424
IEnumerable<TItem> Find(TFilter criteria);
2525

2626
/// <summary>
2727
/// Finds the items from initial collection according to specified filter <paramref name="criteria"/>.
2828
/// </summary>
2929
/// <param name="criteria">The object to filter initial collection with.</param>
3030
/// <param name="matchType">Type of the match.</param>
31-
/// <returns><see cref="ICollection{TItem}"/> object.</returns>
31+
/// <returns><see cref="IEnumerable{TItem}"/> object.</returns>
3232
IEnumerable<TItem> Find(TFilter criteria, MatchType matchType);
3333
}
3434
}

Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ClassTable.cs

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,29 @@
1313

1414
namespace Xtensive.Orm.Building.Builders
1515
{
16-
partial class IndexBuilder
16+
internal partial class IndexBuilder
1717
{
1818
private void BuildClassTableIndexes(TypeInfo type)
1919
{
20-
if (type.Indexes.Count > 0)
21-
return;
22-
if (type.IsStructure)
20+
if (type.Indexes.Count > 0 || type.IsStructure) {
2321
return;
22+
}
2423

2524
var root = type.Hierarchy.Root;
2625
var typeDef = context.ModelDef.Types[type.UnderlyingType];
2726
var ancestors = type.Ancestors;
28-
var interfaces = type.Interfaces;
27+
var interfaces = type.DirectInterfaces;
2928

3029
// Building declared indexes both secondary and primary (for root of the hierarchy only)
3130
foreach (var indexDescriptor in typeDef.Indexes) {
3231
// Skip indef building for inherited fields
3332
var hasInheritedFields = indexDescriptor.KeyFields
3433
.Select(kvp => type.Fields[kvp.Key])
35-
.Any(f => f.IsInherited);
36-
if (hasInheritedFields)
34+
.Any(static f => f.IsInherited);
35+
if (hasInheritedFields) {
3736
continue;
37+
}
38+
3839
var declaredIndex = BuildIndex(type, indexDescriptor, false);
3940

4041
type.Indexes.Add(declaredIndex);
@@ -53,16 +54,21 @@ private void BuildClassTableIndexes(TypeInfo type)
5354

5455
// Building inherited from interfaces indexes
5556
foreach (var @interface in interfaces) {
56-
foreach (var interfaceIndex in @interface.Indexes.Find(IndexAttributes.Primary, MatchType.None)) {
57+
foreach (var interfaceIndex in @interface.Indexes.Find(IndexAttributes.Primary, MatchType.None).ToChainedBuffer()) {
5758
if (interfaceIndex.DeclaringIndex != interfaceIndex &&
5859
parent != null &&
59-
parent.Indexes.Any(i => i.DeclaringIndex == interfaceIndex))
60+
parent.Indexes.Any(i => i.DeclaringIndex == interfaceIndex)) {
6061
continue;
61-
if (type.Indexes.Any(i => i.DeclaringIndex == interfaceIndex))
62+
}
63+
64+
if (type.Indexes.Any(i => i.DeclaringIndex == interfaceIndex)) {
6265
continue;
66+
}
67+
6368
var index = BuildInheritedIndex(type, interfaceIndex, false);
64-
if (IndexBuiltOverInheritedFields(index))
69+
if (IndexBuiltOverInheritedFields(index)) {
6570
BuildLog.Warning(string.Format(Strings.ExUnableToBuildIndexXBecauseItWasBuiltOverInheritedFields, index.Name));
71+
}
6672
else {
6773
type.Indexes.Add(index);
6874
context.Model.RealIndexes.Add(index);
@@ -71,37 +77,44 @@ private void BuildClassTableIndexes(TypeInfo type)
7177
}
7278

7379
// Build typed indexes
74-
if (type == root)
75-
foreach (var realIndex in type.Indexes.Find(IndexAttributes.Real)) {
76-
if (!untypedIndexes.Contains(realIndex))
80+
if (type == root) {
81+
foreach (var realIndex in type.Indexes.Find(IndexAttributes.Real).ToChainedBuffer()) {
82+
if (!untypedIndexes.Contains(realIndex)) {
7783
continue;
84+
}
7885
var typedIndex = BuildTypedIndex(type, realIndex);
7986
type.Indexes.Add(typedIndex);
8087
}
88+
}
8189

8290
// Build indexes for descendants
83-
foreach (var descendant in type.Descendants)
91+
foreach (var descendant in type.DirectDescendants) {
8492
BuildClassTableIndexes(descendant);
93+
}
8594

8695
// Import inherited indexes
8796
var primaryIndex = type.Indexes.FindFirst(IndexAttributes.Primary | IndexAttributes.Real);
88-
if (untypedIndexes.Contains(primaryIndex) && primaryIndex.ReflectedType == root)
97+
if (untypedIndexes.Contains(primaryIndex) && primaryIndex.ReflectedType == root) {
8998
primaryIndex = type.Indexes.Single(i => i.DeclaringIndex == primaryIndex.DeclaringIndex && i.IsTyped);
90-
var filterByTypes = type.RecursiveDescendants.Append(type).ToList();
99+
}
100+
var filterByTypes = type.AllDescendants.Append(type).ToList(type.AllDescendants.Count + 1);
91101

92102
// Build virtual primary index
93103
if (ancestors.Count > 0) {
94104
var baseIndexes = new Stack<IndexInfo>();
95-
foreach (var ancestor in ancestors.Where(t => t.Fields.Any(f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared))) {
96-
var ancestorIndex = ancestor.Indexes.Single(i => i.IsPrimary && !i.IsVirtual);
97-
if (untypedIndexes.Contains(ancestorIndex) && ancestorIndex.ReflectedType == root)
105+
foreach (var ancestor in ancestors.Where(t => t.Fields.Any(static f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared))) {
106+
var ancestorIndex = ancestor.Indexes.Single(static i => i.IsPrimary && !i.IsVirtual);
107+
if (untypedIndexes.Contains(ancestorIndex) && ancestorIndex.ReflectedType == root) {
98108
ancestorIndex = ancestor.Indexes.Single(i => i.DeclaringIndex == ancestorIndex.DeclaringIndex && i.IsTyped);
99-
if (ancestorIndex.ValueColumns.Count > 0)
109+
}
110+
if (ancestorIndex.ValueColumns.Count > 0) {
100111
baseIndexes.Push(ancestorIndex);
112+
}
101113
}
102114
if (baseIndexes.Count > 0) {
103-
if (primaryIndex.ValueColumns.Count > 0 && type.Fields.Any(f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared))
115+
if (primaryIndex.ValueColumns.Count > 0 && type.Fields.Any(static f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared)) {
104116
baseIndexes.Push(primaryIndex);
117+
}
105118
else {
106119
var ancestorIndex = baseIndexes.Pop();
107120
var filteredIndex = BuildFilterIndex(type, ancestorIndex, filterByTypes);
@@ -115,9 +128,15 @@ private void BuildClassTableIndexes(TypeInfo type)
115128
}
116129

117130
// Build virtual secondary index
118-
foreach (var ancestorIndex in ancestors.SelectMany(ancestor => ancestor.Indexes.Find(IndexAttributes.Primary | IndexAttributes.Virtual, MatchType.None))) {
119-
if (ancestorIndex.DeclaringIndex != ancestorIndex)
131+
var primaryOrVirtualIndexes = ancestors
132+
.SelectMany(
133+
ancestor => ancestor.Indexes.Find(IndexAttributes.Primary | IndexAttributes.Virtual, MatchType.None).ToChainedBuffer());
134+
135+
foreach (var ancestorIndex in primaryOrVirtualIndexes) {
136+
if (ancestorIndex.DeclaringIndex != ancestorIndex) {
120137
continue;
138+
}
139+
121140
var ancestorType = ancestorIndex.ReflectedType;
122141
var indexToFilter = untypedIndexes.Contains(ancestorIndex) && ancestorIndex.ReflectedType == root
123142
? ancestorType.Indexes.Single(i => i.DeclaringIndex == ancestorIndex.DeclaringIndex && i.IsTyped)
@@ -127,7 +146,7 @@ private void BuildClassTableIndexes(TypeInfo type)
127146
}
128147
}
129148

130-
static bool IndexBuiltOverInheritedFields(IndexInfo index)
149+
private static bool IndexBuiltOverInheritedFields(IndexInfo index)
131150
{
132151
if (index.IsVirtual)
133152
return false;

Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ClusteredIndexes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private void ChooseClusteredIndexes()
2323
var clusteredIndexesMap = new Dictionary<TypeInfo, IndexInfo>();
2424
queue.Enqueue(hierarchy.Root);
2525
while (queue.TryDequeue(out var type)) {
26-
foreach (var decendant in type.Descendants) {
26+
foreach (var decendant in type.DirectDescendants) {
2727
queue.Enqueue(decendant);
2828
}
2929
var clusteredIndexes = type.Indexes

Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ConcreteTable.cs

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
namespace Xtensive.Orm.Building.Builders
1313
{
14-
partial class IndexBuilder
14+
internal partial class IndexBuilder
1515
{
1616
private void BuildConcreteTableIndexes(TypeInfo type)
1717
{
18-
if (type.Indexes.Count > 0)
19-
return;
20-
if (type.IsStructure)
18+
if (type.Indexes.Count > 0 || type.IsStructure) {
2119
return;
20+
}
2221

2322
var typeDef = context.ModelDef.Types[type.UnderlyingType];
2423
var root = type.Hierarchy.Root;
@@ -31,13 +30,15 @@ private void BuildConcreteTableIndexes(TypeInfo type)
3130
// and if they have some indexes then IndexDef.IsInherited of them will be true and it's truth actually,
3231
// but fields inherited from removed entities will have FieldInfo.IsInherited = false.
3332
// So, if we check only IndexDef.IsInherited then some indexes will be ignored.
34-
if (indexDescriptor.IsInherited && indexDescriptor.KeyFields.Select(kf=> type.Fields[kf.Key]).Any(f=>f.IsInherited))
33+
if (indexDescriptor.IsInherited && indexDescriptor.KeyFields.Select(kf=> type.Fields[kf.Key]).Any(static f => f.IsInherited)) {
3534
continue;
36-
var declaredIndex = BuildIndex(type, indexDescriptor, type.IsAbstract);
35+
}
3736

37+
var declaredIndex = BuildIndex(type, indexDescriptor, type.IsAbstract);
3838
type.Indexes.Add(declaredIndex);
39-
if (!declaredIndex.IsAbstract)
39+
if (!declaredIndex.IsAbstract) {
4040
context.Model.RealIndexes.Add(declaredIndex);
41+
}
4142
}
4243

4344
// Building primary index for non root entities
@@ -48,44 +49,51 @@ private void BuildConcreteTableIndexes(TypeInfo type)
4849

4950
// Registering built primary index
5051
type.Indexes.Add(inheritedIndex);
51-
if (!inheritedIndex.IsAbstract)
52+
if (!inheritedIndex.IsAbstract) {
5253
context.Model.RealIndexes.Add(inheritedIndex);
54+
}
5355
}
5456

5557
// Building inherited from interfaces indexes
56-
foreach (var @interface in type.RecursiveInterfaces) {
57-
foreach (var parentIndex in @interface.Indexes.Find(IndexAttributes.Primary, MatchType.None)) {
58-
if (parentIndex.DeclaringIndex != parentIndex)
58+
foreach (var @interface in type.AllInterfaces) {
59+
foreach (var parentIndex in @interface.Indexes.Find(IndexAttributes.Primary, MatchType.None).ToChainedBuffer()) {
60+
if (parentIndex.DeclaringIndex != parentIndex) {
5961
continue;
62+
}
63+
6064
var index = BuildInheritedIndex(type, parentIndex, type.IsAbstract);
61-
if ((parent != null && parent.Indexes.Contains(index.Name)) || type.Indexes.Contains(index.Name))
65+
if ((parent != null && parent.Indexes.Contains(index.Name)) || type.Indexes.Contains(index.Name)) {
6266
continue;
67+
}
68+
6369
type.Indexes.Add(index);
64-
if (!index.IsAbstract)
70+
if (!index.IsAbstract) {
6571
context.Model.RealIndexes.Add(index);
72+
}
6673
}
6774
}
6875

6976
// Build typed indexes
70-
foreach (var realIndex in type.Indexes.Find(IndexAttributes.Real)) {
71-
if (!untypedIndexes.Contains(realIndex))
77+
foreach (var realIndex in type.Indexes.Find(IndexAttributes.Real).ToChainedBuffer()) {
78+
if (!untypedIndexes.Contains(realIndex)) {
7279
continue;
80+
}
7381
var typedIndex = BuildTypedIndex(type, realIndex);
7482
type.Indexes.Add(typedIndex);
7583
}
7684

7785
// Build indexes for descendants
78-
foreach (var descendant in type.Descendants) {
86+
foreach (var descendant in type.DirectDescendants) {
7987
BuildConcreteTableIndexes(descendant);
8088
}
8189

8290
var ancestors = type.Ancestors;
83-
var descendants = type.RecursiveDescendants;
91+
var descendants = type.AllDescendants;
8492

8593
// Build primary virtual union index
8694
if (descendants.Count > 0) {
87-
var indexesToUnion = new List<IndexInfo>(){type.Indexes.PrimaryIndex};
88-
foreach (var index in descendants.Select(t => t.Indexes.PrimaryIndex)) {
95+
var indexesToUnion = new List<IndexInfo>(descendants.Count + 1) { type.Indexes.PrimaryIndex };
96+
foreach (var index in descendants.Select(static t => t.Indexes.PrimaryIndex)) {
8997
var indexView = BuildViewIndex(type, index);
9098
indexesToUnion.Add(indexView);
9199
}
@@ -95,34 +103,45 @@ private void BuildConcreteTableIndexes(TypeInfo type)
95103
}
96104

97105
// Build inherited secondary indexes
98-
foreach (var ancestorIndex in ancestors.SelectMany(ancestor => ancestor.Indexes.Find(IndexAttributes.Primary | IndexAttributes.Virtual, MatchType.None))) {
99-
if (ancestorIndex.DeclaringIndex != ancestorIndex)
106+
var primaryOrVirtualIndexes = ancestors
107+
.SelectMany(
108+
ancestor => ancestor.Indexes.Find(IndexAttributes.Primary | IndexAttributes.Virtual, MatchType.None).ToChainedBuffer());
109+
110+
foreach (var ancestorIndex in primaryOrVirtualIndexes) {
111+
if (ancestorIndex.DeclaringIndex != ancestorIndex) {
100112
continue;
113+
}
114+
101115
var secondaryIndex = BuildInheritedIndex(type, ancestorIndex, type.IsAbstract);
102116
type.Indexes.Add(secondaryIndex);
103-
if (!secondaryIndex.IsAbstract)
117+
if (!secondaryIndex.IsAbstract) {
104118
context.Model.RealIndexes.Add(secondaryIndex);
119+
}
105120
// Build typed index for secondary one
106-
if (!untypedIndexes.Contains(secondaryIndex))
121+
if (!untypedIndexes.Contains(secondaryIndex)) {
107122
continue;
123+
}
124+
108125
var typedIndex = BuildTypedIndex(type, secondaryIndex);
109126
type.Indexes.Add(typedIndex);
110127
}
111128

112129
// Build virtual secondary indexes
113-
if (descendants.Count > 0)
114-
foreach (var index in type.Indexes.Where(i => !i.IsPrimary && !i.IsVirtual).ToList()) {
130+
if (descendants.Count > 0) {
131+
foreach (var index in type.Indexes.Where(static i => !i.IsPrimary && !i.IsVirtual).ToChainedBuffer()) {
115132
var isUntyped = untypedIndexes.Contains(index);
116133
var indexToUnion = isUntyped
117134
? type.Indexes.Single(i => i.DeclaringIndex == index.DeclaringIndex && i.IsTyped)
118135
: index;
119136

120-
var indexesToUnion = new List<IndexInfo>() {indexToUnion};
121-
indexesToUnion.AddRange(descendants
122-
.Select(t => t.Indexes.Single(i => i.DeclaringIndex == index.DeclaringIndex && (isUntyped ? i.IsTyped : !i.IsVirtual))));
137+
var indexesToUnion = descendants
138+
.Select(t => t.Indexes.Single(i => i.DeclaringIndex == index.DeclaringIndex && (isUntyped ? i.IsTyped : !i.IsVirtual)))
139+
.Prepend(indexToUnion);
140+
123141
var virtualSecondaryIndex = BuildUnionIndex(type, indexesToUnion);
124142
type.Indexes.Add(virtualSecondaryIndex);
125143
}
144+
}
126145
}
127146
}
128147
}

0 commit comments

Comments
 (0)