be91192de837bd0f9a419c0a34413d25fda4ffb8
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / ViewGeneration / Validation / ViewCellRelation.cs
1 //---------------------------------------------------------------------
2 // <copyright file="ViewCellRelation.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner [....]
7 // @backupOwner [....]
8 //---------------------------------------------------------------------
9
10 using System.Collections.Generic;
11 using System.Data.Mapping.ViewGeneration.Structures;
12 using System.Text;
13 using System.Data.Common.Utils;
14
15
16 namespace System.Data.Mapping.ViewGeneration.Validation
17 {
18     /// <summary>
19     /// Represents a relation signature that lists all projected
20     /// slots of two cell queries in a cell after projection. So if
21     /// SPerson1.Disc is present in the cellquery (and part of the where
22     /// clause) but not in the projected slots, it is missing from a ViewCellRelation
23     /// </summary>
24     internal class ViewCellRelation : CellRelation
25     {
26
27         #region Constructor
28         // effects: Creates a view cell relation for "cell" with the
29         // projected slots given by slots -- cellNumber is the number of the
30         // cell for debugging purposes
31         // Also creates the BasicCellRelations for the left and right cell queries
32         internal ViewCellRelation(Cell cell, List<ViewCellSlot> slots, int cellNumber)
33             : base(cellNumber)
34         {
35             m_cell = cell;
36             m_slots = slots;
37             // We create the basiccellrelations  passing this to it so that we have
38             // a reference from the basiccellrelations to this
39             m_cell.CQuery.CreateBasicCellRelation(this);
40             m_cell.SQuery.CreateBasicCellRelation(this);
41         }
42         #endregion
43
44         #region Fields
45         private Cell m_cell; // The cell for which this relation exists
46         private List<ViewCellSlot> m_slots; // Slots projected from both cell queries
47         #endregion
48
49         #region Properties
50         internal Cell Cell
51         {
52             get { return m_cell; }
53         }
54         #endregion
55
56
57         #region Methods
58         // requires: slot corresponds to a slot in the corresponding
59         // BasicCellRelation
60         // effects: Given a slot in the corresponding basicCellRelation,
61         // looks up the slot in this viewcellrelation and returns it. Returns
62         // null if it does not find the slot in the left or right side of the viewrelation
63         internal ViewCellSlot LookupViewSlot(MemberProjectedSlot slot)
64         {
65             // CHANGE_[....]_IMPROVE: We could have a dictionary to speed this up
66             foreach (ViewCellSlot viewSlot in m_slots)
67             {
68                 // If the left or right slots are equal, return the viewSlot
69                 if (ProjectedSlot.EqualityComparer.Equals(slot, viewSlot.CSlot) ||
70                     ProjectedSlot.EqualityComparer.Equals(slot, viewSlot.SSlot))
71                 {
72                     return viewSlot;
73                 }
74             }
75             return null;
76         }
77
78         protected override int GetHash()
79         {
80             // Note: Using CLR-Hashcode
81             return m_cell.GetHashCode();
82             // We need not hash the slots, etc - cell should give us enough
83             // differentiation and land the relation into the same bucket
84         }
85
86         internal override void ToCompactString(StringBuilder builder)
87         {
88             builder.Append("ViewRel[");
89             m_cell.ToCompactString(builder);
90             // StringUtil.ToSeparatedStringSorted(builder, m_slots, ", ");
91             builder.Append(']');
92         }
93         #endregion
94     }
95 }