Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / ProjectedSlot.cs / 2 / ProjectedSlot.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.Utils; using System.Collections.Generic; using System.Text; using System.Data.Mapping.ViewGeneration.CqlGeneration; using System.Data.Mapping.ViewGeneration.Utils; using System.Diagnostics; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Structures { ////// This class represents the constants or members that that can be referenced in a C or S Cell query /// In addition to fields, may represent constants such as types of fields, booleans, etc. /// internal abstract class ProjectedSlot : InternalBase { #region Fields // A comparer object for comparing slots internal static readonly IEqualityComparerEqualityComparer = new ProjectedSlotComparer(); #endregion #region Abstract methods // effects: Given a slot and the new mapping, returns the // corresponding nw slot internal virtual ProjectedSlot RemapSlot(Dictionary remap) { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return null; // To keep the compiler happy } // effects: Returns true if this is semantically equivalent to s2 protected virtual bool IsEqualTo(ProjectedSlot right) { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return false; // To keep the compiler happy } protected virtual int GetHash() { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return 0; // To keep the compiler happy } // effects: Converts all "relevant" ProjectedSlots in this (including // this) to aliased slots for CqlBlock "block". A slot type is // relevant if it is not a constant. "outputPath" is the output path // of this slot in the final view internal virtual ProjectedSlot MakeAliasedSlot(CqlBlock block, MemberPath outputPath, int slotNum) { AliasedSlot result = new AliasedSlot(block, this, outputPath, slotNum); return result; } // requires: outputMember is non-null if slot is ConstantSlot (it can be // null otherwise). indentLevel indicates the appropriate // indentation level (method can ignore it) // effects: Given a slot and a tableAlias, generates the Cql // corresponding to it. If slot is an Aliased slot, tableAlias is ignored // Returns the modified builder internal abstract StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel); #endregion #region Helper Methods for slots and ProjectedSlotMap // effects: Returns the alias corresponding to slot. outputMember is // the member to which this slot is ultimately contributing to, e.g., // CPerson1_pid internal virtual string CqlFieldAlias(MemberPath outputMember) { // Subclasses that don't want the outputMember will override this method return outputMember.CqlFieldAlias; } // effects: Given a slot number, slotNum, returns the output member path // that this slot contributes/corresponds to in the extent view. If // the slot corresponds to one of the boolean variables, returns null internal static MemberPath GetMemberPath(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { MemberPath result = IsBoolSlot(slotNum, projectedSlotMap, numBoolSlots) ? null: projectedSlotMap[slotNum]; return result; } // effects: Given the index of a boolean variable (e.g., of from1), // returns the slot number for that boolean in this internal static int BoolIndexToSlot(int boolIndex, MemberPathMapBase projectedSlotMap, int numBoolSlots) { // Booleans appear after the regular slot Debug.Assert(boolIndex >= 0 && boolIndex < numBoolSlots, "No such boolean in this node"); return projectedSlotMap.Count + boolIndex; } // effects: Given a slotNum corresponding to a boolean slot, returns // the cel number that the cell corresponds to internal static int SlotToBoolIndex(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots && slotNum >= projectedSlotMap.Count, "No such boolean slot"); return slotNum - projectedSlotMap.Count; } // effects: Returns true if slotNum corresponds to a key slot in the // output extent view internal static bool IsKeySlot(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots, "No such slot in tree"); return slotNum < projectedSlotMap.Count && projectedSlotMap[slotNum].IsPartOfKey; } // effects: Returns true if slotNum corresponds to a bool slot and // not a regular field internal static bool IsBoolSlot(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots, "Boolean slot does not exist in tree"); return slotNum >= projectedSlotMap.Count; } #endregion #region Other Methods // effects: Given fields slots1 and slot2, remap then using "remap" and merge them internal static bool TryMergeRemapSlots(ProjectedSlot[] slots1, ProjectedSlot[] slots2, Dictionary remap, out ProjectedSlot[] result) { // First merge them and then remp them ProjectedSlot[] mergedSlots; if (false == TryMergeSlots(slots1, slots2, out mergedSlots)) { result = null; return false; } else { result = RemapSlots(mergedSlots, remap); return true; } } // effects: Given two lists of slots1 and slot2, merges them and returns // the resulting slots, i.e., empty slots from one are overridden by // the slots from the other private static bool TryMergeSlots(ProjectedSlot[] slots1, ProjectedSlot[] slots2, out ProjectedSlot[] slots) { Debug.Assert(slots1.Length == slots2.Length, "Merged slots of two cells must be same size"); slots = new ProjectedSlot[slots1.Length]; for (int i = 0; i < slots.Length; i++) { ProjectedSlot slot1 = slots1[i]; ProjectedSlot slot2 = slots2[i]; if (slot1 == null) { slots[i] = slot2; } else if (slot2 == null) { slots[i] = slot1; } else { // Both slots are non-null: Either both are the same // members or one of them is a constant // Note: if both are constants (even different constants) // it does not matter which one we pick because the CASE statement will override it JoinTreeSlot memberSlot1 = slot1 as JoinTreeSlot; JoinTreeSlot memberSlot2 = slot2 as JoinTreeSlot; if (memberSlot1 != null && memberSlot2 != null && false == EqualityComparer.Equals(memberSlot1, memberSlot2)) { // Illegal combination of slots; non-constant fields disagree return false; } // If one of them is a field we have to get the field ProjectedSlot pickedSlot = (memberSlot1 != null) ? slot1 : slot2; slots[i] = pickedSlot; } } return true; } // effects: Given fields slots, remaps them using remap and returns // the result private static ProjectedSlot[] RemapSlots(ProjectedSlot[] oldSlots, Dictionary remap) { ProjectedSlot[] slots = new ProjectedSlot[oldSlots.Length]; for (int i = 0; i < slots.Length; i++) { ProjectedSlot oldSlot = oldSlots[i]; if (oldSlot != null) { // Remap non-nulls only slots[i] = oldSlot.RemapSlot(remap); } } return slots; } #endregion #region Comparer class // summary: A class that can compare slots basd on their contents internal class ProjectedSlotComparer : IEqualityComparer { // effects: Returns true if left and right are semantically equivalent public bool Equals(ProjectedSlot left, ProjectedSlot right) { // Quick check with references if (object.ReferenceEquals(left, right)) { // Gets the Null and Undefined case as well return true; } // One of them is non-null at least. So if the other one is // null, we cannot be equal if (left == null || right == null) { return false; } // Both are non-null at this point return left.IsEqualTo(right); } public int GetHashCode(ProjectedSlot key) { EntityUtil.CheckArgumentNull(key, "key"); return key.GetHash(); } } #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.Utils; using System.Collections.Generic; using System.Text; using System.Data.Mapping.ViewGeneration.CqlGeneration; using System.Data.Mapping.ViewGeneration.Utils; using System.Diagnostics; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Structures { ////// This class represents the constants or members that that can be referenced in a C or S Cell query /// In addition to fields, may represent constants such as types of fields, booleans, etc. /// internal abstract class ProjectedSlot : InternalBase { #region Fields // A comparer object for comparing slots internal static readonly IEqualityComparerEqualityComparer = new ProjectedSlotComparer(); #endregion #region Abstract methods // effects: Given a slot and the new mapping, returns the // corresponding nw slot internal virtual ProjectedSlot RemapSlot(Dictionary remap) { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return null; // To keep the compiler happy } // effects: Returns true if this is semantically equivalent to s2 protected virtual bool IsEqualTo(ProjectedSlot right) { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return false; // To keep the compiler happy } protected virtual int GetHash() { ExceptionHelpers.CheckAndThrowRes(false, () => Strings.ViewGen_Internal_Error); return 0; // To keep the compiler happy } // effects: Converts all "relevant" ProjectedSlots in this (including // this) to aliased slots for CqlBlock "block". A slot type is // relevant if it is not a constant. "outputPath" is the output path // of this slot in the final view internal virtual ProjectedSlot MakeAliasedSlot(CqlBlock block, MemberPath outputPath, int slotNum) { AliasedSlot result = new AliasedSlot(block, this, outputPath, slotNum); return result; } // requires: outputMember is non-null if slot is ConstantSlot (it can be // null otherwise). indentLevel indicates the appropriate // indentation level (method can ignore it) // effects: Given a slot and a tableAlias, generates the Cql // corresponding to it. If slot is an Aliased slot, tableAlias is ignored // Returns the modified builder internal abstract StringBuilder AsCql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel); #endregion #region Helper Methods for slots and ProjectedSlotMap // effects: Returns the alias corresponding to slot. outputMember is // the member to which this slot is ultimately contributing to, e.g., // CPerson1_pid internal virtual string CqlFieldAlias(MemberPath outputMember) { // Subclasses that don't want the outputMember will override this method return outputMember.CqlFieldAlias; } // effects: Given a slot number, slotNum, returns the output member path // that this slot contributes/corresponds to in the extent view. If // the slot corresponds to one of the boolean variables, returns null internal static MemberPath GetMemberPath(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { MemberPath result = IsBoolSlot(slotNum, projectedSlotMap, numBoolSlots) ? null: projectedSlotMap[slotNum]; return result; } // effects: Given the index of a boolean variable (e.g., of from1), // returns the slot number for that boolean in this internal static int BoolIndexToSlot(int boolIndex, MemberPathMapBase projectedSlotMap, int numBoolSlots) { // Booleans appear after the regular slot Debug.Assert(boolIndex >= 0 && boolIndex < numBoolSlots, "No such boolean in this node"); return projectedSlotMap.Count + boolIndex; } // effects: Given a slotNum corresponding to a boolean slot, returns // the cel number that the cell corresponds to internal static int SlotToBoolIndex(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots && slotNum >= projectedSlotMap.Count, "No such boolean slot"); return slotNum - projectedSlotMap.Count; } // effects: Returns true if slotNum corresponds to a key slot in the // output extent view internal static bool IsKeySlot(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots, "No such slot in tree"); return slotNum < projectedSlotMap.Count && projectedSlotMap[slotNum].IsPartOfKey; } // effects: Returns true if slotNum corresponds to a bool slot and // not a regular field internal static bool IsBoolSlot(int slotNum, MemberPathMapBase projectedSlotMap, int numBoolSlots) { Debug.Assert(slotNum < projectedSlotMap.Count + numBoolSlots, "Boolean slot does not exist in tree"); return slotNum >= projectedSlotMap.Count; } #endregion #region Other Methods // effects: Given fields slots1 and slot2, remap then using "remap" and merge them internal static bool TryMergeRemapSlots(ProjectedSlot[] slots1, ProjectedSlot[] slots2, Dictionary remap, out ProjectedSlot[] result) { // First merge them and then remp them ProjectedSlot[] mergedSlots; if (false == TryMergeSlots(slots1, slots2, out mergedSlots)) { result = null; return false; } else { result = RemapSlots(mergedSlots, remap); return true; } } // effects: Given two lists of slots1 and slot2, merges them and returns // the resulting slots, i.e., empty slots from one are overridden by // the slots from the other private static bool TryMergeSlots(ProjectedSlot[] slots1, ProjectedSlot[] slots2, out ProjectedSlot[] slots) { Debug.Assert(slots1.Length == slots2.Length, "Merged slots of two cells must be same size"); slots = new ProjectedSlot[slots1.Length]; for (int i = 0; i < slots.Length; i++) { ProjectedSlot slot1 = slots1[i]; ProjectedSlot slot2 = slots2[i]; if (slot1 == null) { slots[i] = slot2; } else if (slot2 == null) { slots[i] = slot1; } else { // Both slots are non-null: Either both are the same // members or one of them is a constant // Note: if both are constants (even different constants) // it does not matter which one we pick because the CASE statement will override it JoinTreeSlot memberSlot1 = slot1 as JoinTreeSlot; JoinTreeSlot memberSlot2 = slot2 as JoinTreeSlot; if (memberSlot1 != null && memberSlot2 != null && false == EqualityComparer.Equals(memberSlot1, memberSlot2)) { // Illegal combination of slots; non-constant fields disagree return false; } // If one of them is a field we have to get the field ProjectedSlot pickedSlot = (memberSlot1 != null) ? slot1 : slot2; slots[i] = pickedSlot; } } return true; } // effects: Given fields slots, remaps them using remap and returns // the result private static ProjectedSlot[] RemapSlots(ProjectedSlot[] oldSlots, Dictionary remap) { ProjectedSlot[] slots = new ProjectedSlot[oldSlots.Length]; for (int i = 0; i < slots.Length; i++) { ProjectedSlot oldSlot = oldSlots[i]; if (oldSlot != null) { // Remap non-nulls only slots[i] = oldSlot.RemapSlot(remap); } } return slots; } #endregion #region Comparer class // summary: A class that can compare slots basd on their contents internal class ProjectedSlotComparer : IEqualityComparer { // effects: Returns true if left and right are semantically equivalent public bool Equals(ProjectedSlot left, ProjectedSlot right) { // Quick check with references if (object.ReferenceEquals(left, right)) { // Gets the Null and Undefined case as well return true; } // One of them is non-null at least. So if the other one is // null, we cannot be equal if (left == null || right == null) { return false; } // Both are non-null at this point return left.IsEqualTo(right); } public int GetHashCode(ProjectedSlot key) { EntityUtil.CheckArgumentNull(key, "key"); return key.GetHash(); } } #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
- RC2CryptoServiceProvider.cs
- GeneralTransform3DGroup.cs
- SoapFault.cs
- CharacterMetricsDictionary.cs
- ActivationArguments.cs
- TextUtf8RawTextWriter.cs
- Control.cs
- SID.cs
- XamlInt32CollectionSerializer.cs
- SqlConnectionPoolGroupProviderInfo.cs
- LinkButton.cs
- LazyTextWriterCreator.cs
- IndependentAnimationStorage.cs
- WebPartMinimizeVerb.cs
- sqlpipe.cs
- HttpRuntime.cs
- ConfigDefinitionUpdates.cs
- cookieexception.cs
- DeploymentSection.cs
- _StreamFramer.cs
- XmlUtil.cs
- WsatEtwTraceListener.cs
- ProbeDuplex11AsyncResult.cs
- COM2PictureConverter.cs
- TextFormatterImp.cs
- CustomGrammar.cs
- OTFRasterizer.cs
- ResponseStream.cs
- ArgumentException.cs
- ArgumentOutOfRangeException.cs
- BitmapEffectrendercontext.cs
- SchemaEntity.cs
- FileDialog.cs
- Size.cs
- StyleReferenceConverter.cs
- EventData.cs
- ComponentDispatcherThread.cs
- WizardPanelChangingEventArgs.cs
- CompiledQuery.cs
- SystemDropShadowChrome.cs
- PointConverter.cs
- ZipIOExtraFieldZip64Element.cs
- CodeLinePragma.cs
- InvokerUtil.cs
- KeyedCollection.cs
- COM2ExtendedTypeConverter.cs
- SiteMapNode.cs
- DataGridCaption.cs
- Int64AnimationBase.cs
- Unit.cs
- QueryStringHandler.cs
- StorageInfo.cs
- HtmlImageAdapter.cs
- ProjectionAnalyzer.cs
- XmlFormatWriterGenerator.cs
- FormattedText.cs
- PageAsyncTaskManager.cs
- StringReader.cs
- nulltextnavigator.cs
- SEHException.cs
- KeyMatchBuilder.cs
- Parsers.cs
- HelpKeywordAttribute.cs
- BuilderPropertyEntry.cs
- ConcurrentBag.cs
- ParentQuery.cs
- SafeWaitHandle.cs
- SmiSettersStream.cs
- OledbConnectionStringbuilder.cs
- CatalogZoneDesigner.cs
- EpmTargetPathSegment.cs
- CancellationTokenSource.cs
- RemoteCryptoSignHashRequest.cs
- ComponentResourceManager.cs
- ReflectPropertyDescriptor.cs
- Quack.cs
- MappingException.cs
- VirtualizedCellInfoCollection.cs
- DocumentDesigner.cs
- ResXBuildProvider.cs
- ExpressionNormalizer.cs
- PropertyKey.cs
- StringKeyFrameCollection.cs
- WindowsToolbar.cs
- CoreChannel.cs
- XmlQueryOutput.cs
- NodeFunctions.cs
- NGCUIElementCollectionSerializerAsync.cs
- ItemCheckedEvent.cs
- CompiledQueryCacheEntry.cs
- ExtensibleClassFactory.cs
- QilGenerator.cs
- WindowsIdentity.cs
- DiagnosticStrings.cs
- DataGridViewColumnTypeEditor.cs
- ClickablePoint.cs
- FixedSOMTextRun.cs
- SqlUtil.cs
- StringKeyFrameCollection.cs
- SafeHandles.cs