Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Query / PlanCompiler / CodeGen.cs / 1 / CodeGen.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Diagnostics; // Please use PlanCompiler.Assert instead of Debug.Assert in this class...
using System.Globalization;
using md = System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees;
using System.Data.Query.InternalTrees;
using System.Data.Query.PlanCompiler;
//
// The CodeGen module is responsible for translating the ITree finally into a query
// We assume that various tree transformations have taken place, and the tree
// is finally ready to be executed. The CodeGen module
// * converts the Itree into one or more CTrees (in S space)
// * produces a ColumnMap to facilitate result assembly
// * and wraps up everything in a plan object
//
//
namespace System.Data.Query.PlanCompiler
{
internal class CodeGen
{
#region public methods
///
/// This involves
/// * Converting the ITree into a set of ProviderCommandInfo objects
/// * Creating a column map to enable result assembly
/// Currently, we only produce a single ITree, and correspondingly, the
/// following steps are trivial
///
/// current compiler state
/// CQTs for each store command
/// column map to help in result assembly
internal static void Process(PlanCompiler compilerState, out List childCommands, out ColumnMap resultColumnMap, out int columnCount)
{
CodeGen codeGen = new CodeGen(compilerState);
codeGen.Process(out childCommands, out resultColumnMap, out columnCount);
}
#endregion
#region constructors
private CodeGen(PlanCompiler compilerState)
{
m_compilerState = compilerState;
}
#endregion
#region private methods
///
/// The real driver. This routine walks the tree, converts each subcommand
/// into a CTree, and converts the columnmap into a real column map.
/// Finally, it produces a "real" plan that can be used by the bridge execution, and
/// returns this plan
///
/// The root of the tree must be a PhysicalProjectOp. Each child of this Op
/// represents a command to be executed, and the ColumnMap of this Op represents
/// the eventual columnMap to be used for result assembly
///
/// CQTs for store commands
/// column map for result assembly
private void Process(out List childCommands, out ColumnMap resultColumnMap, out int columnCount)
{
PhysicalProjectOp projectOp = (PhysicalProjectOp)this.Command.Root.Op;
this.m_subCommands = new List(new Node[] { this.Command.Root });
childCommands = new List(new ProviderCommandInfo[] {
ProviderCommandInfoUtils.Create(
this.Command,
this.Command.Root // input node
)});
// Build the final column map, and count the columns we expect for it.
resultColumnMap = BuildResultColumnMap(projectOp);
columnCount = projectOp.Outputs.Count;
}
private ColumnMap BuildResultColumnMap(PhysicalProjectOp projectOp)
{
// convert the column map into a real column map
// build up a dictionary mapping Vars to their real positions in the commands
Dictionary> varMap = BuildVarMap();
ColumnMap realColumnMap = ColumnMapTranslator.Translate(projectOp.ColumnMap, varMap);
return realColumnMap;
}
///
/// For each subcommand, build up a "location-map" for each top-level var that
/// is projected out. This location map will ultimately be used to convert VarRefColumnMap
/// into SimpleColumnMap
///
private Dictionary> BuildVarMap()
{
Dictionary> varMap =
new Dictionary>();
int commandId = 0;
foreach (Node subCommand in m_subCommands)
{
PhysicalProjectOp projectOp = (PhysicalProjectOp)subCommand.Op;
int columnPos = 0;
foreach (Var v in projectOp.Outputs)
{
KeyValuePair varLocation = new KeyValuePair(commandId, columnPos);
varMap[v] = varLocation;
columnPos++;
}
commandId++;
}
return varMap;
}
#endregion
#region private state
private PlanCompiler m_compilerState;
private Command Command { get { return m_compilerState.Command; } }
private List m_subCommands;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Diagnostics; // Please use PlanCompiler.Assert instead of Debug.Assert in this class...
using System.Globalization;
using md = System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees;
using System.Data.Query.InternalTrees;
using System.Data.Query.PlanCompiler;
//
// The CodeGen module is responsible for translating the ITree finally into a query
// We assume that various tree transformations have taken place, and the tree
// is finally ready to be executed. The CodeGen module
// * converts the Itree into one or more CTrees (in S space)
// * produces a ColumnMap to facilitate result assembly
// * and wraps up everything in a plan object
//
//
namespace System.Data.Query.PlanCompiler
{
internal class CodeGen
{
#region public methods
///
/// This involves
/// * Converting the ITree into a set of ProviderCommandInfo objects
/// * Creating a column map to enable result assembly
/// Currently, we only produce a single ITree, and correspondingly, the
/// following steps are trivial
///
/// current compiler state
/// CQTs for each store command
/// column map to help in result assembly
internal static void Process(PlanCompiler compilerState, out List childCommands, out ColumnMap resultColumnMap, out int columnCount)
{
CodeGen codeGen = new CodeGen(compilerState);
codeGen.Process(out childCommands, out resultColumnMap, out columnCount);
}
#endregion
#region constructors
private CodeGen(PlanCompiler compilerState)
{
m_compilerState = compilerState;
}
#endregion
#region private methods
///
/// The real driver. This routine walks the tree, converts each subcommand
/// into a CTree, and converts the columnmap into a real column map.
/// Finally, it produces a "real" plan that can be used by the bridge execution, and
/// returns this plan
///
/// The root of the tree must be a PhysicalProjectOp. Each child of this Op
/// represents a command to be executed, and the ColumnMap of this Op represents
/// the eventual columnMap to be used for result assembly
///
/// CQTs for store commands
/// column map for result assembly
private void Process(out List childCommands, out ColumnMap resultColumnMap, out int columnCount)
{
PhysicalProjectOp projectOp = (PhysicalProjectOp)this.Command.Root.Op;
this.m_subCommands = new List(new Node[] { this.Command.Root });
childCommands = new List(new ProviderCommandInfo[] {
ProviderCommandInfoUtils.Create(
this.Command,
this.Command.Root // input node
)});
// Build the final column map, and count the columns we expect for it.
resultColumnMap = BuildResultColumnMap(projectOp);
columnCount = projectOp.Outputs.Count;
}
private ColumnMap BuildResultColumnMap(PhysicalProjectOp projectOp)
{
// convert the column map into a real column map
// build up a dictionary mapping Vars to their real positions in the commands
Dictionary> varMap = BuildVarMap();
ColumnMap realColumnMap = ColumnMapTranslator.Translate(projectOp.ColumnMap, varMap);
return realColumnMap;
}
///
/// For each subcommand, build up a "location-map" for each top-level var that
/// is projected out. This location map will ultimately be used to convert VarRefColumnMap
/// into SimpleColumnMap
///
private Dictionary> BuildVarMap()
{
Dictionary> varMap =
new Dictionary>();
int commandId = 0;
foreach (Node subCommand in m_subCommands)
{
PhysicalProjectOp projectOp = (PhysicalProjectOp)subCommand.Op;
int columnPos = 0;
foreach (Var v in projectOp.Outputs)
{
KeyValuePair varLocation = new KeyValuePair(commandId, columnPos);
varMap[v] = varLocation;
columnPos++;
}
commandId++;
}
return varMap;
}
#endregion
#region private state
private PlanCompiler m_compilerState;
private Command Command { get { return m_compilerState.Command; } }
private List m_subCommands;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TreeViewAutomationPeer.cs
- StructuralObject.cs
- ReflectionPermission.cs
- ClosableStream.cs
- PermissionSet.cs
- FlowPosition.cs
- ApplicationDirectoryMembershipCondition.cs
- AutoScrollExpandMessageFilter.cs
- DataRelationPropertyDescriptor.cs
- datacache.cs
- HtmlWindow.cs
- DataGridViewAutoSizeModeEventArgs.cs
- CmsUtils.cs
- DataFormats.cs
- NumberAction.cs
- TextElementCollection.cs
- DesignerAdapterUtil.cs
- ToolboxItemImageConverter.cs
- DLinqAssociationProvider.cs
- UnsafeNetInfoNativeMethods.cs
- CurrencyWrapper.cs
- SQLInt64Storage.cs
- InvokePattern.cs
- PropertySet.cs
- ValueType.cs
- DetailsViewDeleteEventArgs.cs
- Ticks.cs
- PartialTrustHelpers.cs
- SettingsContext.cs
- FixedMaxHeap.cs
- CellCreator.cs
- ClientRoleProvider.cs
- EUCJPEncoding.cs
- MultiBindingExpression.cs
- Span.cs
- SpecularMaterial.cs
- OdbcConnectionPoolProviderInfo.cs
- SmiEventSink_Default.cs
- JavaScriptSerializer.cs
- WindowsNonControl.cs
- CultureInfo.cs
- ModulesEntry.cs
- Visitors.cs
- SudsWriter.cs
- Hash.cs
- ArgumentOutOfRangeException.cs
- MexNamedPipeBindingCollectionElement.cs
- DataGridViewRowPrePaintEventArgs.cs
- ParserHooks.cs
- LocatorManager.cs
- StorageScalarPropertyMapping.cs
- ExecutionContext.cs
- CompoundFileDeflateTransform.cs
- OleDbConnectionFactory.cs
- SetStoryboardSpeedRatio.cs
- Sequence.cs
- GenericNameHandler.cs
- DataKeyArray.cs
- ContentType.cs
- DirectoryObjectSecurity.cs
- GradientStopCollection.cs
- AnimationTimeline.cs
- TreeView.cs
- LoginCancelEventArgs.cs
- RuntimeConfig.cs
- ValueTypeFieldReference.cs
- Form.cs
- LockCookie.cs
- DesignerSerializerAttribute.cs
- FontFamily.cs
- TdsParameterSetter.cs
- CodeEventReferenceExpression.cs
- Message.cs
- SortKey.cs
- BooleanKeyFrameCollection.cs
- AsyncOperationManager.cs
- Speller.cs
- ControlBuilder.cs
- BoundPropertyEntry.cs
- DelegatingMessage.cs
- OSFeature.cs
- DbParameterCollectionHelper.cs
- WebPermission.cs
- SafeArrayRankMismatchException.cs
- Vertex.cs
- MULTI_QI.cs
- GeneralTransform.cs
- XmlSchemaParticle.cs
- DocumentViewerBaseAutomationPeer.cs
- EmptyReadOnlyDictionaryInternal.cs
- Trace.cs
- HttpCookie.cs
- TextParagraphView.cs
- CodeStatementCollection.cs
- UnauthorizedAccessException.cs
- MenuDesigner.cs
- HasCopySemanticsAttribute.cs
- Profiler.cs
- InsufficientMemoryException.cs
- MeshGeometry3D.cs