1 //---------------------------------------------------------------------
2 // <copyright file="CellIdBoolean.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 namespace System.Data.Mapping.ViewGeneration.Structures
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;
20 /// Wraps from0, from1, etc. boolean fields that identify the source of tuples (# of respective cell query) in the view statements.
22 internal class CellIdBoolean : TrueFalseLiteral
26 /// Creates a boolean expression for the variable name specified by <paramref name="index"/>, e.g., 0 results in from0, 1 into from1.
28 internal CellIdBoolean(CqlIdentifiers identifiers, int index)
30 Debug.Assert(index >= 0);
32 m_slotName = identifiers.GetFromVariable(index);
38 /// e.g., from0, from1.
40 private readonly int m_index;
41 private readonly string m_slotName;
46 /// Returns the slotName corresponding to this, ie., _from0 etc.
48 internal string SlotName
50 get { return m_slotName; }
54 #region BoolLiteral members
55 internal override StringBuilder AsEsql(StringBuilder builder, string blockAlias, bool skipIsNotNull)
57 // Get e.g., T2._from1 using the table alias
58 string qualifiedName = CqlWriter.GetQualifiedName(blockAlias, SlotName);
59 builder.Append(qualifiedName);
63 internal override DbExpression AsCqt(DbExpression row, bool skipIsNotNull)
65 // Get e.g., row._from1
66 return row.Property(SlotName);
69 internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
71 return AsEsql(builder, blockAlias, skipIsNotNull);
74 internal override StringBuilder AsNegatedUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
76 builder.Append("NOT(");
77 builder = AsUserString(builder, blockAlias, skipIsNotNull);
82 internal override void GetRequiredSlots(MemberProjectionIndex projectedSlotMap, bool[] requiredSlots)
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;
90 protected override bool IsEqualTo(BoolLiteral right)
92 CellIdBoolean rightBoolean = right as CellIdBoolean;
93 if (rightBoolean == null)
97 return m_index == rightBoolean.m_index;
100 public override int GetHashCode()
102 return m_index.GetHashCode();
105 internal override BoolLiteral RemapBool(Dictionary<MemberPath, MemberPath> remap)
111 #region Other Methods
112 internal override void ToCompactString(StringBuilder builder)
114 builder.Append(SlotName);