Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / SqlClient / SqlGen / JoinSymbol.cs
1 //---------------------------------------------------------------------
2 // <copyright file="JoinSymbol.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections.Generic;
12 using System.Diagnostics;
13 using System.IO;
14 using System.Text;
15 using System.Data.SqlClient;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees;
18
19 namespace System.Data.SqlClient.SqlGen
20 {
21     /// <summary>
22     /// A Join symbol is a special kind of Symbol.
23     /// It has to carry additional information
24     /// <list type="bullet">
25     /// <item>ColumnList for the list of columns in the select clause if this
26     /// symbol represents a sql select statement.  This is set by <see cref="SqlGenerator.AddDefaultColumns"/>. </item>
27     /// <item>ExtentList is the list of extents in the select clause.</item>
28     /// <item>FlattenedExtentList - if the Join has multiple extents flattened at the 
29     /// top level, we need this information to ensure that extent aliases are renamed
30     /// correctly in <see cref="SqlSelectStatement.WriteSql"/></item>
31     /// <item>NameToExtent has all the extents in ExtentList as a dictionary.
32     /// This is used by <see cref="SqlGenerator.Visit(DbPropertyExpression)"/> to flatten
33     /// record accesses.</item>
34     /// <item>IsNestedJoin - is used to determine whether a JoinSymbol is an 
35     /// ordinary join symbol, or one that has a corresponding SqlSelectStatement.</item>
36     /// </list>
37     /// 
38     /// All the lists are set exactly once, and then used for lookups/enumerated.
39     /// </summary>
40     internal sealed class JoinSymbol : Symbol
41     {
42         private List<Symbol> columnList;
43         internal List<Symbol> ColumnList
44         {
45             get
46             {
47                 if (null == columnList)
48                 {
49                     columnList = new List<Symbol>();
50                 }
51                 return columnList;
52             }
53             set { columnList = value; }
54         }
55
56         private List<Symbol> extentList;
57         internal List<Symbol> ExtentList
58         {
59             get { return extentList; }
60         }
61
62         private List<Symbol> flattenedExtentList;
63         internal List<Symbol> FlattenedExtentList
64         {
65             get
66             {
67                 if (null == flattenedExtentList)
68                 {
69                     flattenedExtentList = new List<Symbol>();
70                 }
71                 return flattenedExtentList;
72             }
73             set { flattenedExtentList = value; }
74         }
75
76         private Dictionary<string, Symbol> nameToExtent;
77         internal Dictionary<string, Symbol> NameToExtent
78         {
79             get { return nameToExtent; }
80         }
81
82         private bool isNestedJoin;
83         internal bool IsNestedJoin
84         {
85             get { return isNestedJoin; }
86             set { isNestedJoin = value; }
87         }
88
89         public JoinSymbol(string name, TypeUsage type, List<Symbol> extents)
90             : base(name, type)
91         {
92             extentList = new List<Symbol>(extents.Count);
93             nameToExtent = new Dictionary<string, Symbol>(extents.Count, StringComparer.OrdinalIgnoreCase);
94             foreach (Symbol symbol in extents)
95             {
96                 this.nameToExtent[symbol.Name] = symbol;
97                 this.ExtentList.Add(symbol);
98             }
99         }
100     }
101 }