Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Query / PlanCompiler / ProviderCommandInfoUtils.cs / 2 / ProviderCommandInfoUtils.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.Data.Common.CommandTrees;
using System.Data.Common;
using md = System.Data.Metadata.Edm;
using System.Data.Query.InternalTrees;
using System.Data.Query.PlanCompiler;
namespace System.Data.Query.PlanCompiler
{
///
/// Helper class for creating a ProviderCommandInfo given an Iqt Node.
///
internal static class ProviderCommandInfoUtils
{
#region Public Methods
///
/// Creates a ProviderCommandInfo for the given node.
/// This method should be called when the keys, foreign keys and sort keys are known ahead of time.
/// Typically it is used when the original command is factored into multiple commands.
///
/// The owning command, used for creating VarVecs, etc
/// The root of the sub-command for which a ProviderCommandInfo should be generated
/// A list of ProviderCommandInfos that were created for the child sub-commands.
/// The resulting ProviderCommandInfo
internal static ProviderCommandInfo Create(
Command command,
Node node,
List children)
{
PhysicalProjectOp projectOp = node.Op as PhysicalProjectOp;
PlanCompiler.Assert(projectOp != null, "Expected root Op to be a physical Project");
// build up the CQT
DbCommandTree ctree = CTreeGenerator.Generate(command, node);
DbQueryCommandTree cqtree = ctree as DbQueryCommandTree;
PlanCompiler.Assert(cqtree != null, "null query command tree");
// Get the rowtype for the result cqt
md.CollectionType collType = TypeHelpers.GetEdmType(cqtree.Query.ResultType);
PlanCompiler.Assert(md.TypeSemantics.IsRowType(collType.TypeUsage), "command rowtype is not a record");
// Build up a mapping from Vars to the corresponding output property/column
Dictionary outputVarMap = BuildOutputVarMap(projectOp, collType.TypeUsage);
return new ProviderCommandInfo(ctree, children);
}
///
/// Creates a ProviderCommandInfo for the given node.
/// This method should be called when the keys and the sort keys are not known ahead of time.
/// Typically it is used when there is only one command, that is no query factoring is done.
/// This method also has the option of pulling up keys and sort information.
///
/// The owning command, used for creating VarVecs, etc
/// The root of the sub-command for which a ProviderCommandInfo should be generated
/// The resulting ProviderCommandInfo
internal static ProviderCommandInfo Create(
Command command,
Node node)
{
return Create(
command,
node,
new List() //children
);
}
#endregion
#region Private Methods
///
/// Build up a mapping from Vars to the corresponding property of the output row type
///
/// the physical projectOp
/// output type
/// a map from Vars to the output type member
private static Dictionary BuildOutputVarMap(PhysicalProjectOp projectOp, md.TypeUsage outputType)
{
Dictionary outputVarMap = new Dictionary();
PlanCompiler.Assert(md.TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");
IEnumerator propertyEnumerator = TypeHelpers.GetEdmType(outputType).Properties.GetEnumerator();
IEnumerator varEnumerator = projectOp.Outputs.GetEnumerator();
while (true)
{
bool foundProp = propertyEnumerator.MoveNext();
bool foundVar = varEnumerator.MoveNext();
if (foundProp != foundVar)
{
throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1);
}
if (!foundProp)
{
break;
}
outputVarMap[varEnumerator.Current] = propertyEnumerator.Current;
}
return outputVarMap;
}
#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.Data.Common.CommandTrees;
using System.Data.Common;
using md = System.Data.Metadata.Edm;
using System.Data.Query.InternalTrees;
using System.Data.Query.PlanCompiler;
namespace System.Data.Query.PlanCompiler
{
///
/// Helper class for creating a ProviderCommandInfo given an Iqt Node.
///
internal static class ProviderCommandInfoUtils
{
#region Public Methods
///
/// Creates a ProviderCommandInfo for the given node.
/// This method should be called when the keys, foreign keys and sort keys are known ahead of time.
/// Typically it is used when the original command is factored into multiple commands.
///
/// The owning command, used for creating VarVecs, etc
/// The root of the sub-command for which a ProviderCommandInfo should be generated
/// A list of ProviderCommandInfos that were created for the child sub-commands.
/// The resulting ProviderCommandInfo
internal static ProviderCommandInfo Create(
Command command,
Node node,
List children)
{
PhysicalProjectOp projectOp = node.Op as PhysicalProjectOp;
PlanCompiler.Assert(projectOp != null, "Expected root Op to be a physical Project");
// build up the CQT
DbCommandTree ctree = CTreeGenerator.Generate(command, node);
DbQueryCommandTree cqtree = ctree as DbQueryCommandTree;
PlanCompiler.Assert(cqtree != null, "null query command tree");
// Get the rowtype for the result cqt
md.CollectionType collType = TypeHelpers.GetEdmType(cqtree.Query.ResultType);
PlanCompiler.Assert(md.TypeSemantics.IsRowType(collType.TypeUsage), "command rowtype is not a record");
// Build up a mapping from Vars to the corresponding output property/column
Dictionary outputVarMap = BuildOutputVarMap(projectOp, collType.TypeUsage);
return new ProviderCommandInfo(ctree, children);
}
///
/// Creates a ProviderCommandInfo for the given node.
/// This method should be called when the keys and the sort keys are not known ahead of time.
/// Typically it is used when there is only one command, that is no query factoring is done.
/// This method also has the option of pulling up keys and sort information.
///
/// The owning command, used for creating VarVecs, etc
/// The root of the sub-command for which a ProviderCommandInfo should be generated
/// The resulting ProviderCommandInfo
internal static ProviderCommandInfo Create(
Command command,
Node node)
{
return Create(
command,
node,
new List() //children
);
}
#endregion
#region Private Methods
///
/// Build up a mapping from Vars to the corresponding property of the output row type
///
/// the physical projectOp
/// output type
/// a map from Vars to the output type member
private static Dictionary BuildOutputVarMap(PhysicalProjectOp projectOp, md.TypeUsage outputType)
{
Dictionary outputVarMap = new Dictionary();
PlanCompiler.Assert(md.TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");
IEnumerator propertyEnumerator = TypeHelpers.GetEdmType(outputType).Properties.GetEnumerator();
IEnumerator varEnumerator = projectOp.Outputs.GetEnumerator();
while (true)
{
bool foundProp = propertyEnumerator.MoveNext();
bool foundVar = varEnumerator.MoveNext();
if (foundProp != foundVar)
{
throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1);
}
if (!foundProp)
{
break;
}
outputVarMap[varEnumerator.Current] = propertyEnumerator.Current;
}
return outputVarMap;
}
#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
- SqlDependencyUtils.cs
- SchemaDeclBase.cs
- _StreamFramer.cs
- EntityDesignerBuildProvider.cs
- SqlInternalConnection.cs
- SetterBase.cs
- AsymmetricKeyExchangeDeformatter.cs
- WebPartHeaderCloseVerb.cs
- XmlSerializationWriter.cs
- AnnotationMap.cs
- ContextMenuAutomationPeer.cs
- StrokeFIndices.cs
- DataGridBeginningEditEventArgs.cs
- Token.cs
- BufferModesCollection.cs
- FlowNode.cs
- CompiledAction.cs
- MultiSelectRootGridEntry.cs
- RenamedEventArgs.cs
- RegexFCD.cs
- BlockCollection.cs
- SubpageParaClient.cs
- HostExecutionContextManager.cs
- SymmetricSecurityBindingElement.cs
- SQLBinary.cs
- MouseGestureValueSerializer.cs
- DispatcherExceptionEventArgs.cs
- PersistenceProviderFactory.cs
- RenderDataDrawingContext.cs
- FlowDocumentPage.cs
- WebSysDisplayNameAttribute.cs
- SqlUserDefinedAggregateAttribute.cs
- GatewayIPAddressInformationCollection.cs
- CustomErrorsSectionWrapper.cs
- DragDeltaEventArgs.cs
- CompareValidator.cs
- CompiledQuery.cs
- BinaryCommonClasses.cs
- EventProvider.cs
- TakeQueryOptionExpression.cs
- DataGridDetailsPresenterAutomationPeer.cs
- TreeViewHitTestInfo.cs
- BindMarkupExtensionSerializer.cs
- WebPartTransformer.cs
- AutomationElementIdentifiers.cs
- SchemaImporterExtensionElementCollection.cs
- entityreference_tresulttype.cs
- RuleInfoComparer.cs
- PropertyValidationContext.cs
- TransformerInfo.cs
- KeyedCollection.cs
- TraceHandler.cs
- Missing.cs
- ZipIOLocalFileHeader.cs
- Decimal.cs
- UserInitiatedNavigationPermission.cs
- WindowsAuthenticationEventArgs.cs
- MetadataUtil.cs
- KeyboardNavigation.cs
- SqlDataSourceConfigureFilterForm.cs
- ValidationErrorEventArgs.cs
- Slider.cs
- Avt.cs
- AdornerDecorator.cs
- UserPersonalizationStateInfo.cs
- DBSqlParserTable.cs
- BitmapMetadataEnumerator.cs
- AspNetSynchronizationContext.cs
- OperandQuery.cs
- OutputCacheSettings.cs
- WebBrowserNavigatedEventHandler.cs
- AnnotationResource.cs
- CharacterMetricsDictionary.cs
- HtmlInputCheckBox.cs
- KeyTimeConverter.cs
- PageAsyncTask.cs
- HtmlContainerControl.cs
- CodeTypeParameterCollection.cs
- DataTableReaderListener.cs
- XmlSchemaImport.cs
- DataPagerCommandEventArgs.cs
- DataControlPagerLinkButton.cs
- ScrollEvent.cs
- DurationConverter.cs
- HtmlEncodedRawTextWriter.cs
- DataServiceClientException.cs
- DeferredReference.cs
- CodeArgumentReferenceExpression.cs
- AliasExpr.cs
- SystemBrushes.cs
- SamlAssertionKeyIdentifierClause.cs
- LoginNameDesigner.cs
- PeerDuplexChannelListener.cs
- RenderCapability.cs
- DynamicResourceExtensionConverter.cs
- Encoder.cs
- GridViewSortEventArgs.cs
- DocobjHost.cs
- HelpProvider.cs
- DomainUpDown.cs