Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / ViewGeneration / Structures / CellIdBoolean.cs
1 //---------------------------------------------------------------------
2 // <copyright file="CellIdBoolean.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 namespace System.Data.Mapping.ViewGeneration.Structures
11 {
12     using System.Collections.Generic;
13     using System.Data.Common.CommandTrees;
14     using System.Data.Common.CommandTrees.ExpressionBuilder;
15     using System.Data.Mapping.ViewGeneration.CqlGeneration;
16     using System.Diagnostics;
17     using System.Text;
18
19     /// <summary>
20     /// Wraps from0, from1, etc. boolean fields that identify the source of tuples (# of respective cell query) in the view statements.
21     /// </summary>
22     internal class CellIdBoolean : TrueFalseLiteral
23     {
24         #region Constructor
25         /// <summary>
26         /// Creates a boolean expression for the variable name specified by <paramref name="index"/>, e.g., 0 results in from0, 1 into from1.
27         /// </summary>
28         internal CellIdBoolean(CqlIdentifiers identifiers, int index)
29         {
30             Debug.Assert(index >= 0);
31             m_index = index;
32             m_slotName = identifiers.GetFromVariable(index);
33         }
34         #endregion
35
36         #region Fields
37         /// <summary>
38         /// e.g., from0, from1.
39         /// </summary>
40         private readonly int m_index;
41         private readonly string m_slotName;
42         #endregion
43
44         #region Properties
45         /// <summary>
46         /// Returns the slotName corresponding to this, ie., _from0 etc.
47         /// </summary>
48         internal string SlotName
49         {
50             get { return m_slotName; }
51         }
52         #endregion
53
54         #region BoolLiteral members
55         internal override StringBuilder AsEsql(StringBuilder builder, string blockAlias, bool skipIsNotNull)
56         {
57             // Get e.g., T2._from1 using the table alias
58             string qualifiedName = CqlWriter.GetQualifiedName(blockAlias, SlotName);
59             builder.Append(qualifiedName);
60             return builder;
61         }
62
63         internal override DbExpression AsCqt(DbExpression row, bool skipIsNotNull)
64         {
65             // Get e.g., row._from1
66             return row.Property(SlotName);
67         }
68
69         internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
70         {
71             return AsEsql(builder, blockAlias, skipIsNotNull);
72         }
73
74         internal override StringBuilder AsNegatedUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
75         {
76             builder.Append("NOT(");
77             builder = AsUserString(builder, blockAlias, skipIsNotNull);
78             builder.Append(")");
79             return builder;
80         }
81
82         internal override void GetRequiredSlots(MemberProjectionIndex projectedSlotMap, bool[] requiredSlots)
83         {
84             // The slot corresponding to from1, etc
85             int numBoolSlots = requiredSlots.Length - projectedSlotMap.Count;
86             int slotNum = projectedSlotMap.BoolIndexToSlot(m_index, numBoolSlots);
87             requiredSlots[slotNum] = true;
88         }
89
90         protected override bool IsEqualTo(BoolLiteral right)
91         {
92             CellIdBoolean rightBoolean = right as CellIdBoolean;
93             if (rightBoolean == null)
94             {
95                 return false;
96             }
97             return m_index == rightBoolean.m_index;
98         }
99
100         public override int GetHashCode()
101         {
102             return m_index.GetHashCode();
103         }
104
105         internal override BoolLiteral RemapBool(Dictionary<MemberPath, MemberPath> remap)
106         {
107             return this;
108         }
109         #endregion
110
111         #region Other Methods
112         internal override void ToCompactString(StringBuilder builder)
113         {
114             builder.Append(SlotName);
115         }
116         #endregion
117     }
118 }