Propagator.JoinPropagator.JoinPredicateVisitor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Map / Update / Internal / Propagator.JoinPropagator.JoinPredicateVisitor.cs / 1 / Propagator.JoinPropagator.JoinPredicateVisitor.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Data.Common.CommandTrees; 
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Data.Mapping.Update.Internal
{ 
    internal partial class Propagator
    { 
        private partial class JoinPropagator 
        {
            ///  
            /// Extracts equi-join properties from a join condition.
            /// 
            /// 
            /// Assumptions: 
            /// 
            /// Only conjunctions of equality predicates are supported 
            /// Each equality predicate is of the form (left property == right property). The order 
            /// is important.
            ///  
            /// 
            private class JoinPredicateVisitor : UpdateExpressionVisitor
            {
                #region Constructors 
                /// 
                /// Initializes a join predicate visitor. The visitor will populate the given property 
                /// lists with expressions describing the left and right hand side of equi-join 
                /// sub-clauses.
                ///  
                /// List to populate with 'left' equi-join expressions
                /// List to populate with 'right' equi-join expressions
                private JoinPredicateVisitor(List leftProperties,
                    List rightProperties) 
                {
                    EntityUtil.CheckArgumentNull(leftProperties, "leftProperties"); 
                    EntityUtil.CheckArgumentNull(rightProperties, "rightProperties"); 

                    m_leftProperties = leftProperties; 
                    m_rightProperties = rightProperties;
                }
                #endregion
 
                #region Fields
                private List m_leftProperties; 
                private List m_rightProperties; 
                private static readonly string s_visitorName = typeof(JoinPredicateVisitor).FullName;
                #endregion 

                #region Properties
                override protected string VisitorName
                { 
                    get { return s_visitorName; }
                } 
                #endregion 

                #region Methods 
                #region Static helper methods
                /// 
                /// Determine properties from the left and right inputs to an equi-join participating
                /// in predicate. 
                /// 
                ///  
                /// The property definitions returned are 'aligned'. If the join predicate reads: 
                /// 
                /// a = b AND c = d AND e = f 
                /// 
                /// then the output is as follows:
                /// 
                /// leftProperties = {a, c, e} 
                /// rightProperties = {b, d, f}
                ///  
                /// See Walker class for an explanation of this coding pattern. 
                /// 
                ///  
                /// 
                /// 
                static internal void ExtractEquijoinProperties(DbExpression joinCondition, out DbExpression[] leftProperties, out DbExpression[] rightProperties)
                { 
                    EntityUtil.CheckArgumentNull(joinCondition, "joinCondition");
 
                    // Initialize empty property lists 
                    List leftPropertiesList = new List();
                    List rightPropertiesList = new List(); 

                    // Constructs a new predicate visitor, which implements a visitor for expression nodes
                    // and returns no values. This visitor instead builds up a list of properties as leaves
                    // of the join predicate are visited. 
                    DbExpressionVisitor visitor = new JoinPredicateVisitor(leftPropertiesList,
                        rightPropertiesList); 
 
                    // Walk the predicate using the predicate visitor.
                    joinCondition.Accept(visitor); 

                    // Retrieve properties discovered visiting predicate leaf nodes.
                    leftProperties = leftPropertiesList.ToArray();
                    rightProperties = rightPropertiesList.ToArray(); 

                    Debug.Assert(leftProperties.Length == rightProperties.Length, 
                        "(Update/JoinPropagator) The equi-join must have an equal number of left and right properties"); 
                }
                #endregion 

                #region Visitor implementation
                /// 
                /// Visit and node after its children have visited. There is nothing to do here 
                /// because only leaf equality nodes contain properties extracted by this visitor.
                ///  
                /// And expression node 
                /// Results ignored by this visitor implementation.
                public override object Visit(DbAndExpression node) 
                {
                    EntityUtil.CheckArgumentNull(node, "node");

                    Visit(node.Left); 
                    Visit(node.Right);
 
                    return null; 
                }
 
                /// 
                /// Perform work for an equality expression node.
                /// 
                /// Equality expresion node 
                /// Results ignored by this visitor implementation.
                public override object Visit(DbComparisonExpression node) 
                { 
                    EntityUtil.CheckArgumentNull(node, "node");
 
                    if (DbExpressionKind.Equals == node.ExpressionKind)
                    {
                        m_leftProperties.Add(node.Left);
                        m_rightProperties.Add(node.Right); 
                        return null;
                    } 
                    else 
                    {
                        throw ConstructNotSupportedException(node); 
                    }
                }
                #endregion
                #endregion 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Data.Common.CommandTrees; 
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Data.Mapping.Update.Internal
{ 
    internal partial class Propagator
    { 
        private partial class JoinPropagator 
        {
            ///  
            /// Extracts equi-join properties from a join condition.
            /// 
            /// 
            /// Assumptions: 
            /// 
            /// Only conjunctions of equality predicates are supported 
            /// Each equality predicate is of the form (left property == right property). The order 
            /// is important.
            ///  
            /// 
            private class JoinPredicateVisitor : UpdateExpressionVisitor
            {
                #region Constructors 
                /// 
                /// Initializes a join predicate visitor. The visitor will populate the given property 
                /// lists with expressions describing the left and right hand side of equi-join 
                /// sub-clauses.
                ///  
                /// List to populate with 'left' equi-join expressions
                /// List to populate with 'right' equi-join expressions
                private JoinPredicateVisitor(List leftProperties,
                    List rightProperties) 
                {
                    EntityUtil.CheckArgumentNull(leftProperties, "leftProperties"); 
                    EntityUtil.CheckArgumentNull(rightProperties, "rightProperties"); 

                    m_leftProperties = leftProperties; 
                    m_rightProperties = rightProperties;
                }
                #endregion
 
                #region Fields
                private List m_leftProperties; 
                private List m_rightProperties; 
                private static readonly string s_visitorName = typeof(JoinPredicateVisitor).FullName;
                #endregion 

                #region Properties
                override protected string VisitorName
                { 
                    get { return s_visitorName; }
                } 
                #endregion 

                #region Methods 
                #region Static helper methods
                /// 
                /// Determine properties from the left and right inputs to an equi-join participating
                /// in predicate. 
                /// 
                ///  
                /// The property definitions returned are 'aligned'. If the join predicate reads: 
                /// 
                /// a = b AND c = d AND e = f 
                /// 
                /// then the output is as follows:
                /// 
                /// leftProperties = {a, c, e} 
                /// rightProperties = {b, d, f}
                ///  
                /// See Walker class for an explanation of this coding pattern. 
                /// 
                ///  
                /// 
                /// 
                static internal void ExtractEquijoinProperties(DbExpression joinCondition, out DbExpression[] leftProperties, out DbExpression[] rightProperties)
                { 
                    EntityUtil.CheckArgumentNull(joinCondition, "joinCondition");
 
                    // Initialize empty property lists 
                    List leftPropertiesList = new List();
                    List rightPropertiesList = new List(); 

                    // Constructs a new predicate visitor, which implements a visitor for expression nodes
                    // and returns no values. This visitor instead builds up a list of properties as leaves
                    // of the join predicate are visited. 
                    DbExpressionVisitor visitor = new JoinPredicateVisitor(leftPropertiesList,
                        rightPropertiesList); 
 
                    // Walk the predicate using the predicate visitor.
                    joinCondition.Accept(visitor); 

                    // Retrieve properties discovered visiting predicate leaf nodes.
                    leftProperties = leftPropertiesList.ToArray();
                    rightProperties = rightPropertiesList.ToArray(); 

                    Debug.Assert(leftProperties.Length == rightProperties.Length, 
                        "(Update/JoinPropagator) The equi-join must have an equal number of left and right properties"); 
                }
                #endregion 

                #region Visitor implementation
                /// 
                /// Visit and node after its children have visited. There is nothing to do here 
                /// because only leaf equality nodes contain properties extracted by this visitor.
                ///  
                /// And expression node 
                /// Results ignored by this visitor implementation.
                public override object Visit(DbAndExpression node) 
                {
                    EntityUtil.CheckArgumentNull(node, "node");

                    Visit(node.Left); 
                    Visit(node.Right);
 
                    return null; 
                }
 
                /// 
                /// Perform work for an equality expression node.
                /// 
                /// Equality expresion node 
                /// Results ignored by this visitor implementation.
                public override object Visit(DbComparisonExpression node) 
                { 
                    EntityUtil.CheckArgumentNull(node, "node");
 
                    if (DbExpressionKind.Equals == node.ExpressionKind)
                    {
                        m_leftProperties.Add(node.Left);
                        m_rightProperties.Add(node.Right); 
                        return null;
                    } 
                    else 
                    {
                        throw ConstructNotSupportedException(node); 
                    }
                }
                #endregion
                #endregion 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK