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 / Map / ViewGeneration / Structures / ProjectedSlot.cs / 1 / 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
- MbpInfo.cs
- TabletDeviceInfo.cs
- ImageMapEventArgs.cs
- TreeBuilder.cs
- IUnknownConstantAttribute.cs
- TextRangeProviderWrapper.cs
- SplineKeyFrames.cs
- Parallel.cs
- DataGrid.cs
- StylusShape.cs
- SecurityVersion.cs
- FileReservationCollection.cs
- CommonGetThemePartSize.cs
- GridItemPatternIdentifiers.cs
- SettingsPropertyValue.cs
- HostingEnvironment.cs
- ChangeBlockUndoRecord.cs
- MgmtConfigurationRecord.cs
- WpfKnownType.cs
- SqlClientWrapperSmiStream.cs
- SurrogateEncoder.cs
- MachineSettingsSection.cs
- SiteMembershipCondition.cs
- DocumentEventArgs.cs
- Solver.cs
- TreeNodeBindingCollection.cs
- FrameworkTextComposition.cs
- MetadataHelper.cs
- login.cs
- WindowsAuthenticationModule.cs
- JournalEntryStack.cs
- DataGridLinkButton.cs
- WebReference.cs
- Color.cs
- SecurityUniqueId.cs
- DtrList.cs
- TypeBuilder.cs
- Int64AnimationBase.cs
- SmtpAuthenticationManager.cs
- ConvertTextFrag.cs
- AccessDataSourceView.cs
- DrawingContextWalker.cs
- Stream.cs
- InstanceOwnerException.cs
- ShaperBuffers.cs
- CqlParser.cs
- TranslateTransform.cs
- EntryIndex.cs
- MyContact.cs
- DataGridPagerStyle.cs
- _UriTypeConverter.cs
- TabControlEvent.cs
- RtfToXamlReader.cs
- TextSelectionHelper.cs
- XmlSchemaComplexContent.cs
- RuntimeHelpers.cs
- HandoffBehavior.cs
- unsafenativemethodsother.cs
- PresentationTraceSources.cs
- EventSinkHelperWriter.cs
- ToolStripDropDown.cs
- BinaryUtilClasses.cs
- IteratorAsyncResult.cs
- CompilationPass2Task.cs
- NGCUIElementCollectionSerializerAsync.cs
- ArglessEventHandlerProxy.cs
- OdbcFactory.cs
- ReliableSession.cs
- OleDbDataAdapter.cs
- StateDesigner.LayoutSelectionGlyph.cs
- RecordBuilder.cs
- DecimalStorage.cs
- SecurityUtils.cs
- XmlHierarchyData.cs
- BigInt.cs
- NotifyCollectionChangedEventArgs.cs
- VirtualDirectoryMappingCollection.cs
- SaveWorkflowCommand.cs
- WebMethodAttribute.cs
- PickBranchDesigner.xaml.cs
- SoapCodeExporter.cs
- ColumnHeader.cs
- ScriptResourceHandler.cs
- DateTimeUtil.cs
- WebConfigurationHost.cs
- PropertyItem.cs
- TextFormatterContext.cs
- SoapFormatExtensions.cs
- Vars.cs
- ClockController.cs
- TimeSpanStorage.cs
- Matrix.cs
- TextTreeFixupNode.cs
- MouseGestureValueSerializer.cs
- TextStore.cs
- ExcludeFromCodeCoverageAttribute.cs
- ClientUtils.cs
- UiaCoreApi.cs
- EmptyEnumerator.cs
- SQLBoolean.cs