Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / QueryRewriting / Tile.cs / 1305376 / Tile.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Diagnostics; using System.Collections.Generic; using System.Text; using System.Collections.ObjectModel; using System.Linq; using System.Globalization; namespace System.Data.Mapping.ViewGeneration.QueryRewriting { internal enum TileOpKind { Union, Join, AntiSemiJoin, // Project, Named } internal interface ITileQuery { string Description { get; } } internal abstract class TileQueryProcessorwhere T_Query : ITileQuery { internal abstract T_Query Intersect(T_Query arg1, T_Query arg2); internal abstract T_Query Difference(T_Query arg1, T_Query arg2); internal abstract T_Query Union(T_Query arg1, T_Query arg2); internal abstract bool IsSatisfiable(T_Query query); internal abstract T_Query CreateDerivedViewBySelectingConstantAttributes(T_Query query); } internal class DefaultTileProcessor : TileProcessor > where T_Query : ITileQuery { private readonly TileQueryProcessor _tileQueryProcessor; internal DefaultTileProcessor(TileQueryProcessor tileQueryProcessor) { _tileQueryProcessor = tileQueryProcessor; } internal TileQueryProcessor QueryProcessor { get { return _tileQueryProcessor; } } internal override bool IsEmpty(Tile tile) { return false == _tileQueryProcessor.IsSatisfiable(tile.Query); } internal override Tile Union(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.Union, _tileQueryProcessor.Union(arg1.Query, arg2.Query)); } internal override Tile Join(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.Join, _tileQueryProcessor.Intersect(arg1.Query, arg2.Query)); } internal override Tile AntiSemiJoin(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.AntiSemiJoin, _tileQueryProcessor.Difference(arg1.Query, arg2.Query)); } internal override Tile GetArg1(Tile tile) { return tile.Arg1; } internal override Tile GetArg2(Tile tile) { return tile.Arg2; } internal override TileOpKind GetOpKind(Tile tile) { return tile.OpKind; } internal bool IsContainedIn(Tile arg1, Tile arg2) { return IsEmpty(AntiSemiJoin(arg1, arg2)); } internal bool IsEquivalentTo(Tile arg1, Tile arg2) { return IsContainedIn(arg1, arg2) && IsContainedIn(arg2, arg1); } } internal abstract class Tile where T_Query : ITileQuery { private readonly T_Query m_query; private readonly TileOpKind m_opKind; protected Tile(TileOpKind opKind, T_Query query) { m_opKind = opKind; m_query = query; } public T_Query Query { get { return m_query; } } public abstract string Description { get; } // multiple occurrences possible public IEnumerable GetNamedQueries() { return GetNamedQueries(this); } private static IEnumerable GetNamedQueries(Tile rewriting) { if (rewriting != null) { if (rewriting.OpKind == TileOpKind.Named) { yield return ((TileNamed )rewriting).NamedQuery; } else { foreach (T_Query query in GetNamedQueries(rewriting.Arg1)) { yield return query; } foreach (T_Query query in GetNamedQueries(rewriting.Arg2)) { yield return query; } } } } public override string ToString() { string formattedQuery = this.Description; if (formattedQuery != null) { return String.Format(CultureInfo.InvariantCulture, "{0}: [{1}]", this.Description, this.Query); } else { return String.Format(CultureInfo.InvariantCulture, "[{0}]", this.Query); } } public abstract Tile Arg1 { get; } public abstract Tile Arg2 { get; } public TileOpKind OpKind { get { return m_opKind; } } internal abstract Tile Replace(Tile oldTile, Tile newTile); } internal class TileNamed : Tile where T_Query : ITileQuery { public TileNamed(T_Query namedQuery) : base(TileOpKind.Named, namedQuery) { Debug.Assert(namedQuery != null); } public T_Query NamedQuery { get { return this.Query; } } public override Tile Arg1 { get { return null; } } public override Tile Arg2 { get { return null; } } public override string Description { get { return this.Query.Description; } } public override string ToString() { return this.Query.ToString(); } internal override Tile Replace(Tile oldTile, Tile newTile) { return (this == oldTile) ? newTile : this; } } internal class TileBinaryOperator : Tile where T_Query : ITileQuery { private readonly Tile m_arg1; private readonly Tile m_arg2; public TileBinaryOperator(Tile arg1, Tile arg2, TileOpKind opKind, T_Query query) : base(opKind, query) { Debug.Assert(arg1 != null && arg2 != null); m_arg1 = arg1; m_arg2 = arg2; } public override Tile Arg1 { get { return m_arg1; } } public override Tile Arg2 { get { return m_arg2; } } public override string Description { get { string descriptionFormat = null; switch (OpKind) { case TileOpKind.Join: descriptionFormat = "({0} & {1})"; break; case TileOpKind.AntiSemiJoin: descriptionFormat = "({0} - {1})"; break; case TileOpKind.Union: descriptionFormat = "({0} | {1})"; break; default: Debug.Fail("Unexpected binary operator"); break; } return String.Format(CultureInfo.InvariantCulture, descriptionFormat, this.Arg1.Description, this.Arg2.Description); } } internal override Tile Replace(Tile oldTile, Tile newTile) { Tile newArg1 = Arg1.Replace(oldTile, newTile); Tile newArg2 = Arg2.Replace(oldTile, newTile); if (newArg1 != Arg1 || newArg2 != Arg2) { return new TileBinaryOperator (newArg1, newArg2, OpKind, Query); } return this; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Diagnostics; using System.Collections.Generic; using System.Text; using System.Collections.ObjectModel; using System.Linq; using System.Globalization; namespace System.Data.Mapping.ViewGeneration.QueryRewriting { internal enum TileOpKind { Union, Join, AntiSemiJoin, // Project, Named } internal interface ITileQuery { string Description { get; } } internal abstract class TileQueryProcessorwhere T_Query : ITileQuery { internal abstract T_Query Intersect(T_Query arg1, T_Query arg2); internal abstract T_Query Difference(T_Query arg1, T_Query arg2); internal abstract T_Query Union(T_Query arg1, T_Query arg2); internal abstract bool IsSatisfiable(T_Query query); internal abstract T_Query CreateDerivedViewBySelectingConstantAttributes(T_Query query); } internal class DefaultTileProcessor : TileProcessor > where T_Query : ITileQuery { private readonly TileQueryProcessor _tileQueryProcessor; internal DefaultTileProcessor(TileQueryProcessor tileQueryProcessor) { _tileQueryProcessor = tileQueryProcessor; } internal TileQueryProcessor QueryProcessor { get { return _tileQueryProcessor; } } internal override bool IsEmpty(Tile tile) { return false == _tileQueryProcessor.IsSatisfiable(tile.Query); } internal override Tile Union(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.Union, _tileQueryProcessor.Union(arg1.Query, arg2.Query)); } internal override Tile Join(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.Join, _tileQueryProcessor.Intersect(arg1.Query, arg2.Query)); } internal override Tile AntiSemiJoin(Tile arg1, Tile arg2) { return new TileBinaryOperator (arg1, arg2, TileOpKind.AntiSemiJoin, _tileQueryProcessor.Difference(arg1.Query, arg2.Query)); } internal override Tile GetArg1(Tile tile) { return tile.Arg1; } internal override Tile GetArg2(Tile tile) { return tile.Arg2; } internal override TileOpKind GetOpKind(Tile tile) { return tile.OpKind; } internal bool IsContainedIn(Tile arg1, Tile arg2) { return IsEmpty(AntiSemiJoin(arg1, arg2)); } internal bool IsEquivalentTo(Tile arg1, Tile arg2) { return IsContainedIn(arg1, arg2) && IsContainedIn(arg2, arg1); } } internal abstract class Tile where T_Query : ITileQuery { private readonly T_Query m_query; private readonly TileOpKind m_opKind; protected Tile(TileOpKind opKind, T_Query query) { m_opKind = opKind; m_query = query; } public T_Query Query { get { return m_query; } } public abstract string Description { get; } // multiple occurrences possible public IEnumerable GetNamedQueries() { return GetNamedQueries(this); } private static IEnumerable GetNamedQueries(Tile rewriting) { if (rewriting != null) { if (rewriting.OpKind == TileOpKind.Named) { yield return ((TileNamed )rewriting).NamedQuery; } else { foreach (T_Query query in GetNamedQueries(rewriting.Arg1)) { yield return query; } foreach (T_Query query in GetNamedQueries(rewriting.Arg2)) { yield return query; } } } } public override string ToString() { string formattedQuery = this.Description; if (formattedQuery != null) { return String.Format(CultureInfo.InvariantCulture, "{0}: [{1}]", this.Description, this.Query); } else { return String.Format(CultureInfo.InvariantCulture, "[{0}]", this.Query); } } public abstract Tile Arg1 { get; } public abstract Tile Arg2 { get; } public TileOpKind OpKind { get { return m_opKind; } } internal abstract Tile Replace(Tile oldTile, Tile newTile); } internal class TileNamed : Tile where T_Query : ITileQuery { public TileNamed(T_Query namedQuery) : base(TileOpKind.Named, namedQuery) { Debug.Assert(namedQuery != null); } public T_Query NamedQuery { get { return this.Query; } } public override Tile Arg1 { get { return null; } } public override Tile Arg2 { get { return null; } } public override string Description { get { return this.Query.Description; } } public override string ToString() { return this.Query.ToString(); } internal override Tile Replace(Tile oldTile, Tile newTile) { return (this == oldTile) ? newTile : this; } } internal class TileBinaryOperator : Tile where T_Query : ITileQuery { private readonly Tile m_arg1; private readonly Tile m_arg2; public TileBinaryOperator(Tile arg1, Tile arg2, TileOpKind opKind, T_Query query) : base(opKind, query) { Debug.Assert(arg1 != null && arg2 != null); m_arg1 = arg1; m_arg2 = arg2; } public override Tile Arg1 { get { return m_arg1; } } public override Tile Arg2 { get { return m_arg2; } } public override string Description { get { string descriptionFormat = null; switch (OpKind) { case TileOpKind.Join: descriptionFormat = "({0} & {1})"; break; case TileOpKind.AntiSemiJoin: descriptionFormat = "({0} - {1})"; break; case TileOpKind.Union: descriptionFormat = "({0} | {1})"; break; default: Debug.Fail("Unexpected binary operator"); break; } return String.Format(CultureInfo.InvariantCulture, descriptionFormat, this.Arg1.Description, this.Arg2.Description); } } internal override Tile Replace(Tile oldTile, Tile newTile) { Tile newArg1 = Arg1.Replace(oldTile, newTile); Tile newArg2 = Arg2.Replace(oldTile, newTile); if (newArg1 != Arg1 || newArg2 != Arg2) { return new TileBinaryOperator (newArg1, newArg2, OpKind, Query); } return this; } } } // 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
- Triangle.cs
- BindingContext.cs
- SelfIssuedAuthRSAPKCS1SignatureFormatter.cs
- Int64Storage.cs
- WebMessageEncodingBindingElement.cs
- DuplicateWaitObjectException.cs
- CustomAssemblyResolver.cs
- CodeAccessPermission.cs
- SerializationException.cs
- TextOptionsInternal.cs
- QueryCorrelationInitializer.cs
- PrinterUnitConvert.cs
- ColorKeyFrameCollection.cs
- SingletonChannelAcceptor.cs
- EntityCommandExecutionException.cs
- HtmlWindowCollection.cs
- FlatButtonAppearance.cs
- BitmapEffectGeneralTransform.cs
- RtfToken.cs
- ToolBarTray.cs
- RSACryptoServiceProvider.cs
- TableLayoutRowStyleCollection.cs
- PageMediaSize.cs
- filewebresponse.cs
- FrameworkContentElement.cs
- XmlEncodedRawTextWriter.cs
- TraceData.cs
- StringToken.cs
- RowUpdatedEventArgs.cs
- DummyDataSource.cs
- SamlSubjectStatement.cs
- EntitySetRetriever.cs
- WebPartTransformerAttribute.cs
- HtmlInputPassword.cs
- CompilerGlobalScopeAttribute.cs
- EntityDataSourceContextCreatingEventArgs.cs
- WebPartZoneBase.cs
- WindowsAuthenticationEventArgs.cs
- InternalTypeHelper.cs
- FieldBuilder.cs
- CustomSignedXml.cs
- ToolStripMenuItem.cs
- GenerateHelper.cs
- XLinq.cs
- DbConnectionOptions.cs
- InterleavedZipPartStream.cs
- Assert.cs
- WpfWebRequestHelper.cs
- ISAPIApplicationHost.cs
- OletxTransactionHeader.cs
- StringCollectionMarkupSerializer.cs
- DbMetaDataFactory.cs
- FixedPage.cs
- UniformGrid.cs
- Blend.cs
- GeometryValueSerializer.cs
- XamlSerializerUtil.cs
- PropertyContainer.cs
- InfoCardBaseException.cs
- clipboard.cs
- ImageField.cs
- C14NUtil.cs
- AppLevelCompilationSectionCache.cs
- ResourcePermissionBase.cs
- LayoutEngine.cs
- PositiveTimeSpanValidator.cs
- CodeAttributeArgument.cs
- PartitionerQueryOperator.cs
- ReflectEventDescriptor.cs
- DataObjectCopyingEventArgs.cs
- FixUpCollection.cs
- ProcessRequestArgs.cs
- SessionEndingCancelEventArgs.cs
- VariableQuery.cs
- AnnotationResource.cs
- FileSystemEventArgs.cs
- BuildResult.cs
- TextParaClient.cs
- OpenTypeLayoutCache.cs
- TrackingProvider.cs
- DocumentViewerBase.cs
- TextRunCacheImp.cs
- TransportBindingElementImporter.cs
- GridLengthConverter.cs
- Delegate.cs
- PagesSection.cs
- ProcessProtocolHandler.cs
- AuthenticationServiceManager.cs
- Walker.cs
- Translator.cs
- ConstantSlot.cs
- DbConnectionPoolGroupProviderInfo.cs
- ObjectListCommandCollection.cs
- httpserverutility.cs
- DataGridAutoGeneratingColumnEventArgs.cs
- ColorMap.cs
- HtmlSelect.cs
- UnmanagedHandle.cs
- LocatorGroup.cs
- WindowsStatic.cs